In what scenarios does executeScript + activeTab work?
I’ve been trying to replace <all_urls> with activeTab to execute scripts in pages:
//// manifest.json ////
{
"name": "My extension",
"manifest_version": 3,
"permissions": [ "activeTab", "scripting"],
"background": {
"service_worker": "background.js"
}
}
// background.js
chrome.tabs.onActivated.addListener(activeInfo => {
const { tabId } = activeInfo;
chrome.scripting.executeScript({
target: { tabId, allFrames: true },
files: ['content.js']
});
});
However, this causes error:
Uncaught (in promise) Error: Cannot access contents of the page. Extension manifest must request permission to access the respective host.
But executeScript works in chrome.action.onClicked.addListener().
So I am wondering does this only work in certain scenarios or am I doing something wrong?