chrome.tabs.onUpdated.addListener( function (tabId, changeInfo, tab) {
if (changeInfo.status == 'complete' && tab.active) {
chrome.tabs.query({active: true,lastFocusedWindow: true}, function(tabs) {
var tab = tabs[0];
if(tab.url.indexOf("local")>-1){
function(tab){
alert("Test");
chrome.tabs.executeScript(null,{code:"document.body.style.backgroundColor='yellow'"});
console.log("injected");
}
}
}
}
});
This is manifest.json:
{
"manifest_version": 2,
"name": "Environment Locator",
"description": "My Extension",
"version": "1.0",
"permissions": [
"tabs"
],
"background": {
"scripts": ["background.js"] ,
"persistent": false
}
}
I want to inject some js code using chrome extensions to the pages whose URLs contain some predefined strings. 1. I want this code will be displayed in all the pages. When tab is updated the url should be checked again. 2. Extension will be run without any user click. No pop up.