Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
Do not update toolbar button state inside tab 'activated' event handler
Browse files Browse the repository at this point in the history
According to kmag, webextension buttons have per-tab state, so setting
the button enabled or disabled on update should be enough. Updating the
icon on tab activated may be causing performance issues.

See https://bugzilla.mozilla.org/show_bug.cgi?id=1361792 for details.

Also remove tab.active check, so that non-active tabs can catch button
updates (https://bugzilla.mozilla.org/show_bug.cgi?id=1362234#c2)
  • Loading branch information
jaredhirsch committed May 5, 2017
1 parent 81a567a commit f63b90e
Showing 1 changed file with 1 addition and 15 deletions.
16 changes: 1 addition & 15 deletions addon/webextension/background/main.js
Expand Up @@ -199,7 +199,7 @@ this.main = (function() {
}

browser.tabs.onUpdated.addListener(catcher.watchFunction((id, info, tab) => {
if (info.url && tab.active) {
if (info.url) {
if (urlEnabled(info.url)) {
enableButton(tab.id);
} else if (hasSeenOnboarding) {
Expand All @@ -208,20 +208,6 @@ this.main = (function() {
}
}, true));

browser.tabs.onActivated.addListener(catcher.watchFunction(({tabId, windowId}) => {
catcher.watchPromise(browser.tabs.get(tabId).then((tab) => {
// onActivated may fire before the url is set
if (!tab.url) {
return;
}
if (urlEnabled(tab.url)) {
enableButton(tabId);
} else if (hasSeenOnboarding) {
disableButton(tabId);
}
}), true);
}, true));

communication.register("sendEvent", (sender, ...args) => {
catcher.watchPromise(sendEvent(...args));
// We don't wait for it to complete:
Expand Down

0 comments on commit f63b90e

Please sign in to comment.