如何触发Chrome扩展程序,URL中给定哈希的内容脚本?

Ale*_*lex 8 javascript manifest google-chrome-extension hashtag content-script

我的比赛计划:

"content_scripts" : [
 {
   "matches" : [
     "https://stackoverflow.com/questions#epic*"
   ],
   "js" : ["silly.js"]
 }
],
Run Code Online (Sandbox Code Playgroud)

因此,如果用户访问网页(如https://stackoverflow.com/questions),然后添加#epic它将转到https://stackoverflow.com/questions#epic但是会#epic在URL的末尾,这将激活内容脚本silly.js.

这应该发生的事情,但这不起作用.

Bro*_*ams 17

请参阅内容脚本,匹配模式.匹配模式不对查询或URL 的片段部分进行操作.

来限制内容脚本给定的散列,使用include_globs和/或exclude_globs性质.

例如,在这种情况下,您可以使用:

"content_scripts" :     [ {
    "matches" :         [
        "*://stackoverflow.com/questions/*"
    ],
    "include_globs" :   ["*#epic*"],
    "js" :              ["silly.js"]
} ],
Run Code Online (Sandbox Code Playgroud)