You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
The user’s CSS is injected before Refined GitHub’s #4731
The CSS field in the options is supposed to be used as overrides to Refined GitHub's styles but it's actually injected earlier than RG's, so RG ends up overriding it instead.
We need to find alternative solutions for the injection. For example:
how does Stylus inject them?
can it be registered via contentScript.register()? Does the behavior differ in Chrome's polyfill?
is there any new way to register stylesheets? For example some CSSOM api
...is injecting duplicate styles when navigating to different pages via AJAX:
Can't reproduce this on Firefox.
can it be registered via contentScript.register()?
Yes we can register CSS using contentScript.register(), or use tab.insertCSS() directly like your polyfill does.
is there any new way to register stylesheets? For example some CSSOM api
I haven't found an API to register a whole stylesheet, but we could use insertRule() on the main RGH stylesheet to append the user-CSS to it. (Although that might mean manually splitting the CSS into several rules before injecting it.)
We could use contentScript.register on Firefox and adoptedStyleSheets on Chromium-based browsers. Although I don't know if either of these methods can guarantee that user styles take precedence over RGH's.
Or, maybe we could register an empty CSS file directly in manifest.json, and modify its contents at runtime?
even with contentScript.register/insertCSS we can't guarantee that the order is what we expect
there's no way to catch the injection of the static CSS file, although we could detect it via getComputedStyle
an installation might have multiple CSS due to Enterprise support, so this should probably be done in the content script instead of the background page, because that would be rather complicated
Could something as simple as document.body.prepend(<style/>) work? The rest of the stylesheets should be in the HEAD and refined-github.css presumably has the same weight.
Activity
eqvinox commentedon Aug 28, 2021
Ostensibly in the same way — because it has exactly the same result, i.e. doesn't work either. Screenshot:
fregante commentedon Aug 28, 2021
Wow. Thanks for checking and for the screenshot!
kidonng commentedon Oct 29, 2021
I had a feeling RGH...
...is injecting duplicate styles when navigating to different pages via AJAX:
And it won't stop:
fregante commentedon Oct 29, 2021
Time to bring out the big guns
cheap-glitch commentedon Nov 8, 2021
Can't reproduce this on Firefox.
Yes we can register CSS using
contentScript.register(), or usetab.insertCSS()directly like your polyfill does.I haven't found an API to register a whole stylesheet, but we could use
insertRule()on the main RGH stylesheet to append the user-CSS to it. (Although that might mean manually splitting the CSS into several rules before injecting it.)fregante commentedon Nov 8, 2021
I assume this is #4827 (comment)
fregante commentedon Nov 8, 2021
That'd mean keeping track of each load from the background page. That API does it automatically (in Firefox)
https://developers.google.com/web/updates/2019/02/constructable-stylesheets
Not sure if it's cross-browser yet
eqvinox commentedon Nov 8, 2021
fregante commentedon Nov 9, 2021
Refined GitHub dropped the custom tab size in https://github.com/refined-github/refined-github/releases/tag/21.10.4 because GitHub now lets you customize it directly.
Your custom CSS can be avoided. Also it's off-topic here.
cheap-glitch commentedon Nov 9, 2021
It's only supported in Chrome & derived: https://caniuse.com/?search=adoptedStyleSheets.
We could use
contentScript.registeron Firefox andadoptedStyleSheetson Chromium-based browsers. Although I don't know if either of these methods can guarantee that user styles take precedence over RGH's.Or, maybe we could register an empty CSS file directly in
manifest.json, and modify its contents at runtime?fregante commentedon Nov 9, 2021
One is enough, it's poly filled.
The native version probably does, the polyfill I'm not too sure, even if there's a test for it (but it occasionally fails I think)
Can't
fregante commentedon Mar 12, 2022
Let's use
contentScript.registerin the background script, right here:refined-github/source/background.ts
Line 11 in b9c951a
fregante commentedon Mar 13, 2022
This is actually kind of a pain because:
contentScript.register/insertCSSwe can't guarantee that the order is what we expectgetComputedStyleCould something as simple as
document.body.prepend(<style/>)work? The rest of the stylesheets should be in the HEAD andrefined-github.csspresumably has the same weight.CSS layers could be a solution, but still no Chrome/Safari support.
kidonng commentedon Mar 13, 2022
Actually recently released Chrome 99 adds support to layers, but still.