If I understand correctly what you are trying to do, then page-mod is the wrong solution - you just want to listen to the active tab. Use the tabs module to do this, listen to ready (new URL loaded) and activate (active tab changed):
var tabs = require("tabs"); tabs.on("ready", function(tab) { if (tab == tabs.activeTab) updateActiveTab(tab); }); tabs.on("activate", function(tab) { updateActiveTab(tab); });
Your updateActiveTab() function will need to check tab.url and activate or deactivate the widget. If you want to use templates for them similar to the ones you specify for page-mod , then you need to use an internal match-pattern module like this
var {MatchPattern} = require("match-pattern"); var patterns = [ new MatchPattern("*.site1.com"), new MatchPattern("*.site2.com") ]; function updateActiveTab(tab) { var matches = false; for (var i = 0; i < patterns.length; i++) if (patterns[i].test(tab.url)) matches = true; if (matches) activateWidget(); else deactivateWidget(); }
But of course, you can just use a regular expression or something similar to test tab.url , you do not need to use the match-pattern module.
Disclaimer: The code examples are only there to facilitate understanding of the approach, they have not been tested.
source share