Skip to content

Commit f3a6031

Browse files
committed
Handle wrong content script order
For #273
1 parent a4d9be9 commit f3a6031

3 files changed

Lines changed: 19 additions & 7 deletions

File tree

lib/main.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,24 +95,28 @@
9595
allFrames: true,
9696
runAt: "document_start",
9797
js: [{
98-
code: `(function(){
98+
code: `(function(settingsData){
9999
if (typeof require !== "undefined"){
100100
const settings = require("./settings");
101101
const logging = require("./logging");
102-
if (settings.init(${JSON.stringify(data)})){
102+
if (settings.init(settingsData)){
103103
logging.message("Initialized settings by dynamic content script.");
104104
}
105105
else {
106106
logging.error("Dynamic content script was too late to provide settings.");
107107
}
108108
}
109109
else {
110-
console.error(
111-
"[CanvasBlocker] invalid content scripts: require not defined at",
110+
if (!window.scope){
111+
window.scope = {};
112+
}
113+
window.scope.settingsData = settingsData;
114+
console.warn(
115+
"[CanvasBlocker] invalid content script order: require not defined at",
112116
window.location.href
113117
);
114118
}
115-
}())`
119+
}(${JSON.stringify(data)}))`
116120
}]
117121
}).then(function(api){
118122
logging.verbose("Content script registered.");

lib/require.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
const require = function(){
66
"use strict";
7-
window.scope = {};
7+
if (!window.scope){
8+
window.scope = {};
9+
}
810
const scope = window.scope;
911

1012
function getScopeName(module){

lib/settings.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,13 @@
415415
initEvents.forEach(function(callback){callback();});
416416
return true;
417417
};
418-
scope.loaded = browser.storage.local.get().then(scope.init);
418+
if (window.scope.settingsData){
419+
scope.init(window.scope.settingsData);
420+
scope.loaded = Promise.resolve(false);
421+
}
422+
else {
423+
scope.loaded = browser.storage.local.get().then(scope.init);
424+
}
419425
scope.onloaded = function(callback){
420426
if (scope.isStillDefault){
421427
initEvents.push(callback);

0 commit comments

Comments
 (0)