-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
create specification for self.browser #508
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @xeenon! |
8e08253
to
ffcf572
Compare
Co-authored-by: Rob Wu <[email protected]>
Co-authored-by: Rob Wu <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks so much for putting this together, I'm excited! Left a couple of thoughts but this generally looks good.
Co-authored-by: Oliver Dunk <[email protected]>
Co-authored-by: Oliver Dunk <[email protected]>
Co-authored-by: Oliver Dunk <[email protected]>
are you considering renaming this PR (or part of the non-normative sections) to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
@Rob--W any thoughts? |
specification/window.browser.bs
Outdated
When {{browser}} is defined on {{window}}, it SHOULD also be implemented on {{ServiceWorkerGlobalScope}} and {{DedicatedWorkerGlobalScope}}. | ||
It MUST be used exclusively for WebExtension purposes, however the contents of each instance of {{browser}} is UA defined. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: The mention of Service Workers here may raise questions, because Service workers are defined for http(s) URLs only: https://w3c.github.io/ServiceWorker/#start-register-algorithm
(in practice mainly https, http is only supported for edge cases such as localhost).
Chrome (and Firefox's experimental implementation) does not permit extension code to register arbitrary service workers. Instead, the extension framework takes care of registering workers despite the http(s) restrictions.
Should we clarify in a note that extensions cannot register Service workers as usual (i.e. the https restriction), but that browsers may spawn a Service worker associated with a WebExtension origin?
Should we drop the mention of workers entirely from this "window.browser" document, and define the worker behavior in an entirely separate spec/PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback @Rob--W!
because Service workers are defined for http(s) URLs only: https://w3c.github.io/ServiceWorker/#start-register-algorithm (in practice mainly https, http is only supported for edge cases such as localhost).
I am not sure I follow. The spec in this PR says that if window.browser
is defined, then self.browser
should be defined on any ServiceWorkerGlobalScope
whose origin
is a webextension. While the service worker spec is only http(s), the thing that is registered as a background script in Chrome for manifest v3 is
ServiceWorkerGlobalScope
.
Chrome (and Firefox's experimental implementation) does not permit extension code to register arbitrary service workers. Instead, the extension framework takes care of registering workers despite the http(s) restrictions.
If they are not permitted, then I don't see the problem? ServiceWorkerGlobalScope is what is created when you have an extension in Chrome/Firefox's-experimental-implementation. Can you explain what you are wanting changed?
Should we clarify in a note that extensions cannot register Service workers as usual (i.e. the https restriction)
While I see the use for that in a broader web extensions specification, as there is no other portion of this document is about registering a service worker, or when it should be registered on window
. That seems outside of this document's scope.
Should we drop the mention of workers entirely from this "window.browser" document, and define the worker behavior in an entirely separate spec/PR?
Given the current level of web extension specification, having two essentially identical documents to accomplish the same thing ("globalThis.browser
should only be used for web extensions") feels unnecessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback @Rob--W!
because Service workers are defined for http(s) URLs only: https://w3c.github.io/ServiceWorker/#start-register-algorithm (in practice mainly https, http is only supported for edge cases such as localhost).
I am not sure I follow. The spec in this PR says that if
window.browser
is defined, thenself.browser
should be defined on anyServiceWorkerGlobalScope
whoseorigin
is a webextension. While the service worker spec is only http(s), the thing that is registered as a background script in Chrome for manifest v3 is
ServiceWorkerGlobalScope
.
In the realm of specifications, Service Workers (and thus ServiceWorkerGlobalScope instances) only exist on https schemes (and localhost). Here we specify that ServiceWorkerGlobalScope should have a browser object, for WebExtension origins only. I initially found this inconsistent, because the SW spec doesn't leave room for SW on other schemes, while our spec here implies the existence of an extension origin.
I have now reconciled this inconsistency by observing that "extension origin" could theoretically also involve one of the accepted schemes (even though that doesn't happen in practice - as an example from a far past, Chrome had the concept of Hosted apps where regular websites received extra privileges if a crx file defining the "hosted app" was installed).
We (browser vendors) understand the intent and practical meaning here, and I am fine with not mentioning anything more about SW for now.
I know that we wanted us to spec the existence of Chrome (and Safari) both have the concept of "isolated world" for content scripts. An isolated world shares the same view of the DOM (DOM instances from native code are shared), with unique JavaScript wrappers (isolated per world). If Here is some background on isolated world and a description of bindings: https://chromium.googlesource.com/chromium/src.git/+/123.0.6266.0/third_party/blink/renderer/bindings/core/v8/V8BindingDesign.md In Firefox, externally_connectable has not been implemented yet (bug 1319168), which means that there is no |
The Safari and WebKit implementations of web extensions currently dynamically add the It needed to be different since the things contained in the We will likely continue to dynamically add this property to the global scope, instead of adding it in our DOM window IDL. I don't think that fundamentally blocks anything here. Browser implementations can expose the APIs however their implementation requires, as long as it matches how the IDL in the spec defines it. |
Co-authored-by: Rob Wu <[email protected]>
Co-authored-by: Rob Wu <[email protected]>
Co-authored-by: Rob Wu <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! I can't easily verify the preview, but the source looks good!
Create specification for window.browser/self.browser.
preview available here