From 2742f09dc2cdd3659a5709ad063ebb85d72ad680 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Luba=C5=84ski?= Date: Mon, 25 Jul 2022 09:28:06 +0200 Subject: [PATCH] Fix resolving the promise if there is no scripts --- packages/adblocker-webextension/adblocker.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/adblocker-webextension/adblocker.ts b/packages/adblocker-webextension/adblocker.ts index 1c9a1dae2f..e78e958e41 100644 --- a/packages/adblocker-webextension/adblocker.ts +++ b/packages/adblocker-webextension/adblocker.ts @@ -298,8 +298,7 @@ export class WebExtensionBlocker extends FiltersEngine { browser: Browser, msg: IBackgroundCallback & { action?: string }, sender: Runtime.MessageSender, - sendResponse: (response?: IMessageFromBackground) => void, - ): Promise => { + ): Promise => { const promises: Promise[] = []; // Make sure we only listen to messages coming from our content-script @@ -361,6 +360,8 @@ export class WebExtensionBlocker extends FiltersEngine { ); } + let response: IMessageFromBackground | undefined = undefined; + // Separately, requests cosmetics which depend on the page it self // (either because of the hostname or content of the DOM). Content script // logic is responsible for returning information about lists of classes, @@ -396,16 +397,17 @@ export class WebExtensionBlocker extends FiltersEngine { // Inject scripts from content script if (scripts.length !== 0) { - sendResponse({ + response = { active, extended, scripts, styles: '', - }); + }; } } await Promise.all(promises); + return response; }; /** @@ -451,9 +453,7 @@ export class WebExtensionBlocker extends FiltersEngine { msg: IBackgroundCallback & { action?: string }, sender: Runtime.MessageSender, ): Promise => { - return new Promise((resolve, reject) => { - this.handleRuntimeMessage(browser, msg, sender, resolve).catch(reject); - }); + return this.handleRuntimeMessage(browser, msg, sender); }; private async injectStylesWebExtension(