Skip to content
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

documentUrl and documentOrigin should be just url and origin in runtime.getContexts and be defined for the worker context #695

Closed
tophf opened this issue Sep 26, 2024 · 7 comments
Labels
neutral: safari Not opposed or supportive from Safari next manifest version Consider for the next manifest version opposed: chrome Opposed by Chrome opposed: firefox Opposed by Firefox

Comments

@tophf
Copy link

tophf commented Sep 26, 2024

Any context, be it a document or a worker, always has an intrinsic URL exposed in its location object, so adding the word document is redundant, inconsequential, and wrong as we can't tell one service worker from another (in Chrome extensions can register multiple service workers for nested paths under the root).

  • url and origin should be used instead and workers should be supported as they also have a URL (location.href) and origin (location.origin).
  • documentUrl and documentOrigin should be kept as a deprecated alias, its value should remain undefined in a non-document context for compatibility with the existing code.

No changes for documentId which is a synthetic separate concept used in many places in other APIs such as tabs, webRequest, webNavigation.

@github-actions github-actions bot added needs-triage: chrome Chrome needs to assess this issue for the first time needs-triage: firefox Firefox needs to assess this issue for the first time needs-triage: safari Safari needs to assess this issue for the first time labels Sep 26, 2024
@tophf tophf changed the title documentUrl and documentOrigin should be just url and origin in runtime.getContexts documentUrl and documentOrigin should be just url and origin in runtime.getContexts and be defined for the worker context Sep 26, 2024
@xeenon xeenon added neutral: safari Not opposed or supportive from Safari needs-triage: chrome Chrome needs to assess this issue for the first time next manifest version Consider for the next manifest version and removed needs-triage: chrome Chrome needs to assess this issue for the first time needs-triage: safari Safari needs to assess this issue for the first time labels Sep 26, 2024
@xeenon
Copy link
Collaborator

xeenon commented Sep 26, 2024

We discussed this today at TPAC. Originally we considered the role of content scripts in the design of getContexts. In that scenario, url and origin could become more ambiguous. While we should keep this in mind for future manifest versions as a possible time to rename them, for now, we’ve decided not to make any changes.

@xeenon xeenon closed this as completed Sep 26, 2024
@xeenon xeenon added opposed: chrome Opposed by Chrome opposed: firefox Opposed by Firefox and removed needs-triage: chrome Chrome needs to assess this issue for the first time needs-triage: firefox Firefox needs to assess this issue for the first time labels Sep 26, 2024
@tophf
Copy link
Author

tophf commented Sep 26, 2024

Looks like you've ignored this problem:

we can't tell one service worker from another (in Chrome extensions can register multiple service workers for nested paths under the root)

I guess I should open a new issue about that?

@Rob--W
Copy link
Member

Rob--W commented Sep 26, 2024

Looks like you've ignored this problem:

we can't tell one service worker from another (in Chrome extensions can register multiple service workers for nested paths under the root)

I guess I should open a new issue about that?

What is the use case for that?

In extensions, only one extension service worker is supported. I know that the web supports multiple service registrations via the scope option of navigator.serviceWorker.register(), but that is not an intentionally supported API in extensions. In fact, when a Chrome extension does that, the generated service worker is a regular service worker without access to extension APIs. If you really want to interact with this service worker, you can use the standard web platform APIs for that, by calling navigator.serviceWorker.getRegistrations().

Note: Firefox does not allow extensions to register its own service workers. The Service Worker specification specifies that the serviceWorker.register() method should reject registrations when the input URL is not http or https: https://www.w3.org/TR/service-workers/#start-register-algorithm . I cannot find evidence of Chrome's support for this to be intentional.

Since we're in the realm of the regular web platform, you could also compare this with dedicated workers (new Worker(url)) and shared workers (new SharedWorker(url)). These workers do not have extension APIs, and do not appear in runtime.getContexts() either.

@tophf
Copy link
Author

tophf commented Sep 26, 2024

The use case is proper support of the existing capabilities as extensions support multiple service workers in Chrome. Such a worker doesn't have access to chrome extensions API, but that doesn't mean it's not a context of this extension.

@tophf
Copy link
Author

tophf commented Sep 26, 2024

I cannot find evidence of Chrome's support for this to be intentional.

It is intentional, rdevlin explicitly stated it several times.

@tophf
Copy link
Author

tophf commented Sep 26, 2024

dedicated [...] and shared workers [...] do not have extension APIs, and do not appear in runtime.getContexts() either.

Looks like a bug in the design of the API, because these workers are also meaningful contexts of the extension.

@tophf
Copy link
Author

tophf commented Sep 26, 2024

OTOH, my mistake is that I use a common technical definition for "context" whereas here it means an API-reachable context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
neutral: safari Not opposed or supportive from Safari next manifest version Consider for the next manifest version opposed: chrome Opposed by Chrome opposed: firefox Opposed by Firefox
Projects
None yet
Development

No branches or pull requests

3 participants