I'm getting this error when attempting to dynamically inject a script into an iFrame of the active tab:
Error encountered: Error: error injecting script into tab '1071087490' and frame '350': Error: Cannot access contents of the page. Extension manifest must request permission to access the respective host.
Here's my code:
chrome.scripting.executeScript({
target: {
tabId: tab.id!,
frameIds: [frameId],
},
files: [contentScript],
}),
And my manifest permissions:
permissions: [
"storage",
"contextMenus",
"activeTab",
"scripting",
"webNavigation",
],
The injection process is started when the user selects a context menu item, which I believe gives me host_permissions to go HOG WILD! on the active tab, including the iFrames within it, but I'm being denied!
ideas:
Maiybe there's something with the iFrames url that makes it a cross-origin issue, and I'm denied for that reason. Here are the urls of the tab and the iFrame:
Tab:
https://www.thewebsite.app.thewebsiteinc.com/profound
iFrame:
I think that the domains should work okay, though.
Idea 2:
My god-like host_permissions for the active tab are lost somewhere as I'm calling my code. Somehow the magic powers granted to me with the activeTab permission when the user invokes the context menu are lost by the time I go to insert the page.
My code flow:
background.ts: registers an asynchronous event handler for the chrome.contextMenus.OnClicked event. The handler code is in another typescript module.
handleMenuitemClick.ts: attempts to inject the script first. It calls a function in another typescript module in my extension code to do this.
Last thoughts:
When inserting into the tab itself, frameId = 0, all is well. But I get the failure when attempting to insert into that iFrame.
This isn't an issue when I use chrome.scripting.executeScript() with allFrames: true. I do see my content script inserted when I inspect the source files of the page in chrome's developer tools, but I don't know if the script was just inserted into the tab, and not the iFrame (anyone know how to check if the content script was inserted into an iFrame of the tab?).
Thanks for reading all this and your help!