Implement documentId in extension APIs
Categories
(WebExtensions :: General, enhancement, P3)
Tracking
(firefox153 fixed)
| Tracking | Status | |
|---|---|---|
| firefox153 | --- | fixed |
People
(Reporter: robwu, Assigned: robwu)
References
(Blocks 2 open bugs)
Details
(Keywords: dev-doc-complete, Whiteboard: [wecg][addons-jira])
Attachments
(7 external files)
The extension API currently has tabId + frameId to identify specific frames. Several APIs (e.g. scripting.executeScript) support a way to run code in that specific frame. The issue with the current API is that the document may have navigated between notifying the extension and the call to scripting.executeScript. We therefore need a way for extensions to target specific documents, independent of the frame.
Chrome introduced the documentId concept to identify specific document instances, coupled with the documentLifeCycle and frameType properties. This was announced at https://developer.chrome.com/blog/extension-instantnav/
Note: in the WECG there are several requests/proposals/enhancements that rely on documentId as a primitive: https://github.com/w3c/webextensions/issues?q=is%3Aissue+documentId
Updated•2 years ago
|
| Assignee | ||
Comment 1•1 year ago
|
||
There is still no official "spec" for documentId, but we discussed runtime.getDocumentId (to complement runtime.getFrameId) at https://github.com/w3c/webextensions/issues/800.
| Assignee | ||
Comment 2•1 year ago
•
|
||
New WECG ticket filed about standardizing documentId: https://github.com/w3c/webextensions/issues/890
I left a comment describing all APIs that currently support documentId in Chrome, at https://github.com/w3c/webextensions/issues/890#issuecomment-3446258636
| Assignee | ||
Comment 3•6 months ago
|
||
Also proposal to add documentId to tabs.query:
| Assignee | ||
Updated•5 months ago
|
| Assignee | ||
Comment 4•5 months ago
|
||
I'd consider tabs.query to be out of scope for this bug. The PR proposal is still open and there are no implementations in Safari and Chrome. Moreover I question the utility in its design when there is no tabs.Tab.documentId counterpart. I expressed these thoughts here: https://github.com/w3c/webextensions/issues/553#issuecomment-4416596765
| Assignee | ||
Comment 5•4 months ago
|
||
Introduces ExtensionDocumentId.sys.mjs as the module responsible for
mapping innerWindowId to documentId UUIDs. This module will be used by
any extension API needing a documentId, starting with
runtime.getDocumentId in this patch.
| Assignee | ||
Comment 6•4 months ago
|
||
| Assignee | ||
Comment 7•4 months ago
|
||
| Assignee | ||
Comment 8•4 months ago
|
||
| Assignee | ||
Comment 9•4 months ago
|
||
| Assignee | ||
Comment 10•4 months ago
|
||
| Assignee | ||
Comment 11•4 months ago
|
||
Updated•4 months ago
|
Comment 12•4 months ago
|
||
| Assignee | ||
Comment 13•4 months ago
•
|
||
Given the many APIs touched here, here is a full list of what is (and in some cases not implemented).
Where parentDocumentId is mentioned, it is only set if a parent document exists, otherwise the field is omitted.
I also includes references to relevant WECG issues / proposals for future reference.
runtimenamespace:runtime.getDocumentId()runtime.getContexts()- now includesdocumentIdin the returned contexts, making the already-existingdocumentIdsfilter more useful.runtime.MessageSenderincludesdocumentId- visible where applicable inruntime.onConnect,runtime.onMessage,runtime.onMessageExternal,runtime.onConnectExternal,runtime.onUserScriptMessage,runtime.onUserScriptConnect.
scriptingnamespace:scripting.executeScript,scripting.insertCSSandscripting.removeCSSnow supporttarget.documentId(InjectionTarget.documentId)scripting.executeScript- includesdocumentIdin all results (InjectionResulttype)
userScriptsnamespaces:userScripts.execute- recognizestarget.documentIdand also includesdocumentIdin the result.- Note that
userScripts.executewas introduced in the same Firefox version (bug 1930776), so there is no version ofuserScripts.executethat lacksdocumentIdsupport. - https://github.com/w3c/webextensions/blob/main/proposals/user-scripts-execute-api.md
- Note that
tabsnamespace:tabs.connect-options.documentIdsupportedtabs.sendMessage-options.documentIdsupported- (
tabs.executeScript,insertCSSandremoveCSSdid NOT getdocumentIdsupport - usescriptingAPI instead)
webNavigationnamespace:webNavigation.getAllFrames()-documentIdandparentDocumentIdincludes in returned objectswebNavigation.getFrame()-details.documentIdoption introduced,details.frameIdis now optional. Returned object includesdocumentIdoption.webNavigation.onBeforeNavigate-parentDocumentIdonly (nodocumentIdbecause the target document does not exist yet)webNavigation.onCommitted-documentIdandparentDocumentIdwebNavigation.onDOMContentLoaded-documentIdandparentDocumentIdwebNavigation.onCompleted-documentIdandparentDocumentIdwebNavigation.onErrorOccurred-documentIdandparentDocumentIdwebNavigation.onCreatedNavigationTarget- (no changes, target document does not exist; there was already ansourceFrameIdso an equivalent could have beensourceDocumentId, but Chrome does not have this either, so I did not bother adding it)webNavigation.onReferenceFragmentUpdated-documentId,parentDocumentIdwebNavigation.onTabReplaced- (no changes, does not relate to documents, we never fire it either)webNavigation.onHistoryStateUpdated-documentIdandparentDocumentId
webRequestnamespace:- all
webRequestevents receivedocumentIdandparentDocumentIdwhen applicable. Document navigations do not havedocumentIdset since their target document is unknown.
- all
proxynamespace:proxy.onRequestevent receivesdocumentIdandparentDocumentIdwhen applicable.
I considered the following but did not proceed with their implementation. They are not implemented by any other browser either:
tabs.query-documentId- my rationale for not implementing is at https://github.com/w3c/webextensions/issues/553#issuecomment-4416596765tabs.Tab.documentId- https://github.com/w3c/webextensions/issues/496browser.tabs.sendMessageacceptingdocumentIdwithouttabId- open questions at https://github.com/w3c/webextensions/issues/971#issuecomment-4692317832devtools.inspectedWindow.eval- currently targets byframeURLwhich is strange. There are proposals forframeIdanddocumentId, neither of which have been implemented by any browser (https://github.com/w3c/webextensions/issues/389 , https://github.com/w3c/webextensions/issues/393)scripting.executeScriptwithouttabId- deferred to bug 1891480.
EDIT: runtime.sendMesage and runtime.connect were erroneously listed as accepting documentId; that is not the case, but there is an open proposal for the option at https://github.com/w3c/webextensions/issues/294
Comment 14•4 months ago
|
||
| bugherder | ||
https://hg.mozilla.org/mozilla-central/rev/93dd399a5666
https://hg.mozilla.org/mozilla-central/rev/1c769f3a861e
https://hg.mozilla.org/mozilla-central/rev/50d23e9ba2ac
https://hg.mozilla.org/mozilla-central/rev/7f3931e9e079
https://hg.mozilla.org/mozilla-central/rev/72c7d7189007
https://hg.mozilla.org/mozilla-central/rev/afbfcbb266b0
https://hg.mozilla.org/mozilla-central/rev/5f5140fe7fbd
Comment 15•4 months ago
|
||
Documentation updates in:
- (BCD) Bug 1891478 Implement documentId in extension APIs #29853
- (content) Bug 1891478 Implementation of documentId in more extension APIs #44491
| Assignee | ||
Updated•4 months ago
|
Description
•