Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex in chrome.declarativeContent.PageStateMatcher

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

like image 860
d9120 Avatar asked Mar 10 '14 19:03

d9120


1 Answers

Instead 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

like image 91
fedmich Avatar answered Nov 03 '22 01:11

fedmich