w3c / webextensions

Charter and administrivia for the WebExtensions Community Group (WECG)
Other
576 stars 50 forks source link

sidePanel API: site-specific panels #618

Open tophf opened 1 month ago

tophf commented 1 month ago

Currently, if we want to toggle side panel's availability for a given tab id depending on its URL, we have to observe navigation in all tabs all the time, which frequently wakes up the background script, because we can't use url-filtering in webNavigation.onCommitted (or a filtered tabs.onUpdated in Firefox): it won't be triggered in the tab that previously contained our supported site example.com, but then was navigated to unsupported.com. We also can't register a listener for this tab id dynamically because such listeners won't wake up the background script.

Add URL patterns to chrome.sidePanel.setOptions()

It would be fully declarative, no need to observe navigation, here's some naming ideas:

Add documentId to chrome.sidePanel.setOptions()

Specifying documentId will automatically discard the specific options object when the page is destroyed on navigation or when the tab is closed, which will restore the global mode that we set in chrome.sidePanel.setOptions({enabled: false}). This solution can be used on top of the other solutions.

chrome.runtime.onInstalled.addListener(() => {
  chrome.sidePanel.setOptions({enabled: false});
});
chrome.webNavigation.onCommitted.addListener(e => {
  if (e.frameId) return;
  chrome.sidePanel.setOptions({
    enabled: true,
    tabId: e.tabId,
    documentId: e.documentId,
  });
}, {url: [{hostEquals: 'example.com'}]});

Add SetSidePanel action with parameters to declarativeContent API

A fully declarative method similar to SetIcon action. The declarativeContent API already supports advanced URL filtering.