Closed Bug 1352917 Opened 7 years ago Closed 7 years ago

Cannot executeScript to a specific sub-frame before its own scripts run; get "no window matching" error when trying.

Categories

(WebExtensions :: General, enhancement)

enhancement
Not set
normal

Tracking

(Not tracked)

RESOLVED DUPLICATE of bug 1332273

People

(Reporter: wisniewskit, Unassigned)

Details

Unlike top frames, it is not possible to executeScript(document_start) to a sub-frame during a webNavigation.onCommitted event (or similar early events). The window of the subframe's frameId simply isn't found:

>Unchecked lastError value: Error: No window matching >{"frame_id":10737418244,"matchesHost":["<all_urls>"]}

Note that doing an executeScript(document_idle) does work, as does triggering the executeScript during a later time, such as webNavigation.onDOMComplete.

However that's too late to be able to execute a script in the frame before its own scripts begin to run, which is something that's effectively blocking me in an addon I'm writing for the web compat team.

I did some investigating, and it's simply because the frame truly isn't ready yet. It's URI is still about:blank, the contentWindow doesn't exist, and the docshell view of the object still has a childCount of 0.

I'm not sure what value onCommitted has for subframes if this is true? Would it be against the spec to wait until the contentWindow is ready, before the subframe's own scripts have run? I see this:

>Fired when a navigation is committed. At least part of the new document has been received from the server and the browser has decided to switch to the new document.

But I don't see why it precludes waiting until the contentWindow object is at least formed. After all, the top frame doesn't get onCommitted until its window is ready.

Thoughts? If we're not against such a change (or adding a new event between onCommitted and when the subframe's own scripts run) then I don't mind helping to implement it. I would just need pointers as to what the correct fix would be.
Flags: needinfo?(kmaglione+bmo)
There are no guarantees that `executeScript` called from onCommitted, or content scripts executed in any way other than a manifest "content_scripts" entry, will run before page scripts.
Flags: needinfo?(kmaglione+bmo)
Thanks. That's just not good enough for my purposes, from what I can see. I need my background script to be able to open a new tab, seed the initial window state somehow before the page scripts run. I can't call chrome.runtime.sendMessage from the content script to get the data, as that will usually call back after the page scripts begin to run. I can't modify the URL I open the tab with, or the cookie, as the data I'm seeding with can be prohibitively large. I can't seed Session/LocalStorage from a background script, either.

Is there another way I'm missing where I can pass data from the background script to the tab's content script *before* the page scripts run? Would we be against adding a new event type to allow such a guarantee? (Again I don't mind implementing it, with guidance).
Flags: needinfo?(kmaglione+bmo)
yes, bug 1332273
Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → DUPLICATE
Flags: needinfo?(kmaglione+bmo)
Thanks, :zombie! I'll follow up in that bug.
Product: Toolkit → WebExtensions
You need to log in before you can comment on or make changes to this bug.