Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Match all URLs except certain URLs in Chrome Extension

I'm trying to have it so that my content script runs on every site except for 3. I know there's probably a way to do it with regex but I'd prefer not to. Does the chrome extension manifest allow for exceptions?

If regex is the only solution and anyone knows the pattern to exclude these 3 URLs that would be great too.

https://www.linkedin.com/
https://mail.google.com/
https://twitter.com/
like image 533
Ryan Grush Avatar asked Sep 10 '15 19:09

Ryan Grush


2 Answers

https://developer.chrome.com/extensions/content_scripts lists an option exclude_matches:

"content_scripts": [
    {
        "matches": ["<all_urls>"],
        "js": ["myscript.js"],
        "exclude_matches": [
            "https://www.linkedin.com/",
            "https://mail.google.com/",
            "https://twitter.com/"
        ]
    }
]

I'm guessing you'll want a * at the end of those: "https://twitter.com/*", et.c., to exclude the script on all pages on those domains, and not just the homepages. You can also look into the exclude_globs option.

like image 79
Teepeemm Avatar answered Oct 05 '22 06:10

Teepeemm


Well, in this case, Regex is quite straight forward:

(www\.linkedin\.com)|(mail\.google\.com)|(twitter\.com)

)nly thing, you have to escape the dots (.) With Backslash (). Assuming the protocol should be left open. Else just put the escaped protocol up front

https:\/\/
like image 20
azt Avatar answered Oct 05 '22 05:10

azt