Skip to content

The user’s CSS is injected before Refined GitHub’s #4731

Closed

Description

@fregante

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

Activity

  1. eqvinox commented on Aug 28, 2021

    @eqvinox
    * how does Stylus inject them?
    

    Ostensibly in the same way — because it has exactly the same result, i.e. doesn't work either. Screenshot:

    css2

  2. fregante commented on Aug 28, 2021

    @fregante
    MemberAuthor

    Wow. Thanks for checking and for the screenshot!

  3. kidonng commented on Oct 29, 2021

    @kidonng
    Member

    I had a feeling RGH...

    Screen Shot 2021-10-29 at 19 26 15

    ...is injecting duplicate styles when navigating to different pages via AJAX:

    Screen Shot 2021-10-29 at 19 26 24

    And it won't stop:

    Screen Shot 2021-10-29 at 19 25 46

  4. fregante commented on Oct 29, 2021

    @fregante
    MemberAuthor

    ...is injecting duplicate styles when navigating to different pages via AJAX:

    Time to bring out the big guns

  5. added
    Please! ♥︎
    on Oct 31, 2021
  6. cheap-glitch commented on Nov 8, 2021

    @cheap-glitch
    Contributor

    ...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.)

  7. fregante commented on Nov 8, 2021

    @fregante
    MemberAuthor

    ...is injecting duplicate styles when navigating to different pages via AJAX:

    Can't reproduce this on Firefox.

    I assume this is #4827 (comment)

  8. fregante commented on Nov 8, 2021

    @fregante
    MemberAuthor

    or use tab.insertCSS() directly like your polyfill does.

    That'd mean keeping track of each load from the background page. That API does it automatically (in Firefox)

    I haven't found an API to register a whole stylesheet

    https://developers.google.com/web/updates/2019/02/constructable-stylesheets

    Not sure if it's cross-browser yet

  9. eqvinox commented on Nov 8, 2021

    @eqvinox
  10. fregante commented on Nov 9, 2021

    @fregante
    MemberAuthor

    So… the Tab size workaround has broken somewhere along the way

    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.

  11. cheap-glitch commented on Nov 9, 2021

    @cheap-glitch
    Contributor

    Not sure if it's cross-browser yet

    It's only supported in Chrome & derived: https://caniuse.com/?search=adoptedStyleSheets.

    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?

  12. fregante commented on Nov 9, 2021

    @fregante
    MemberAuthor

    We could use contentScript.register on Firefox and adoptedStyleSheets on Chromium-based browsers

    One is enough, it's poly filled.

    Although I don't know if either of these methods can guarantee that user styles take precedence over RGH's

    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)

    Or, maybe we could register an empty CSS file directly in manifest.json, and modify its contents at runtime?

    Can't

  13. added
    small
    on Mar 12, 2022
  14. fregante commented on Mar 12, 2022

    @fregante
    MemberAuthor

    Let's use contentScript.register in the background script, right here:

  15. self-assigned this
    on Mar 13, 2022
  16. removed
    small
    on Mar 13, 2022
  17. removed their assignment
    on Mar 13, 2022
  18. fregante commented on Mar 13, 2022

    @fregante
    MemberAuthor

    This is actually kind of a pain because:

    • 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.

    CSS layers could be a solution, but still no Chrome/Safari support.

  19. kidonng commented on Mar 13, 2022

    @kidonng
    Member

    CSS layers could be a solution, but still no Chrome/Safari support.

    Actually recently released Chrome 99 adds support to layers, but still.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Please! ♥︎acceptedbugunder discussion

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions