What could be the reason why script only run once for a Chrome extension? Here is our code:
inject.js
var s = document.createElement('script');
// TODO: add "script.js" to web_accessible_resources in manifest.json
s.src = chrome.extension.getURL('script.js');
s.onload = function() {
this.remove();
};
(document.head || document.documentElement).appendChild(s);
$( document ).ready(function() {
console.log("start")
//$("body").bind("DOMSubtreeModified", function() {
$("#btn").click(function(){
console.log("do something")
});
//});
});
The expected behavior is for the click event to be fired everytime the #btn
is clicked, however it only works once the page reloads and the succeeding clicks does not trigger what could be the bug here?
The click event will trigger every time if we bind to the DOMSubtreeModified
however there are side effects, since our actual code calls for ajax resource, having the bind to DOMSubtreeModified
fires the ajax request continuously as the page DOM changes.