Can I prevent an alert() with a Google Chrome Extension

后端 未结 3 484
礼貌的吻别
礼貌的吻别 2020-11-29 09:27

Can I create a Google chrome extension to prevent the page from doing an alert() ?

3条回答
  •  一向
    一向 (楼主)
    2020-11-29 10:00

    Yes you can, alert() is just a JavaScript method, you can override its functionality by doing.

    window.alert = function alert(msg) {
      console.log('Hidden Alert ' + msg);
    };
    

    Just remember to run that content script at document_start within the manifest via run_at manifest content script modifier.

    I believe there is an extension that just does that. The developer names it Nice Alert. https://chrome.google.com/extensions/detail/ehnbelnegmgdnjaghgomaakjcmpcakhk

提交回复
热议问题