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: Re-evaluate userScript and userStyle API #489

Open
erosman opened this issue Nov 14, 2023 · 3 comments
Open

Proposal: Re-evaluate userScript and userStyle API #489

erosman opened this issue Nov 14, 2023 · 3 comments
Labels
discussion Needs further discussion enhancement Enhancement or change to an existing feature proposal Proposal for a change or new feature topic: user scripts

Comments

@erosman
Copy link

erosman commented Nov 14, 2023

Proposal: Re-evaluate userScript and userStyle API

scripting in manifest v3 removed the code property which was available in contentScripts (and Firefox MV2 userScripts) API.

Requirements

UserScript and UserStyle managers require:

  • Both js and css properties
  • code property in above in order to function
  • An array of objects to include more than one (file and/or code) at a time
  • Access to "MAIN", "ISOLATED" & "USER_SCRIPT" execution worlds
  • executeScript() & insertCSS() APIs

Having a separate API to inject js and css results in having to make 2 almost identical registrations which would be less efficient for both the browser and the manager.

footnote: scripting.register() namespace could be more inclusive than the literal scripting.registerContentScripts().

Proposal

In order to facilitate both the userScript and the userStyle managers, a combined API would be more efficient.

In fact, the new API would need to be a duplicate of the scripting API with some minor changes, e.g. a flag/permission to enable code inclusion.

See also

#279, #284, #477

@dotproto dotproto added enhancement Enhancement or change to an existing feature discussion Needs further discussion proposal Proposal for a change or new feature topic: user scripts and removed needs-triage labels Nov 23, 2023
@Rob--W
Copy link
Member

Rob--W commented Nov 23, 2023

As written in the meeting notes of today's meeting, it was Chrome's design request to have intentionally separate namespaces for the userScripts functionality. Merging the namespaces is therefore unlikely.

There was some further discussion on the support of "css". While not opposed, we'd like to see actual demand for the feature before considering its support.

P.S. The "userScripts" MDN link in the issue links to Firefox's MV2-only userScripts API. That is separate from the userScripts API that has been designed in #279 and whose proposal was posted at https://github.com/w3c/webextensions/blob/main/proposals/user-scripts-api.md

@erosman
Copy link
Author

erosman commented Nov 23, 2023

Namespace

As written in the meeting notes of today's meeting, it was Chrome's design request to have intentionally separate namespaces for the userScripts functionality. Merging the namespaces is therefore unlikely.

That was not part of the proposal.
The proposal mentioned the API would be an almost duplicate of the scripting API with some minor changes/additions.

CSS

There was some further discussion on the support of "css". While not opposed, we'd like to see actual demand for the feature before considering its support.

What about user-style managers?

Since scripting in manifest v3 removed the code property, and user-style managers require that property, unless the intention is to create another API (e.g. userStyles API), then a combined API would be the obvious choice.

Furthermore, scripting API has both JS & CSS in order to handle various situations and user-script & user-style managers require the same (for the same reasons).

The issue was also brought up in the early days of the Firefox MV2 userScripts API development in Bug 1437098.

Array of Objects

An array of objects to include more than one (file and/or code) at a time

Above (important) issue seem to have been missed.

// Must specify exactly one of: `file` or `code`.
dictionary ScriptSource {
  string? code;
  string? file;
}

ScriptSource

code
string optional
A string containing the JavaScript code to inject. Exactly one of file or code must be specified.

file
string optional
The path of the JavaScript file to inject relative to the extension's root directory. Exactly one of file or code must be specified.

Statistics

user-script user-style Chrome Users Firefox Users Edge Users Opera Users
Tampermonkey11m670k10m3.5m
Violentmonkey900k79k600k
Greasemonkey203k
FireMonkey1.5k
Stylish2m41k10k
Stylus700k87k
xStyle60k290

P.S. The "userScripts" MDN link in the issue links to Firefox's MV2-only userScripts API.

Post updated for clarification.

@mon-jai
Copy link

mon-jai commented Nov 27, 2023

@erosman As a workaround, maybe we can create custom style tags with the userscript API?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Needs further discussion enhancement Enhancement or change to an existing feature proposal Proposal for a change or new feature topic: user scripts
Projects
None yet
Development

No branches or pull requests

4 participants