-
Notifications
You must be signed in to change notification settings - Fork 306
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
Use browser.tabs.insertCSS everywhere #248
Comments
tabs.insertCSS approach has some problems which I've described several times over the last year here and there.
Right now I'm not interested in the least. In the future, yeah quite possible. Maybe someone else will do it as I'm just another user and I don't visit weird sites that remove our styles or overwrite their pages entirely.
We can protect the style elements, it's neither hard nor CPU-intensive. |
Makes sense, thanks. I will watch for any cases of style disappearance and try to understand how it happens. |
I remember when we dealt with mmo-champion.com page, which was rewritten by uBlock Extra extension via document.write, I experimented with protecting and used for that a non-recursive (hence superfast) MutationObserver on the documentElement. It turned out unnecessary so the change wasn't committed. If you find real sites (not PoC) that delete our style elements, I'll reintroduce the feature. Probably with some kind of time limit in order not to cause deadlocks with a super aggressive site script. |
Another approach is to insert style code inside a ShadowDOM root on documentElement - it requires dynamic rewriting of all CSS selectors in order to add |
It looks like there is a Chrome feature request to add https://bugs.chromium.org/p/chromium/issues/detail?id=608854 |
@yurikhan actually, it looks like the patch for it already exists and has more or less passed review as well. It's also compatible with the Firefox implementation. Seems like this could land in Chrome any day now. Perhaps the solution is for someone representative (as in, a project contributor+) to draw attention to that bug? |
Update: crrev.com/c/765642 adds CSSOrigin to the internals so we can hope it'll be exposed in the extensions API. Not that it solves the bigger problem with the lack of tabs.removeCSS in Chrome... |
Test version that uses tabs.insertCSS everywhere in FF [edit: updated the link] fixes the issue. |
Gave that test version a quick try in Firefox Nightly 59.0a1 (2018-01-05): I noticed this warning when loading the temporary addon, but the extension still worked:
Updating a style seems to be partially broken in this version. When I edit a style, the page style is not updated immeditately. When I reload the page, it is unstyled on first reload but when reloading a second time, the style gets applied again. I strongly recommend using the |
@silverwind, that version is buggy and currently not developed, mainly because I don't use FF and the implementation turned out to be more complicated - Stylus has to enumerate sub-frames on each page, and IIRC there are certain bugs in various versions of FF that aren't easy to circumvent.
You can disregard it.
Bad idea. Making it the default will break all styles that don't use |
I'm aware of that, but that's how the old Stylish for Firefox actually worked and their docs recommend putting |
It's the only way I'll accept. |
Okay. BTW, can you elborate
Is this because Chrome would error out when loading the extension because it requests unknown permissions? |
It's an old remark, no longer relevant as I found a way to use declarativeContent in Chrome. |
Let's say that I'd like to add such a option and work on using |
You can use both branches, but be prepared to have a hard time as there are lots of edge cases. I don't know when I'll be interested in working on that branch. I don't plan to rewrite it per se, it's just the way it goes: I already rewrote it several times because the implementation was either incorrect or I got blocked by some bug in FF. Just found I have another attempt locally so I've pushed it into |
Bad outdated advice based on the web in those days with lots of inline styles etc. Anyway, Stylus is based on Stylish-for-Chrome, with its more than a million of users, which always used
I don't see that. |
Actually according to the page I linked, even Stylish for Firefox was inserting |
Currently Stylus adds style elements at the end of DOM so a userstyle's As for USER_AGENT, there's simply no method to implement it other than process the entire DOM manually. Obviously, it'll be slow. |
Let me give you an example why I need body {
background-color: #111 !important;
} Now take a look at the CSS of http://www.imdb.com/: they have body#styleguide-v2 {
background-color: #e3e2dd !important;
} In the old Stylish, I just used a |
Well, USER_AGENT is out of the question. As for the imdb example, you can simply use a specificity hack like |
Interesting. I haven't thought about exploiting
Why thought? If we implement a select box for CSS origin and a browser supports inserting user agent sheets, why not provide the option? |
tabs.insertCSS doesn't support |
I meant we should only support it if the browser supports inserting |
Another concern is that tabs.insertCSS with |
Yes, that sounds like a possible source of issues because |
I think this discussion needs to be brought up on https://discourse.wicg.io/ to get feedback. |
In practice, Firefox behaves sanely. My injected styles consistenly win over page styles. |
Uhm, this is too vague without describing whether the specificity was identical, whether |
Oh fine. I filed a documentation request for that. |
Thanks for the pointer. That place seems not the right one for talking about web extensions, but I created a proposal for the cascade issue of |
FYI
|
@mjethani It appears the patch is stuck in a merge conflict. is that the holdup ? |
@uBlock-user the patch has been stuck in review forever. I have asked multiple times but received no response. I have no idea what the problem is, but I am disappointed by the lack of transparency and openness. If you would like to see this resolved, please star Chromium issue #608854 and leave a comment explaining your use case. |
@mjethani That's really disappointing to see that happen to you when you put so much effort and time into this. I have starred the issue. |
it looks like the docs have finally been clarified for Firefox at least. bugzilla issue: https://bugzilla.mozilla.org/show_bug.cgi?id=1428398 |
IIRC, Chromium is the problem. |
Right you are, sorry. I should've clarified that I was speaking specifically to this documentation request from earlier in this thread that was filed to assuage concerns about the cascade order. |
https://crrev.com/c/2250506 finally added removeCSS based on @mjethani's code so it'll be available in Chrome 87, right now in Chromium trunk builds, and Chrome Canary in a day or two. |
No generate incompatible few CSS-es (?), inline Perhaps it is better to introduce detection of: *[style*="important"] {
... : ...;
} and then only try use |
Currently, Stylus applies styles to most pages by sending them in a message to a content script which creates a
style
element and inserts it into the page DOM.(An exception to that is XML documents, for which the message gets reflected back to the background script and styles are applied via the
browser.tabs.insertCSS
API.)As a result of injection being performed from a content script, the page’s own scripts see the
style
elements and can tamper with them. As a realistic example, a slowly loading page can unintentionally overwrite the injected styles.Taken from the security point of view, this is an information disclosure vulnerability (page script has access to the userstyle source, can leak it to the site owner to fingerprint the user) and can be a tampering vulnerability (page script can deny the user’s right to customize site appearance).
I have made a proof-of-concept page.
To reproduce:
Create a global style or a style that applies specifically to that URI. E.g.:
Navigate to that page. Observe that the page background is a pleasant light green, as specified by the user style.
Wait a second. Observe that the page script notices the user style and removes it, restoring its ugly brown background.
I have loaded the
apply-css
example extension that demonstrates theinsertCSS
API, and the style it injects is not detected by the page script.Is there any reason why
insertCSS
should not be used for all pages which it is able to handle?The text was updated successfully, but these errors were encountered: