Match all URLs except certain URLs in Chrome Extension

本秂侑毒 提交于 2020-01-02 06:12:10

问题


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/

回答1:


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.




回答2:


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:\/\/


来源:https://stackoverflow.com/questions/32509752/match-all-urls-except-certain-urls-in-chrome-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!