From d59eeba8e2de3980bc0a4db57d6c0c4e2d212675 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Tue, 4 Apr 2023 14:28:48 -0400 Subject: [PATCH] Fix tabs.executeScript() not resolving in due time Related feedback: - https://github.com/gorhill/uBlock/commit/6efd8eb84aaae43b05c3e9f2bffd13cf85f16018 --- src/js/messaging.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/js/messaging.js b/src/js/messaging.js index 5c4a0d82e..4bfb82ee9 100644 --- a/src/js/messaging.js +++ b/src/js/messaging.js @@ -609,6 +609,10 @@ const onMessage = function(request, sender, callback) { }); return; + // https://github.com/gorhill/uBlock/commit/6efd8eb#commitcomment-107523558 + // Important: for whatever reason, not using `document_start` causes the + // Promise returned by `tabs.executeScript()` to resolve only when the + // associated tab is closed. case 'launchReporter': { const pageStore = µb.pageStoreFromTabId(request.tabId); if ( pageStore === null ) { break; } @@ -619,6 +623,7 @@ const onMessage = function(request, sender, callback) { allFrames: true, file: '/js/scriptlets/cosmetic-report.js', matchAboutBlank: true, + runAt: 'document_start', }).then(results => { const filters = results.reduce((a, v) => { if ( Array.isArray(v) ) { a.push(...v); }