Search code examples
firefox-addon-sdk

how to specify include and exclude url patterns together in a pageMod?


I want my pageMod to load for all pages except a particular domain(s).

currently i have specified

include:['*'] in the pageMod that loads it for all urls.

how can i make it avoid particular domains such as www.example.com and load for the rest?


Solution

  • There is no 'exclude' property for page-mod ( and after some fiddling I could not get negative lookahead assertions to work well ), so I expect the best route might be to use the tabs module instead:

    var tabs = require('tabs');
    
    tabs.on('open', function(tab) {
        // some url exclusion logic?
        if (tab.url.indexOf('http://example.com') !== -1) {
            tab.on('ready', function(tab) {
                let worker = tab.attach({
                    contentScriptfile: data.url('somefile.js')
                });
    
                worker.on('event', function(message) {
                    //...
                });
            });
        }
    });