You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(Please fill out the issue template with your details)
Expected Behavior
Let's say we have userscript1 (pos # 1) and userscript2 (pos # 2).
If neither have a top-level await, userscript1 will execute from start to finish, and then userscript2 will execute from start to finish.
If userscript1 has a top-level await (in Chrome it needs to be put on the event loop and not executed directly, like a fetch), you'd expect the code afterwards to finish executing before userscript2 starts executing.
Actual Behavior
userscript2 in most cases will start executing before the remaining code of userscript1 that is after the top-level await.
If the execution order of userscripts isn't guaranteed, then what's the point of specifying the position setting of each?
Top-level await works only in script modules where dependency on other scripts (modules) is clearly defined.
Userscripts don't have such dependency definition, and it will cause trouble for people with hundreds of scripts per page.
If you need to await another script, use markers and events:
// userscript1awaitsomething;window.dispatchEvent(newCustomEvent("script-finished",{detail: { foo, bar }}));document.documentElement.classList.add("script1-finished");// userscript2if(document.documentElement.classList.contains("script1-finished")){// userscript1 already finished}else{window.addEventListener("script-finished",(ev)=>{const{ foo, bar }=ev.detail;// do something});}
(Please fill out the issue template with your details)
Expected Behavior
Let's say we have userscript1 (pos # 1) and userscript2 (pos # 2).
If neither have a top-level await, userscript1 will execute from start to finish, and then userscript2 will execute from start to finish.
If userscript1 has a top-level await (in Chrome it needs to be put on the event loop and not executed directly, like a
fetch
), you'd expect the code afterwards to finish executing before userscript2 starts executing.Actual Behavior
userscript2 in most cases will start executing before the remaining code of userscript1 that is after the top-level await.
If the execution order of userscripts isn't guaranteed, then what's the point of specifying the position setting of each?
Specifications
Script
Output:
I think a possible solution could be to just wrap each userscript in an async function and await a call to it.
The text was updated successfully, but these errors were encountered: