summaryrefslogtreecommitdiffstats
path: root/toolkit/components/extensions/ExtensionContent.sys.mjs
diff options
context:
space:
mode:
Diffstat (limited to 'toolkit/components/extensions/ExtensionContent.sys.mjs')
-rw-r--r--toolkit/components/extensions/ExtensionContent.sys.mjs18
1 files changed, 15 insertions, 3 deletions
diff --git a/toolkit/components/extensions/ExtensionContent.sys.mjs b/toolkit/components/extensions/ExtensionContent.sys.mjs
index a2fce282ee..83d17ca84e 100644
--- a/toolkit/components/extensions/ExtensionContent.sys.mjs
+++ b/toolkit/components/extensions/ExtensionContent.sys.mjs
@@ -475,6 +475,10 @@ class Script {
* execution is complete.
*/
async inject(context, reportExceptions = true) {
+ // NOTE: Avoid unnecessary use of "await" in this function, because doing
+ // so can delay script execution beyond the scheduled point. In particular,
+ // document_start scripts should run "immediately" in most cases.
+
DocumentManager.lazyInit();
if (this.requiresCleanup) {
context.addScript(this);
@@ -552,11 +556,19 @@ class Script {
let scripts = this.getCompiledScripts(context);
if (scripts instanceof Promise) {
+ // Note: in theory, the following async await could result in script
+ // execution being scheduled too late. That would be an issue for
+ // document_start scripts. In practice, this is not a problem because the
+ // compiled script is cached in the process, and preloading to compile
+ // starts as soon as the network request for the document has been
+ // received (see ExtensionPolicyService::CheckRequest).
scripts = await scripts;
}
- // Make sure we've injected any related CSS before we run content scripts.
- await cssPromise;
+ if (cssPromise) {
+ // Make sure we've injected any related CSS before we run content scripts.
+ await cssPromise;
+ }
let result;
@@ -623,7 +635,7 @@ class Script {
p.catch(error => {
Services.console.logMessage(
new ScriptError(
- `${error.name}: ${error.message}`,
+ error.toString(),
error.fileName,
null,
error.lineNumber,