Open
Bug 1499667
Opened 6 years ago
Updated 2 years ago
Promise returned by browser.tabs.executeScript is neither resolved nor rejected
Categories
(WebExtensions :: General, defect, P3)
Tracking
(Not tracked)
NEW
People
(Reporter: gildas.lormeau, Assigned: robwu)
References
Details
Attachments
(1 file)
816 bytes,
application/x-zip-compressed
|
Details |
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:63.0) Gecko/20100101 Firefox/63.0
Steps to reproduce:
- Unzip and install the test extension attached
- Go to https://viewfromthewing.boardingarea.com/
- Click the extension button in the toolbar to inject the content script in all the frames
Actual results:
The Developer tools of the background script displays:
"before executeScript ..."
Expected results:
The Developer tools of the background script should have displayed:
"before executeScript ..."
"after executeScript ..."
Or:
"before executeScript ..."
"Error ..."
The same test with Chrome is OK. I develop an extension called "SingleFile" and test it with a lot of sites. This is the only website I know that has this issue. This issue disappears with allFrames set to false instead of true when calling browser.tabs.executeScript.
Reporter | ||
Updated•6 years ago
|
Component: Untriaged → Compatibility
Product: Firefox → WebExtensions
Version: 63 Branch → 62 Branch
Reporter | ||
Updated•6 years ago
|
Component: Compatibility → General
Updated•6 years ago
|
Flags: needinfo?(lgreco)
Reporter | ||
Comment 1•6 years ago
|
||
I have more info about this issue:
- the iframe causing this issue is this one:
<iframe id="sovrn_container" margin="0" padding="0" scrolling="no" src="about:blank" style="margin: 0px; padding: 0px; border: 0px none; width: 1px; height: 1px; overflow: hidden;" width="1" height="1" frameborder="0">
- it contains this script: http://ap.lijit.com/res/sovrn.containertag.min.js?cid=17&aid=218669
- calling contentWindow.stop() in the debugger before clicking the button solves the issue.
Assignee | ||
Comment 2•6 years ago
|
||
Minimal STR. Use the extension from comment #0, and the following HTML document:
index.html
<script>
window.onload = function() {
let f = document.createElement("iframe");
document.body.append(f);
let doc = f.contentDocument;
doc.open();
doc.write("document.write content here");
let but = document.body.appendChild(document.createElement("button"));
but.textContent = "Call document.close()";
but.onclick = function() {
console.log("readyState before: " + doc.readyState);
doc.close();
console.log("readyState after: " + doc.readyState);
};
};
</script>
When I click on the "Call document.close()" button, the script is executed as expected, and the tab's console contains:
readyState before: loading
readyState after: interactive
content script loaded
This is because the default behavior of tabs.executeScript is runAt: "document_idle".
Since the document parsing has not finished (the document.write call was never followed by document.close), the script is still queued and the promise is still pending. If you want the script to execute as soon as possible, use runAt: "document_start".
I am still observing a bug:
- When I reload the page, the executeScript promise is still not resolved, unexpectedly.
(If I add runAt: "document_end", then the promise is resolved when the page reloads).
(in either case, when the tab is closed, the promise is rejected with "Message manager disconnected".)
Assignee | ||
Comment 3•6 years ago
|
||
Upon reloading the page, `documentReadyForIdle` is called as expected, but the callback queued with `requestIdleCallback` [1] is never invoked. Consequently, the document_idle promise is never fulfilled, and consequently the executeScript callback is never called.
[1]: https://searchfox.org/mozilla-central/rev/efc0d9172cb6a5849c6c4fc0f19d7fd5a2da9643/toolkit/components/extensions/ExtensionUtils.jsm#177
Reporter | ||
Comment 4•6 years ago
|
||
Thanks for your help! I confirm that using the option runAt set to "document_start" fixes the issue in SingleFile. I see no problem when I reload the page and try to save it again. This is maybe related to the fact that I call window.stop() on each frame before retrieving their contents.
Updated•6 years ago
|
Flags: needinfo?(lgreco)
Assignee | ||
Updated•6 years ago
|
Assignee: nobody → rob
Status: UNCONFIRMED → NEW
Ever confirmed: true
Updated•6 years ago
|
Assignee: rob → nobody
Status: NEW → UNCONFIRMED
Ever confirmed: false
Priority: -- → P3
Assignee | ||
Updated•6 years ago
|
Assignee: nobody → rob
Status: UNCONFIRMED → NEW
Ever confirmed: true
Updated•2 years ago
|
Severity: normal → S3
You need to log in
before you can comment on or make changes to this bug.
Description
•