w3c / webextensions

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

Determine the nuances of aliasing `chrome` and `browser` #532

Open patrickkettner opened 5 months ago

patrickkettner commented 5 months ago

Now that #508 has been merged (🎉), our team began discussing the specifics on how to alias chrome to browser. It turns out, what we want to do is different from everyone, but also everyone is different from everyone.

In Firefox, chrome and browser appear to be clones of the same object. So the values are the same, but updating one does not change another.

browser.foo = 123
console.log(browser.foo)
123
console.log(chrome.foo)
undefined

In Safari, chrome and browser appear to be a direct alias to one another

browser.foo = 123
console.log(browser.foo)
123
console.log(chrome.foo)
123

What Chrome wants to do is make chrome and browser separate objects, but make the various properties of each object a direct alias.

So in the above example, the Firefox behavior would be matched

browser.foo = 123
console.log(browser.foo)
123
console.log(chrome.foo)
undefined

But modifying a specific property or value inside of chrome or browser would update the other.

browser.runtime.PlatformArch.ARM = 123
console.log(browser.runtime.PlatformArch.ARM)
123
console.log(chrome.runtime.PlatformArch.ARM)
123

The reason why we like this option is the mix of ease of implementation from aliasing, while also allowing us to sluff off APIs we do not want to carry forward into browser.

xeenon commented 5 months ago

I see the benefit of having separate namespace objects for each, while sharing everything else internally. However, that would be technically tricky for Safari/WebKit to support. In practice, we don't anticipate the need to have them be separate for us, so we will likely keep our implantation as-is (direct aliases of one another, described above).

@patrickkettner What APIs do you plan to "sluff off" of browser?

tophf commented 5 months ago

to sluff off APIs we do not want to carry forward into browser.

This implies browser is the successor of chrome and not an alias, which doesn't seem conceptually justified. Edit: although removing junk like csi and loadTimes would indeed make sense as the next comment says.

hanguokai commented 5 months ago
Screenshot 2024-02-01 at 17 10 00

The reason why we like this option is the mix of ease of implementation from aliasing, while also allowing us to sluff off APIs we do not want to carry forward into browser.

chrome has some non-extension properties, like chrome.loadTimes. This approach allows Chrome to keep chrome for some private APIs, and browser only contains extension-related APIs. IMO, from a practical perspective, whether chrome === browser should not have much impact on developers.

patrickkettner commented 5 months ago

@xeenon > What APIs do you plan to "sluff off" of browser? I don't have a definitive list, but I would imagine things like loadTimes or csi, that are not Chrome specific (thanks @hanguokai!).

patrickkettner commented 5 months ago

During the call outlined in #537, I believe that the following was agreed on

@oliverdunk @zombie @xeenon @Rob--W is the above true?

xeenon commented 5 months ago

Sounds good.

oliverdunk commented 5 months ago

Sounds good to me.