admin管理员组文章数量:1333414
I'm trying to make a simple Chrome Addon to remove every event from domain x. I've looked into it and found out about the "beforeload" event listener, this is apparently what things like adblock use to block ads pletely from loading. I've implemented this into the addon and added things like console.log("addon loaded") to be sure it's actually loading the javascript, but the problem is, it only catches a handful of the events, for instance on a page of 50 events, it catches only maybe 1-2. It misses obvious other things.
twitch.js
document.addEventListener("beforeload", function(event) {
event.preventDefault();
$(event.target).remove();
}, true);
manifest.json
...
"content_scripts": [ {
"js": [ "js/jquery.js", "js/twitch.js" ],
"css": [ "css/twitch.css"],
"matches": ["*://*/*"],
"run_at": "document_start",
"all_frames" : true
}],
...
Does anyone have any ideas?
I'm trying to make a simple Chrome Addon to remove every event from domain x. I've looked into it and found out about the "beforeload" event listener, this is apparently what things like adblock use to block ads pletely from loading. I've implemented this into the addon and added things like console.log("addon loaded") to be sure it's actually loading the javascript, but the problem is, it only catches a handful of the events, for instance on a page of 50 events, it catches only maybe 1-2. It misses obvious other things.
twitch.js
document.addEventListener("beforeload", function(event) {
event.preventDefault();
$(event.target).remove();
}, true);
manifest.json
...
"content_scripts": [ {
"js": [ "js/jquery.js", "js/twitch.js" ],
"css": [ "css/twitch.css"],
"matches": ["*://*/*"],
"run_at": "document_start",
"all_frames" : true
}],
...
Does anyone have any ideas?
Share Improve this question edited Jul 8, 2012 at 20:57 Wladimir Palant 57.7k12 gold badges99 silver badges127 bronze badges asked Jul 8, 2012 at 20:04 clone1018clone1018 1,2672 gold badges11 silver badges13 bronze badges1 Answer
Reset to default 5beforeload
is called once for each script, iframe, image and stylesheet on the page, not for every event (do you mean element?). Were you expecting other elements to raise this event?
This document, Blocking Unwanted Content, mentions a requirement:
To block content, your script must be run as a Start Script, so that it executes before the content is displayed.
So check that. Also, you don't need the .remove()
line, just calling event.preventDefault()
will stop the creation of the resource.
document.addEventListener( 'beforeload', function( event ) {
event.preventDefault();
}, true );
本文标签: javascriptaddEventListener(quotbeforeloadquot) missing eventsStack Overflow
版权声明:本文标题:javascript - addEventListener("beforeload") missing events - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742328568a2454223.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论