Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to trigger a Chrome extension, content-script for a given hash in the URL?

My matches scheme:

"content_scripts" : [
 {
   "matches" : [
     "https://stackoverflow.com/questions#epic*"
   ],
   "js" : ["silly.js"]
 }
],

So if the user went to a webpage (like https://stackoverflow.com/questions) then added #epic it would go to https://stackoverflow.com/questions#epic but would have #epic on the end of the URL, which would activate the content script silly.js.

That's what's supposed to happen, but that doesn't work.

like image 286
Alex Avatar asked Apr 11 '13 21:04

Alex


1 Answers

See Content scripts, Match Patterns.
Match patterns do not operate on the fragment portion of a URL.

To restrict a content script to a given hash, use the include_globs and/or exclude_globs properties.

For example, in this case you might use:

"content_scripts" :     [ {
    "matches" :         [
        "*://stackoverflow.com/questions/*"
    ],
    "include_globs" :   ["*#epic*"],
    "js" :              ["silly.js"]
} ],
like image 173
Brock Adams Avatar answered Sep 18 '22 23:09

Brock Adams