I need to add some Regex inside my chrome.declarativeContent.PageStateMatcher.
So far I have
var matcher = new chrome.declarativeContent.PageStateMatcher({
pageUrl: {
urlContains: "something/someRegex/something"
}
});
Essentially I want to have a regular expression to evaluate to "something/4-5 char string/somithing".
How would I do this? Is this possible to do with chrome.declarativeContent.PageStateMatcher?
Thanks
I need to add some Regex inside my chrome.declarativeContent.PageStateMatcher.
So far I have
var matcher = new chrome.declarativeContent.PageStateMatcher({
pageUrl: {
urlContains: "something.com/someRegex/something"
}
});
Essentially I want to have a regular expression to evaluate to "something.com/4-5 char string/somithing".
How would I do this? Is this possible to do with chrome.declarativeContent.PageStateMatcher?
Thanks
Share Improve this question asked Mar 10, 2014 at 19:17 d9120d9120 5111 gold badge8 silver badges23 bronze badges 1 |2 Answers
Reset to default 22Instead of urlContains use urlMatches
This is what I'm using for both domain fedmich.com and fedche.com
chrome.runtime.onInstalled.addListener(function() {
chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
chrome.declarativeContent.onPageChanged.addRules([
{
conditions: [
new chrome.declarativeContent.PageStateMatcher({
pageUrl: { urlMatches: '(fedmich|fedche)\.com' },
})
],
actions: [ new chrome.declarativeContent.ShowPageAction() ]
}
]);
});
});
documentation is here https://developer.chrome.com/extensions/events#property-UrlFilter-hostEquals
The regular expressions use the RE2 syntax. https://code.google.com/p/re2/wiki/Syntax
In https://developer.chrome.com/extensions/events#property-UrlFilter-hostEquals it describes urlMatches case.
something\.com/[^/]{4,5}/something
. It means any substring that isnt a "/" and is 4-5 characters in length. You also have to escape.
since it is a metacharacter and means "any character". – tenub Commented Mar 10, 2014 at 19:22