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

Add developer tools contexts in runtime.getContexts() proposal #675

Merged
merged 4 commits into from
Sep 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions proposals/runtime_get_contexts.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ extension.ContextType = {
OFFSCREEN_DOCUMENT: 'OFFSCREEN_DOCUMENT',
// A side panel or sidebar context.
SIDE_PANEL: 'SIDE_PANEL',
// A developer tools context.
DEVELOPER_TOOLS: 'DEVELOPER_TOOLS',
};
```

Expand Down Expand Up @@ -236,6 +238,25 @@ This is an artifact of existing APIs and precedence. Since many existing APIs
use the constant integer values, we want to be consistent with those. However,
for newly-introduced fields, we use the more intuitive `undefined` state.


### Developer Tools Contexts

Extensions can use the
[Dev Tools API](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/devtools)
to extend the browser's developer tools. When doing so, these extensions can run
different types of contexts (page, panel, sidebar). `runtime.getContexts()`
returns these contexts with the `DEVELOPER_TOOLS` context type.

- These contexts have `tabId` and `frameId` as -1 as these contexts are not
hosted inside a tab.
- If developer tools are docked to a tab, the `windowId` will be the ID of the
window containing the tab.
- If developer tools are undocked, the `windowId` will the ID of the developer
sohailrajdev97 marked this conversation as resolved.
Show resolved Hide resolved
tools window.

Other fields (`contextId`, `documentId`, `documentUrl`, `documentOrigin`,
`incognito`) are populated as expected. No special handling is done for them.

## Future Work

### Messaging APIs Support `ContextId`s as Target
Expand Down Expand Up @@ -278,17 +299,6 @@ like to add these contexts in the future.
With the content script additions, we may add new fields to `ExtensionContext`,
such as `scriptUrl` (to indicate the content script's source).

### Dev Tools Contexts

Extensions can use the
[Dev Tools API](https://developer.chrome.com/docs/extensions/mv3/devtools/] to
extend the browser's developer tools. When doing so, these extensions can have
a panel (an extension view) within the developer tools console. These views
are a little different than others, though -- in Chromium, they commit to a
different origin (one with a devtools:-scheme). These are also not currently
returned from `chrome.extension.getViews()`. In the future, we will expand
`runtime.getContexts()` with devtools context types to accommodate these.

## Footnotes

<sup>1</sup>: Non-main threads in a
Expand Down