browser.runtime.onInstalled does not fire for async scripts
Categories
(WebExtensions :: Untriaged, defect)
Tracking
(Not tracked)
People
(Reporter: 5i13ghzt462u, Assigned: robwu)
Details
Updated•6 years ago
|
Assignee | ||
Comment 1•6 years ago
|
||
Sorry for the late reply, but this still does not make sense to me.
AFAIK the order in which the events/things happen is this:
async scripts start running -> DOMContentLoaded + onInstalled -> deferred script start
So if I add an onInstalled listener in my async script to wait for the event, then I am just faster than any deferred scripts and it should actually be the same as if I load my own script later.
Actually, it would make more sense to me when the deferred could have problems, because DOMContentLoaded and thus onInstalled fires before they get started, but apparently they don't have.
Assignee | ||
Comment 3•5 years ago
|
||
I think that you've either mixed up the meaning of async
or defer
, or don't understand what these do.
From MDN: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script
async For classic scripts, if the
async
attribute is present, then the classic script will be fetched in parallel to parsing and evaluated as soon as it is available.
defer This Boolean attribute is set to indicate to a browser that the script is meant to be executed after the document has been parsed, but before firingDOMContentLoaded
.
In other words, defer
is guaranteed to run before DOMContentLoaded
, whereas async
is run "as soon as it is available", which may be before DOMContentLoaded
, but potentially also afterwards.
You can easily test the expected behavior by loading scripts with and without defer
/ async
, and delaying the completion of the requests for script/HTML.
- Load order = defer, async, HTML gives execution order = async, defer, DOMContentLoaded.
- Load order = async, defer, HTML gives execution order = async, defer, DOMContentLoaded.
- Load order = HTML, async, defer gives execution order = async, defer, DOMContentLoaded.
- Load order = HTML, defer, async gives execution order = defer, DOMContentLoaded, async.
Results obtained in Firefox Nightly 76.0a1 buildID 20200319193622, with nc
(netcat) to manually control the order of responses.
Okay thanks for the detailed answer, so it is indeed "just" that async may (in, I guess, really not many cases though) run later than defer. That makes sense though, as "unintuitive" this behaviour seems to me, anyway.
Description
•