w3c / webextensions

Charter and administrivia for the WebExtensions Community Group (WECG)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Proposal: filter by documentId in tabs.query()

bershanskiy opened this issue · comments

Background

tabs.query() is not currently aware of tabs being navigated and moved around, so there is very little information to refer to the same document. Luckily, most use cases require querying info about the active tab, which happens to be the default behavior for this API. Unfortunately, some use cases require querying info about non-active tabs. Currently, the best way to match a document belonging to an inactive tab is to refer to its coincidental mutable non-unique attributes like its location (window id and an index on tab strip), its URL or title, which are problematic from privacy perspective.

Problem

tabs.query() and other APIs under tabs are async and inherently racy. For example, the background may get a message from content script, call tabs.query() to get more information about the sender and receive a response containing information about a different document (because the tab may navigate between the message being sent and the tabs.query() being called).

Proposal

Extend tabs.query(queryInfo: QueryInfo, callback)argument QueryInfo (Chrome docs, MDN) to take optional documentId argument.

If developer specifies documentId, browser returns only the tab which currently hosts the corresponding document. If the provided documentId has invalid format, then an error is returned. If provided documentId is semantically valid, but browser is not aware of a document with this id, then nothing is matched so an empty array is returned (since this may be an id from an older browser session, tab open on a different device and synced via storage.sync or something like this). If the provided documentId corresponds to a sub-frame or a top-level frame currently sitting in BFCache, then nothing is returned to match existing behavior.

Relevant links