1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2024-12-22 12:50:36 +01:00

Handle wrong content script order

For #273
This commit is contained in:
kkapsner 2018-10-02 13:20:40 +02:00
parent a4d9be9bd5
commit f3a6031f5a
3 changed files with 19 additions and 7 deletions

View File

@ -95,11 +95,11 @@
allFrames: true,
runAt: "document_start",
js: [{
code: `(function(){
code: `(function(settingsData){
if (typeof require !== "undefined"){
const settings = require("./settings");
const logging = require("./logging");
if (settings.init(${JSON.stringify(data)})){
if (settings.init(settingsData)){
logging.message("Initialized settings by dynamic content script.");
}
else {
@ -107,12 +107,16 @@
}
}
else {
console.error(
"[CanvasBlocker] invalid content scripts: require not defined at",
if (!window.scope){
window.scope = {};
}
window.scope.settingsData = settingsData;
console.warn(
"[CanvasBlocker] invalid content script order: require not defined at",
window.location.href
);
}
}())`
}(${JSON.stringify(data)}))`
}]
}).then(function(api){
logging.verbose("Content script registered.");

View File

@ -4,7 +4,9 @@
const require = function(){
"use strict";
window.scope = {};
if (!window.scope){
window.scope = {};
}
const scope = window.scope;
function getScopeName(module){

View File

@ -415,7 +415,13 @@
initEvents.forEach(function(callback){callback();});
return true;
};
scope.loaded = browser.storage.local.get().then(scope.init);
if (window.scope.settingsData){
scope.init(window.scope.settingsData);
scope.loaded = Promise.resolve(false);
}
else {
scope.loaded = browser.storage.local.get().then(scope.init);
}
scope.onloaded = function(callback){
if (scope.isStillDefault){
initEvents.push(callback);