I am trying to inject content script via chrome.tabs.executeScript command, but it try to inject to every opened tab on the browser.
There is a way to deremine if the extension have the right permission for the tab (in the manifest.json, permissions key) before trying to inject script?
My error is: Unchecked runtime.lastError: Cannot access contents of url "https://exmaple.com/". Extension manifest must request permission to access this host.
My code is:
const chromeManifest = chrome.runtime.getManifest();
chrome.tabs.query({}, tabs => {
const [script] = chromeManifest?.content_scripts?.[0].js;
tabs.forEach(tab => {
/* HERE CHECK IF THERE IS PERMISSION FOR THE TAB */
chrome.tabs.executeScript(tab.id, {
file: script,
});
});
});