Bug 1347700 - Fix async loading of content scripts
MozReview-Commit-ID: LjuiizBh1OK
--- a/toolkit/components/extensions/ExtensionContent.jsm
+++ b/toolkit/components/extensions/ExtensionContent.jsm
@@ -255,25 +255,25 @@ Script.prototype = {
this.deferred.resolve();
}
}
let result;
let scheduled = this.run_at || "document_idle";
if (shouldRun(scheduled)) {
- for (let url of this.js) {
- url = this.extension.baseURI.resolve(url);
-
+ for (let [i, url] of this.js.entries()) {
let options = {
target: sandbox,
charset: "UTF-8",
- // Inject asynchronously unless we're expected to inject before any
- // page scripts have run, and we haven't already missed that boat.
- async: this.run_at !== "document_start" || when !== "document_start",
+ // Inject the last script asynchronously unless we're expected to
+ // inject before any page scripts have run, and we haven't already
+ // missed that boat.
+ async: (i === this.js.length - 1) &&
+ (this.run_at !== "document_start" || when !== "document_start"),
};
try {
result = Services.scriptloader.loadSubScriptWithOptions(url, options);
} catch (e) {
Cu.reportError(e);
this.deferred.reject(e);
}
}