Skip to content

Commit

Permalink
Register listeners ASAP to make Manifest V3 friendly
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Jan 22, 2024
1 parent fb58623 commit f4b2477
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
3 changes: 2 additions & 1 deletion webextensions/background/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ async function getAllWindows() {

log('init: Start queuing of messages notified via WE APIs');
ApiTabsListener.init();
const promisedRestored = waitUntilCompletelyRestored(); // this must be called synchronosly

export async function init() {
log('init: start');
Expand Down Expand Up @@ -101,7 +102,7 @@ export async function init() {
let promisedWindows;
log('init: Getting existing windows and tabs');
await MetricsData.addAsync('init: waiting for waitUntilCompletelyRestored, ContextualIdentities.init and configs.$loaded', Promise.all([
waitUntilCompletelyRestored().then(() => {
promisedRestored.then(() => {
// don't wait at here for better performance
promisedWindows = getAllWindows();
}),
Expand Down
10 changes: 8 additions & 2 deletions webextensions/background/handle-misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,15 @@ let mInitialized = false;
// unneeded cases.
// See also: https://github.com/piroor/treestyletab/issues/2200

Background.onInit.addListener(() => {
(browser.action || browser.browserAction).onClicked.addListener(onToolbarButtonClick);
if (browser.action) { // Manifest V3
browser.action.onClicked.addListener(onToolbarButtonClick);
browser.commands.onCommand.addListener(onShortcutCommand);
}
Background.onInit.addListener(() => {
if (browser.browserAction) { // Manifest V2
browser.browserAction.onClicked.addListener(onToolbarButtonClick);
browser.commands.onCommand.addListener(onShortcutCommand);
}
TSTAPI.onMessageExternal.addListener(onMessageExternal);
});

Expand Down

0 comments on commit f4b2477

Please sign in to comment.