Chrome extension simple script not being injected

后端 未结 1 586
感动是毒
感动是毒 2021-01-27 09:52

I\'m trying my first steps in writing a minimal Chrome extension, and I cannot figure out why it does not execute my clientScript.js.

This is my manifest.json:



        
相关标签:
1条回答
  • 2021-01-27 10:08

    Assuming you did reload the tab (the content scripts are injected only on initial tab load, see this for more info and a workaround), you're probably a victim of the infamous Google's decision to hide www in the address bar: if you enter the edit mode and select/copy the entire text (or simply double-click the address) you will see the site's URL is actually https://www.twitch.tv/ so your manifest.json has an incorrect URL pattern that doesn't match the real site.

    Simply use a generalized pattern like "https://*.twitch.tv/*" that will match both https://www.twitch.tv/ and https://twitch.tv/ and any other subdomain(s).

    P.S. as a debugging step, you can check if the content script is even injected by looking at the context selector in devtools console toolbar or in devtools -> Sources -> Content scripts panel. And if you want to restore the classic address bar behavior, see https://superuser.com/a/1498561

    0 讨论(0)
提交回复
热议问题