2

I've checked all the other threads I could find on this topic, but I haven't seen an issue like mine. I have a chrome extension manifest.json (version 3) where I declare that I want a js file and a css file injected based on a host match pattern:

"content_scripts": [
    {
        "matches": ["https://docs.google.com/presentation/d/*"],
        "js": ["/Assets/JS/PageScript.js"],
        "css": ["/Assets/CSS/PageCSS.css"]
    }
]

I know the host pattern is valid because the js file is injected and runs. However, the CSS file refuses to inject.

Did I miss something?

Kiansjet
  • 21
  • 3
  • Does the filename match exactly? Same case? Ensure it exists, that's it's readable and that it's valid. Try to re-create the CSS folder and the file. – fregante Mar 15 '21 at 05:55
  • I've been programmatically injecting the same file from the service worker side using `chrome.scripting.insertCSS()` and it works. I'm trying to move to static declarations since the webstore asks for justification of use of the scripting API and they'll probably just reject me and tell me to use static declarations. – Kiansjet Mar 15 '21 at 21:05

1 Answers1

1

docs.google.com is a SPA (Single-Page Application) so it preserves the same initially constructed page and just changes the visible URL via History API and rewrites the DOM of the page to imitate real navigation.

With your current manifest.json's matches it won't match if you opened the tab with docs on its home UI like docs.google.com/ or docs.google.com/document/u/0/ and then navigated to a document.

The solution is to match the entire site: https://docs.google.com/* and maybe fix some CSS rules inside so they only match things on pages you want and don't match things on other pages.

See also methods of detecting history navigation.

wOxxOm
  • 65,848
  • 11
  • 132
  • 136
  • thanks for the tip and ur right I didn't consider that. Still, my #1 concern at the moment is that I *know* the url is matching since the javascript under the same pattern is successfully injected, but my css isn't injecting. – Kiansjet Mar 15 '21 at 21:03
  • 1
    Sounds like a bug. Probably [this one](https://stackoverflow.com/a/66643016). – wOxxOm Mar 15 '21 at 21:08