w3c / webextensions

Charter and administrivia for the WebExtensions Community Group (WECG)
Other
603 stars 56 forks source link

Exposing developer tools contexts in runtime.getContexts() API #670

Open sohailrajdev97 opened 3 months ago

sohailrajdev97 commented 3 months ago

Exposing developer tools contexts in runtime.getContexts() API

WECG proposal for runtime.getContexts()

https://github.com/w3c/webextensions/blob/main/proposals/runtime_get_contexts.md

Background

Extensions can customize the browser developer tools. When an extension customises the developer tools, it can run code in the following contexts:

  1. Developer tools page: This is a background page which is spawned as soon as developer tools is opened. Its lifetime is tied to the developer tools.
  2. Developer tools panel: This is a panel which the extension can add to the developer tools by calling devtools.panels.create() from the developer tools page (1).
  3. Developer tools sidebar pane: This is a side pane which the extension can add to a particular panel (2) by calling devtools.panels.<panel>.createSidebarPane() from the developer tools page (1).
drawing

image

image

Proposal

All the above contexts host extension content (HTML and JavaScript). These should be available in the results of runtime.getContexts() API. runtime.getContexts() asynchronously returns a list of ExtensionContext objects. Following is a description of how ExtensionContext’s fields would be populated for developer tools contexts.

Other fields (contextId, documentId, frameId, documentUrl, documentOrigin, incognito) should be populated as expected. No special handling is needed for them.

Current support

  1. Firefox 129 does not return these contexts via the API call.
  2. Chrome 129 returns these contexts with a “TAB” context type, which is incorrect.

Compatibility issues

Chrome already returns developer tools contexts via the API; some extensions might be using that information. Currently the contexts are returned with the “TAB” context type and that is a bug.

Creating this issue to get group's feedback. We will create a follow-up PR to modify the runtime.getContexts() proposal after we have consensus within the group.

oliverdunk commented 3 months ago

Thanks again for filing this @sohailrajdev97. On the Chrome side, we are supportive - we would prefer only a single new ContextType variant to avoid adding several. We should also work together to communicate the change to developers before it happens since it is a behavior change, even if adoption is low.

Looking forward to seeing this progress :)

Rob--W commented 2 months ago

I filed this bug on the Firefox side to implement DEVELOPER_TOOLS in runtime.getContexts(): https://bugzilla.mozilla.org/show_bug.cgi?id=1918719