Skip to content

Commit

Permalink
Fix resolving the promise if there is no scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
smalluban committed Jul 25, 2022
1 parent 11cc91c commit 1907f40
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions packages/adblocker-webextension/adblocker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,7 @@ export class WebExtensionBlocker extends FiltersEngine {
browser: Browser,
msg: IBackgroundCallback & { action?: string },
sender: Runtime.MessageSender,
sendResponse: (response?: IMessageFromBackground) => void,
): Promise<void> => {
): Promise<IMessageFromBackground | undefined> => {
const promises: Promise<void>[] = [];

// Make sure we only listen to messages coming from our content-script
Expand Down Expand Up @@ -361,6 +360,8 @@ export class WebExtensionBlocker extends FiltersEngine {
);
}

let response: IMessageFromBackground | 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,
Expand Down Expand Up @@ -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;
};

/**
Expand Down Expand Up @@ -451,9 +453,7 @@ export class WebExtensionBlocker extends FiltersEngine {
msg: IBackgroundCallback & { action?: string },
sender: Runtime.MessageSender,
): Promise<IMessageFromBackground | undefined> => {
return new Promise((resolve, reject) => {
this.handleRuntimeMessage(browser, msg, sender, resolve).catch(reject);
});
return this.handleRuntimeMessage(browser, msg, sender);
};

private async injectStylesWebExtension(
Expand Down

0 comments on commit 1907f40

Please sign in to comment.