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
Add a GM.addStyle API, for styling CSP-restrictive pages #2724
Comments
|
Thanks ! However that makes the current lack even more incomprehensible... |
I think this will be hit in FF 58. |
I filed a bug against Stylish since that's where I ran into the issue. Still, thought it might be worth considering here since GM's current APIs mostly expose privileged WebExt APIs that circumvent some content script restriction or other, and insertCSS is another one of those. |
I don't know exactly what "This should work if you bundle the CSS in your extension..." means, in the linked bug. Dynamic node insertion might not work. I'll reopen to consider CSP-safe functionality. (But at a really low priority...) |
In principle this could also be implemented without waiting for FF by passing up a message to the background script and running tabs.insertCSS. But jumping through those hoops won't be necessary once that bug is implemented. |
In case there's no plan to add a Thanks! |
Regarding the polyfill: ever since I heard that GM_addStyle was on the chopping block, I've actually only used 3 commands to replace it. Rather than testing for HEAD, I just add the STYLE directly to the documentElement, which is always present, even at document-start.
Here's the function version that I use more rarely, which clocks in at 5 lines:
I've tested this in GM 3 and 4 on Firefox, and TamperMonkey on Chrome, without issue, despite not being standard. And I prefer nonstandard to having it fail if the HEAD has not yet loaded (which happens surprisingly often. I've had complaints.) I also note that UserStyles,org uses my method as a fallback in its automatically generated userscripts. |
In FF57 and GM4, documentElement is not always available at document-start, at least on my machine. |
Since GM 4 (for now) has document-start happen even later than before, I'm
not sure how that's possible. But if the documentElement is not present,
then neither will be the HEAD element, since the documentElement is the
HTML element. which is what contains the HEAD element. So my method is not
any worse.
I admit I've not tested the latest dev on Fx 59, which uses a different
method to get document-start, but I hope the documentElement is present. If
not, then all sorts of scripts will break. You can't do anything to the
document before there is a documentElement. I don't even think you can set
up mutation observers.
I would definitely expect the document element to exist at the point when
any content script is injected.
…On Tue, Dec 26, 2017 at 6:26 PM, CoolCmd ***@***.***> wrote:
Rather than testing for HEAD, I just add the STYLE directly to the
documentElement, which is always present, even at document-start.
In FF57 and GM4, documentElement is *not* always available at
document-start, at least on my machine.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#2724 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AFNSrmb5eKj-nY9vnR3d94bq5kIjaz9Tks5tEY7PgaJpZM4QnG03>
.
|
You can attach mutation observer to |
the current lack of scripting style is actually a complete disaster :-(
The text was updated successfully, but these errors were encountered: