-
Notifications
You must be signed in to change notification settings - Fork 56
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
request: allow to retrieve a tabId
and documentId
from the content script
#469
Comments
Once browsers support both |
|
Ideally this info must be available synchronously because async call may take several seconds to complete on a slower device if the site is busy (e.g. compiling/running a big js or building its virtual DOM or whatever else). AFAIK documentId in Chrome is stored in the document's renderer, so it can be exposed as a field in |
I'm supportive of the capability requests, i.e. the ability to retrieve the current tabId/documentId, asynchronously. I'd like this to be part of the "Contexts" feature (getContexts) rather than separate synchronous methods. webextensions/proposals/runtime_get_contexts.md Lines 264 to 279 in 10a84ee
|
That makes sense but then one has to match the objects returned with each |
What is the use case for this?
In my comment I referenced the part of the proposal that calls out the potential to introduce getCurrentContext, AND making the concept available to content scripts. |
Sorry, on mobile the link opened the page without deep-linking, I didn't see the specific section.
One of the usages was to enable communication between frames, e.g.:
Other than
This new API would allow: // From a `chrome-extension://` iframe to a `http://` top frame
const {tabId, iframeId} = await browser.runtime.getTarget(window.top)
chrome.tabs.sendMessage(tabId, message, {frameId}) and: // From a `chrome-extension://` top frame to a `http://` iframe
const {tabId, iframeId} = await browser.runtime.getTarget($('iframe'))
chrome.tabs.sendMessage(tabId, message, {frameId}) or via I suppose #77 would be a more direct solution to this, but it would not be enough "iframe to iframe" communication, because they don't have access to each other's |
Since |
This is also important that this is synchronous as I can use this ID to do I'm looking for a way to securely do |
@wfjsw, it's not possible to achieve a real document_start with executeScript because it injects asynchronously, messaging is asynchronous as well. A real document_start can be achieved by using a declared or registered content script (chrome.scripting.registerContentScripts).
It will be implemented as a separate API to communicate between the worlds securely. Note that your code in the MAIN world may run in an already poisoned JS environment (https://crbug.com/40202434 applies to all browsers). Currently the only secure way is to create a temporary iframe to extract dispatchEvent/addEventListener/etc. to establish a secure channel, it's very complicated and you can see how it's done in Violentmonkey. In ManifestV3 it requires using the userScripts API permission, which is problematic because it misrepresents the function of the extensions, also users in Chrome must enable "developer mode" in chrome://extensions. |
This was already requested in the previous thread, but it was probably too late by then, so I'll extract it into its own request
frameID
from an<iframe>
element #12 (comment)Could this be expanded to include the tab ID as well?
It's a pretty common request to know "this" tab ID: https://stackoverflow.com/q/6202953/288906 (123 upvotes)
Currently this requires a ping to the runtime, which may or may not be "quick".
Including the recently-added
documentId
would be great. There's a lot of potential here so limiting it to just aframeId
seems overly specific; returning an object makes it more flexible for future usage without having to create specific APIs.The text was updated successfully, but these errors were encountered: