如何禁用Chrome警报通知? [英] How to disable chrome alert notification?
问题描述
我需要通过我的扩展程序关闭警报通知.警报功能是javascript的内置函数,我在内容脚本中像下面一样覆盖了它,但仍然可以使用.
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.
内容脚本:
window.alert = function(){}
它不会关闭它.这个问题确实很简单,但是它不起作用,我快要疯了:)
It does not turn it off. The problem is realy simple but it does not work and i am going crazy :)
manifest.json:
manifest.json:
"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"
}
],
handler.js:
handler.js:
window.alert = function (msg) {
debugger;
console.log(msg);
}
推荐答案
您无法在Chrome中全局关闭通知(至少不是那样).
You can't switch off notifications globally in Chrome (at least, not that way).
这样做
window.alert = function(){}
您只需为自己的扩展名(=您自己的window
上下文)关闭通知.出于安全原因,您不能在全球范围内执行此操作(请考虑一下如果可能的话,恶意扩展会做什么).
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).
您实际上可以将您的代码注入到内容页面中;但这仍然不是您要寻求的全球"变化.如果您仍然想要这样做,那么:
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
您的扩展程序:
{
"name": "MyExtension",
...
"permissions": ["tabs", "http://*/*"],
"content_scripts" : [{
"js" : ["script.js"]
}]
}
和您的script.js
:
window.alert = function(){}
这篇关于如何禁用Chrome警报通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!