I am calling a Chrome extension from a web portal to open a URL in a new tab, and on the newly opened tab I want to perform executeScript
:
manifest.json
"externally_connectable": {
"matches": ["http://localhost:3000/*"]
},
"permissions": ["tabs", "http://*/*", "https://*/*"]
background.js
// listen to webportal
chrome.runtime.onMessageExternal.addListener(
function(request, sender, sendResponse) {
a = chrome.tabs.create({ url: request.openUrlInEditor });
chrome.tabs.insertCSS(a.id, { file: "combined.css" });
chrome.tabs.executeScript(a.id, { file: "combined.js" });
}
);
If I try to perform insertCSS
and executeScript
on extension click,
it works fine
background.js
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.insertCSS(tab.id, { file: "combined.css" });
chrome.tabs.executeScript(tab.id, { file: "combined.js" });
});