-
Notifications
You must be signed in to change notification settings - Fork 70
Description
The Chrome Extensions team is looking to align on the sender.url
property when messages originate from service workers.
Current Behavior
In the current Chrome Extensions environment, when a message is sent from a service worker, the sender.url
property in the receiving end's sender
object is undefined
. While this behavior could be technically correct since service workers don't execute within the context of a page or frame, it creates limitations for developers who want to differentiate between messages originating from different parts of an extension or debug complex extension architectures.
Currently, Firefox uses script URL for the sender.url
when a message is sent from a service worker.
Proposed Solution:
Script URL: Set sender.url to the specific URL of the service worker script (e.g., chrome-extension://<extension_id>/background.js
). This offers a more granular identification which could be beneficial for debugging and also aligns with the current behavior in Firefox, but may be unnecessarily detailed for simple use cases.
Alternatives Considered:
- Extension Origin URL: Set sender.url to the extension's origin URL (e.g.,
chrome-extension://<extension_id>/
). This provides a simple identifier, but is less granular than having a script URL. - Introduce
documentUrl
andscriptUrl
properties: We could add new documentUrl and scriptUrl properties to the MessageSender which would offer developers more precise attribution options without overloading the url property.
Questions for Discussion
- Which approach would be more beneficial for extension developers?
- What are the primary use cases that would drive this preference?
- Are there other solutions we should consider?
- Are there any security implications we should be aware of? Are there potential security benefits or risks of each approach?