PSA: runtime.getContexts() is now available for testing

294 views
Skip to first unread message

Oliver Dunk

unread,
May 11, 2023, 3:10:50 PM5/11/23
to Chromium Extensions
Hi all,

The runtime.getContexts() API is now available in dev channels, including Chrome Canary: https://developer.chrome.com/docs/extensions/reference/runtime/#method-getContexts

You can see the original proposal which includes more information about the API here: https://github.com/w3c/webextensions/blob/main/proposals/runtime_get_contexts.md

What’s the goal of the API?

The goal of this API is to solve some of the use cases previously solved by the extension.getViews() API in MV2, although without exposing the HTMLWindow object in a service worker (which cannot use windows). We expect one major use case to be determining if pages like the popup or an offscreen document are open.

What should I try?

We’re currently looking for any feedback on the behavior of the API. As this API is limited to specific channels, we currently have the most flexibility to make changes before we bring this to stable.

When will this API be released?

We do not have a definite release date, but are hoping to ship within the next few Chrome releases depending on the feedback we receive.

What’s still to come?

In the future, we plan to expose content script contexts in the API. Additionally, we are looking into updating our messaging APIs to support the context IDs returned.

What design decisions were made?

We are explicitly not looking to expose the Window and allow direct access to other contexts from the service worker since HTMLWindow objects are unsupported in worker contexts. Additionally, we plan to keep this API asynchronous as building a list of contexts requires messaging between processes in a way which is inherently asynchronous in nature.

Thanks,
Oliver, on behalf of Chrome Extensions DevRel

Uladzimir Yankovich

unread,
May 12, 2023, 6:16:27 AM5/12/23
to Chromium Extensions, Oliver Dunk
Oliver, cool!

1) When do you plan to deliver this API to production?
2) It seems to me that in the first version of this API, we should get ContextType: SidePanel. Especially since side panels are already returned with extension.getViews().

Oliver Dunk

unread,
May 12, 2023, 6:46:59 AM5/12/23
to Uladzimir Yankovich, Chromium Extensions
Hi Uladzimir,

When do you plan to deliver this API to production?

We think it's in a pretty good place, so if there isn't much feedback, we may be able to ship it fairly soon. However, we're intentionally not deciding on a Chrome version ahead of time - we're not in a rush to get this out and if there is significant feedback we want to leave time for potential changes. That said, I would be surprised if it took more than a few Chrome versions for us to release the first iteration of this.

It seems to me that in the first version of this API, we should get ContextType: SidePanel. Especially since side panels are already returned with extension.getViews().

Great callout! This was part of our proposal, so it's definitely something we want to support. I suspect it may be missing because this API was being developed in parallel with the Side Panel and we didn't get time to join the two together. I'll pass that along.
Oliver Dunk | DevRel, Chrome Extensions | https://developer.chrome.com/ | London, GB

Reply all
Reply to author
Forward
0 new messages