From 387eaa0b21187182fe600dc36bf8b71711d6615a Mon Sep 17 00:00:00 2001 From: gorhill Date: Thu, 16 Nov 2017 10:55:28 -0500 Subject: [PATCH] fix #3185 --- platform/chromium/manifest.json | 4 ++-- platform/chromium/vapi-background.js | 23 ++++++++++++----------- platform/chromium/vapi.js | 6 ++++-- platform/webext/manifest.json | 8 ++++---- src/js/traffic.js | 10 +++++----- 5 files changed, 27 insertions(+), 24 deletions(-) diff --git a/platform/chromium/manifest.json b/platform/chromium/manifest.json index b02b945b9..c5a631a99 100644 --- a/platform/chromium/manifest.json +++ b/platform/chromium/manifest.json @@ -38,13 +38,13 @@ "content_scripts": [ { "matches": ["http://*/*", "https://*/*"], - "js": ["js/vapi.js", "js/vapi-client.js", "js/contentscript.js"], + "js": ["/js/vapi.js", "/js/vapi-client.js", "/js/contentscript.js"], "run_at": "document_start", "all_frames": true }, { "matches": ["http://*/*", "https://*/*"], - "js": ["js/scriptlets/subscriber.js"], + "js": ["/js/scriptlets/subscriber.js"], "run_at": "document_idle", "all_frames": false } diff --git a/platform/chromium/vapi-background.js b/platform/chromium/vapi-background.js index 4589c8d05..62b37f0cc 100644 --- a/platform/chromium/vapi-background.js +++ b/platform/chromium/vapi-background.js @@ -1031,20 +1031,21 @@ vAPI.onLoadAllCompleted = function() { // http://code.google.com/p/chromium/issues/detail?id=410868#c11 // Need to be sure to access `vAPI.lastError()` to prevent // spurious warnings in the console. - var scriptDone = function() { + var onScriptInjected = function() { vAPI.lastError(); }; var scriptStart = function(tabId) { - vAPI.tabs.injectScript(tabId, { - file: 'js/vapi-client.js', - allFrames: true, - runAt: 'document_idle' - }, function(){ }); - vAPI.tabs.injectScript(tabId, { - file: 'js/contentscript.js', - allFrames: true, - runAt: 'document_idle' - }, scriptDone); + var manifest = chrome.runtime.getManifest(); + if ( manifest instanceof Object === false ) { return; } + for ( var contentScript of manifest.content_scripts ) { + for ( var file of contentScript.js ) { + vAPI.tabs.injectScript(tabId, { + file: file, + allFrames: contentScript.all_frames, + runAt: contentScript.run_at + }, onScriptInjected); + } + } }; var bindToTabs = function(tabs) { var µb = µBlock; diff --git a/platform/chromium/vapi.js b/platform/chromium/vapi.js index 57fd75cca..f62294041 100644 --- a/platform/chromium/vapi.js +++ b/platform/chromium/vapi.js @@ -28,7 +28,7 @@ /******************************************************************************/ // https://bugzilla.mozilla.org/show_bug.cgi?id=1408996#c9 -var vAPI; // jshint ignore:line +var vAPI = window.vAPI; // jshint ignore:line // https://github.com/chrisaljoudi/uBlock/issues/464 // https://github.com/chrisaljoudi/uBlock/issues/1528 @@ -48,7 +48,9 @@ if ( ) && (/^image\/|^text\/plain/.test(document.contentType || '') === false) ) { - vAPI = vAPI instanceof Object && vAPI.uBO === true ? vAPI : { uBO: true }; + vAPI = window.vAPI = vAPI instanceof Object && vAPI.uBO === true + ? vAPI + : { uBO: true }; } /******************************************************************************/ diff --git a/platform/webext/manifest.json b/platform/webext/manifest.json index d3b6cb77d..70e97de5f 100644 --- a/platform/webext/manifest.json +++ b/platform/webext/manifest.json @@ -37,9 +37,9 @@ "file://*/*" ], "js":[ - "js/vapi.js", - "js/vapi-client.js", - "js/contentscript.js" + "/js/vapi.js", + "/js/vapi-client.js", + "/js/contentscript.js" ], "run_at":"document_start", "all_frames":true @@ -50,7 +50,7 @@ "https://*/*" ], "js":[ - "js/scriptlets/subscriber.js" + "/js/scriptlets/subscriber.js" ], "run_at":"document_idle", "all_frames":false diff --git a/src/js/traffic.js b/src/js/traffic.js index 073cd77fb..eaea84158 100644 --- a/src/js/traffic.js +++ b/src/js/traffic.js @@ -46,6 +46,11 @@ var exports = {}; var onBeforeReady = null; +µBlock.onStartCompletedQueue.push(function(callback) { + vAPI.onLoadAllCompleted(); + callback(); +}); + if ( µBlock.hiddenSettings.suspendTabsUntilReady ) { onBeforeReady = (function() { var suspendedTabs = new Set(); @@ -66,11 +71,6 @@ if ( µBlock.hiddenSettings.suspendTabsUntilReady ) { } }; })(); -} else { - µBlock.onStartCompletedQueue.push(function(callback) { - vAPI.onLoadAllCompleted(); - callback(); - }); } /******************************************************************************/