Match url patterns in firefox addons

I can't figure out how to use regex matching patterns in Firefox add-ons (using the Add-on Builder). I tried using match-pattern

package
.

My main.js

looks like this:

var { MatchPattern } = require("match-pattern");
//Matching all urls containing moz and chrome
var pattern = new MatchPattern(/.*moz.*/);
var pattern2 = new MatchPattern(/.*chrome.*/);

var pageMod = require("page-mod");
var data = require("self").data;

pageMod.PageMod({
    include: [pattern, pattern2],
    contentScriptWhen: 'ready',
    contentScriptFile: [data.url('jquery-1.7.1.min.js'),data.url('jquery-ui.js')]

});

      

But the Error console shows this error:

Timestamp: 3/19/2012 9:03:34 PM Error: An exception occurred. Traceback (last call last): File "Resource: //jid0-m6oqvn6bm6wcoo89bddsxwddkou-at-jetpack/api-utils/lib/match-pattern.js", line 87, in MatchPattern_test this.regexp.exec (urlStr) [0] == urlStr) TypeError: this.regexp.exec is not a function

What am I doing wrong here? Can I pass regex matching patterns in an array include

pageMod

? Any help would be appreciated.

+3


source to share


1 answer


You don't need to use the package match-pattern

directly, it is used by the backend module page-mod

. Just pass the regular expressions as a parameter include

:



pageMod.PageMod({
    include: [/.*moz.*/, /.*chrome.*/],
    ...
});

      

+9


source







All Articles