My extension is supposed to inject js-code to scrape the active tab for images when the popup is opened.
I encountered a problem in amazon.DE where the JS-code breaks at the point of script injection, but not amazon.COM! No codes after the injection get's executed and I get no error message in the consoles of both my popup nor the active Tab.
I think the issue comes down to the code being injected into all [frames][edit], not all of which share their host with the active tab.
From my manifest.json:
{
"manifest_version": 3,
"permissions": [
"storage",
"unlimitedStorage",
"activeTab",
"scripting",
"webNavigation"
]
}
The code I use for injection:
async scrape() {
let tabs = await chrome.tabs.query({ currentWindow: true, active: true });
let tab = tabs[0];
let frames = await chrome.scripting.executeScript({
target:{tabId: tab.id, allFrames: true},
func:grabImages
});
My bug testing has yielded the following:
- the script always gets injected in the frames I care about (main frames). It can do what I want it to do there.
- if the script injects via
allFrames: trueinto amazon.COM I don't have an issue - if the script injects via
frameIds: [list, of, ids, of, all, frames]it breaks with the error message:Uncaught (in promise) Error: Cannot access contents of the page. Extension manifest must request permission to access the respective host. - if the script injects via
allFrames:trueinto amazon.DE it breaks without any error message - the code works fine on the amazon.DE homepage, it only fails on the product pages
- if I click my extension fast enough, before the product page of amazon is fully loaded it works (kinda, it is missing some images that are present on the fully loaded page)
- the amazon.COM product page has 3 frames, the amazon.DE frames has 7.
My questions are:
- What is the difference between injecting via
allFrames: truevs injecting viaframeIds: []that leads to the difference in outcome? - Why does "allFrames: true" work on amazon.COM but fails silently on amazon.DE?