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

GM.addStyle not injecting into sub-iframes #755

Open
ACTCD opened this issue Nov 16, 2024 · 1 comment
Open

GM.addStyle not injecting into sub-iframes #755

ACTCD opened this issue Nov 16, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@ACTCD
Copy link
Collaborator

ACTCD commented Nov 16, 2024

It seems that in the previous resolution of related issues, only the .css file injection path was changed, but not the GM.addStyle API, which has been using tabs.insertCSS() until now.

But since allFrames, frameId is not supported by Safari, in fact we just inject it into the top frame instead of the corresponding sub-frame.

Methods using the <style> element may be blocked by CSP, and in fact there may still be no way to inject into sub-frame in this case.

The best solution at the moment is probably:

  • If it is top frame, use the tabs.insertCSS() to inject

  • If it is sub frame, use the <style> element to inject it

    • If blocked by CSP, fails and logs in console

The .css file and GM.addStyle API should share the same injection path, but the .css feature will be deprecated (#711) in favor of GM.addStyle in the future.

@ACTCD ACTCD changed the title GM.addStyle not injecting into iframes GM.addStyle not injecting into sub-iframes Nov 16, 2024
@ACTCD ACTCD added the bug Something isn't working label Nov 16, 2024
@ACTCD
Copy link
Collaborator Author

ACTCD commented Nov 18, 2024

Some updates

According to my testing, cssOrigin, allFrames actually work in the latest Safari (but not sure from which version it is supported, and apparently Apple hasn't updated their documentation).

frameId is still not supported due to: https://bugs.webkit.org/show_bug.cgi?id=262491


Where allFrames is supported, we may have a workaround to support injecting sub-frames.

That is, add a random class-name to the root node of sub-frame and append it to the user-style.
In this way, even if we inject the user-style into allFrames, only the corresponding sub-frame will take effect.

Adding a class-name to an element is not subject to CSP rules, so in principle this should be able to inject a specific sub-frame without being affected by the site's CSP rules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant