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

Expose openOrClosedShadowRoot for userscripts #612

Open
tophf opened this issue May 14, 2024 · 0 comments
Open

Expose openOrClosedShadowRoot for userscripts #612

tophf opened this issue May 14, 2024 · 0 comments
Labels
needs-triage: chrome Chrome needs to assess this issue for the first time needs-triage: firefox Firefox needs to assess this issue for the first time neutral: safari Not opposed or supportive from Safari topic: user scripts

Comments

@tophf
Copy link

tophf commented May 14, 2024

Currently userscripts can't use elem.openOrClosedShadowRoot (Firefox) and chrome.dom.openOrClosedShadowRoot (Chrome) because it's exposed only in the isolated world.

There's a number of reasons it should be exposed to userscript worlds:

  • Userscripts need it to augment web pages e.g. to apply custom CSS to sites built on shadow DOM, example.

  • Userscripts are already privileged compared to the page scripts as they are installed by the user to act on the user's behalf.

  • If necessary, the owner extension is still able to control the availability of chrome.dom (Chrome) or Element.prototype.openOrClosedShadowRoot (Firefox) by overriding it before running the userscript.

    Alternatively, chrome.userScripts.configureWorld may be extended with dom: true.

  • The internal implementation is trivial, so exposing it even by default is not costly and it won't set a bad example because DOM-related differences between worlds are intentionally avoided i.e. it's possible this will be the only such difference for a very long time.

  • In Chrome userscripts would benefit from other possible additions to chrome.dom namespace such as the ability to run a function in the main JS world of the page without creating a script element to avoid detection via MutationObserver and being able to get the [serializable] result of the function directly without the inherently unsafe usage of dispatchEvent in a potentially poisoned environment. FWIW, Firefox already has a different solution: wrappedJSObject+cloneInto+exportFunction.

  • There's no safe/easy workaround:

    • No secure cross-world communication yet.
    • Even with secure cross-world communication, it is wasteful to spin up an entire JS world just to access a trivial feature, especially since there's no way to unload it.
    • The cross-world communication is unlikely to support exchanging DOM elements directly as they're not compatible with the structured cloning algorithm, so the extension would need to exchange a random event id first, set up a listener, send MouseEvent with relatedTarget for the element. Really arcane stuff.

The only con I remember seeing in WECG is that the exposed API for userscripts should be as simple as possible and intentionally limited, but this feature isn't something complicated or privileged, it's rather a trivial DOM feature necessary for userscripts that frequently augment web pages. If anything should be removed, it's chrome.csi and chrome.loadTimes, which seem useless in a userscript.

@github-actions github-actions bot added needs-triage: chrome Chrome needs to assess this issue for the first time needs-triage: firefox Firefox needs to assess this issue for the first time needs-triage: safari Safari needs to assess this issue for the first time labels May 14, 2024
@xeenon xeenon added neutral: safari Not opposed or supportive from Safari and removed needs-triage: safari Safari needs to assess this issue for the first time labels May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-triage: chrome Chrome needs to assess this issue for the first time needs-triage: firefox Firefox needs to assess this issue for the first time neutral: safari Not opposed or supportive from Safari topic: user scripts
Projects
None yet
Development

No branches or pull requests

3 participants