RockOnGom RockOnGom - 1 year ago 70
Javascript Question

How to disable chrome alert notification?

I need to turn alert notification off by my extension. The alert function is a javascript built-in function and i override it like below in content script but it still works.

content script:

window.alert = function(){}

It does not turn it off. The problem is realy simple but it does not work and i am going crazy :)


"content_scripts": [
"js": [ "assets/js/jquery-1.12.4.min.js", "assets/js/common.js", "assets/js/handlers.js" ],
"matches": [ "http://*/*", "https://*/*" ],
"run_at": "document_start"


window.alert = function (msg) {

Answer Source

You can't switch off notifications globally in Chrome (at least, not that way).

By doing

window.alert = function(){}

you simply switch off notifications for your own extension (= your own window context). You can't do this globally for security reasons (think what malicious extension could do if this was possible).

Edit: you actually can inject your code into the content pages; but this is still not a "global" change that you seek. If you still want this, then:

manifest.js of your extension:

    "name": "MyExtension",
    "permissions": ["tabs", "http://*/*"],
    "content_scripts" : [{
        "js" : ["script.js"]

And your script.js:

window.alert = function(){}