如何"hook"通知对象



我需要"钩住"通知对象。我要每一个

new Notification(title);

登录到控制台标题,但也创建通知。我想保留通知对象的值(例如,如果在通知请求权限之前,则保留此权限(

怎么做?

您可以覆盖默认构造函数:

// Override default notification constructor:
Notification = (function(Notification) {
  function MyNotification(...args) {
    console.log(...args);
    return new Notification(...args);
  };
  Object.assign(MyNotification, Notification);
  MyNotification.prototype = Notification.prototype;
  return MyNotification;
})(Notification);

最新更新