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

Proposal: scripting.executeScript without specifying tabId #91

Open
carlosjeurissen opened this issue Sep 30, 2021 · 5 comments
Open

Proposal: scripting.executeScript without specifying tabId #91

carlosjeurissen opened this issue Sep 30, 2021 · 5 comments
Labels
proposal Proposal for a change or new feature supportive: chrome Supportive from Chrome supportive: firefox Supportive from Firefox supportive: safari Supportive from Safari

Comments

@carlosjeurissen
Copy link
Contributor

carlosjeurissen commented Sep 30, 2021

Background

  1. currently scripting.executeScript / tabs.executeScript require one to define the tabId of the main_frame or sub_frame to inject the content script in.
  2. extension popups have their tabId set to -1 (no tabId). This makes sense as they are no tabs, but puts limitations like the inability to use executeScript for iframes within extension popups.

Proposal

Allow to only specify a frameId as target when running scripting.executeScript / tabs.executeScript. This basically means either tabId or frameId will be required when running executeScript or insertCSS.

Reasoning

This will allow dynamic contentscript to be injected into frames within non-tab environments like extension popups, and to allow injection of script when it's faster / more convenient to not specify a tabId.

Requirement

All frameIds should be unique for this to be implemented. See:

@carlosjeurissen carlosjeurissen changed the title scripting.executeScript with just frameId as target Proposal: scripting.executeScript with just frameId as target Oct 1, 2021
@carlosjeurissen carlosjeurissen changed the title Proposal: scripting.executeScript with just frameId as target Proposal: scripting.executeScript without specifying tabId Nov 12, 2021
@carlosjeurissen
Copy link
Contributor Author

As discussed during the 2021-11-11 meeting, this can be tricky as of right now frameId is not unique in all contexts. A potential alternative proposal was to use a window object.

You can think about a syntax like this:

browserOrChrome.scripting.executeScript(
    {
      target: {window: someFrame.contentWindow},
      files: ['script.js'],
    },
    () => { ... });

@xeenon xeenon added the proposal Proposal for a change or new feature label Aug 31, 2022
@carlosjeurissen
Copy link
Contributor Author

carlosjeurissen commented Mar 20, 2024

As with #12 (comment)

With the introduction of documentId this seems to become possible.

@erosman
Copy link

erosman commented Mar 20, 2024

@rdcronin
Copy link
Contributor

We discussed this at the WECG meet-up.

We're agreed that this is useful functionality. There's one tricky bit, which is that currently, the main frame is always 0 (whereas subframes are globally-unique). While we've talked about changing that, it's a very breaking change and not something we're actively looking at.

We tentatively agred that we're supportive of:

  • Allowing non-zero frameId without a tabId (new)
  • Allowing any documentId without a tabId (new)
  • Allowing any frameId with a tabId (as today)

This would also allow extensions to inject in non-tab contexts, as @carlosjeurissen mentioned in the issue report.

We also pointed out that this does introduce a requirement that non-main-frame IDs are globally unique. This is already an attribute in most Chromium-based browsers, Firefox, and Safari, but is now a requirement for this functionality.

@rdcronin rdcronin added the supportive: chrome Supportive from Chrome label Mar 20, 2024
@Rob--W Rob--W added the supportive: firefox Supportive from Firefox label Apr 15, 2024
@Rob--W
Copy link
Member

Rob--W commented Apr 15, 2024

Filed https://bugzilla.mozilla.org/show_bug.cgi?id=1891480 to track this at the Firefox side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal Proposal for a change or new feature supportive: chrome Supportive from Chrome supportive: firefox Supportive from Firefox supportive: safari Supportive from Safari
Projects
None yet
Development

No branches or pull requests

5 participants