Open xeenon opened 1 year ago
AFAIK, Chrome verifies parameters against a schema for many years, maybe from the very beginning, so extending the existing methods wouldn't crash an old Chrome, it would just report an error. I'm not saying it'd be a better solution though, because developers would have to either use try{}catch{} (and what's worse .catch() wouldn't work at least in Chrome as far as I know as the error is thrown by the JS shim) or check the version of the browser, which is an anti-pattern in general.
Regarding the name, maybe it could be just set
or setOptions
or configure
and accept various other aspects like title and color?
Yeah, I know Chrome is strict with argument type checks. I think all browsers are in this regard. That's why changing the allow types for enable()
and disable()
would likely be off the table without a manifest version bump.
Questions for Chrome (https://github.com/w3c/webextensions/labels/follow-up%3A%20chrome):
windowId
option in action API? (tabId > windowId > manifest-specified default)enable
/disable
methods to also accept an object instead of just an integer option? (the old signature is kept for backcompat and can be removed only in a new manifest version)Additional thoughts on:
Supportive of windowId option in action API? (tabId > windowId > manifest-specified default)
Yes.
Supportive of overloading the enable/disable methods to also accept an object instead of just an integer option? (the old signature is kept for backcompat and can be removed only in a new manifest version)
Yes.
Re setEnabled()
vs updating enable()
and disable()
-- there's no harm in changing the signature (still backwards compatible), and one of the pieces that hasn't been mentioned here is the isEnabled()
function. isEnabled()
currently only accepts a tabId in Chrome, so we'd need to change that to accept an object. Since we'd already be changing signatures of existing methods, I'd lean towards just using the existing enable()
and disable()
rather than introducing a new method.
There is an inconsistency in the
browser.action
APIs with thewindowId
key. Currently, this key is only supported in Firefox but is slated for future implementation in Safari. This feature is essential for extensions aiming to synchronize action customizations across all tabs within a specific window.In Firefox, the
windowId
key allows extensions to uniformly apply action states to all tabs within a designated window.In Firefox's existing API design, the options dictionary should specify either a
tabId
or awindowId
. This approach ensures that action states are applied on either a per-tab or per-window basis. Safari plans to adopt this behavior.Contrastingly, the
enable()
anddisable()
methods currently only accept atabId
as an argument:Proposed Changes
To harmonize these APIs, I propose adopting
windowId
in all action methods to match Firefox's existing behavior. Additionally, a newsetEnabled()
method is proposed. This method would accept an options dictionary that can includetabId
,windowId
, andenabled
keys.This new method offers a consistent way to manage action enabled states across both tabs and windows. The existing
enable()
anddisable()
methods would be deprecated until removed in a future manifest version.Alternate Solution
An alternative to introducing
setEnabled()
would be to update the existingenable()
anddisable()
methods. These methods could accept an options dictionary, in addition to the currenttabId
argument:This alternative also maintains backward compatibility while providing the flexibility to manage action enabled states across different tabs and windows.
Compatibility Considerations
This proposal aims to extend existing APIs in a backward-compatible manner. Nevertheless, the introduction of the
windowId
key and an options dictionary inenable()
anddisable()
could cause exceptions in older browsers. The introduction ofsetEnabled()
offers the advantage of being feature-detectable from JavaScript. Developers would be strongly advised to test compatibility.