Google Chrome Extension: Inject contentscript in a webpage with js errors

Because the webpage contains errors, we can't inject directly the content script using this code in the manifest.json file
"content_scripts": [
      "matches": ["http://*/*"],
      "js": ["jquery.js", "content_script.js"]
But we can inject the code each time the page is changed using an url change event listener, inserting the following code in the background.html page:
	if(changeInfo.status == "complete" && (tab.url.substr(0,25) == "" || tab.url.substr(0,26) == "") ){
		chrome.tabs.executeScript(null, {file: "jquery.js"});
		chrome.tabs.executeScript(null, {file: "content_script_injected.js"});
This entry was posted in Uncategorized and tagged . Bookmark the permalink.

Comments are closed.