We have developed browser extensions for Chrome, Firefox, and Safari. The Firefox extension includes a tracker called tracker.js, which is accessed from the controller using this line of code:
tracker = require("../../firefox/tracker.js").tracker;
The tracker functionality relies on requiring other files such as:
if (typeof exports !== 'undefined') {
common = require("../content/src/common.js").common;
utils = require("../content/src/utils.js").utils;
}
var tracker = new function() {
this.ws_track = function(params) {
params["from_extension"] = true;
params["platform"] = common.sys.platform;
params["version"] = utils.get_version();
if (params["e"] === "install") {
utils.send_get_request(common.config.urls.apis.wstrack, params, function(data) {}, 'json');
}
};
};
if (typeof exports !== 'undefined') {
exports.tracker = tracker;
}
However, I encountered an error when trying to require the controller file from the tracker:
JPM [error] Message: TypeError: tracker is undefined
In this scenario, the tracker code looks like this:
if (typeof exports !== 'undefined') {
common = require("../content/src/common.js").common;
controller = require("../content/src/controller.js").controller;
utils = require("../content/src/utils.js").utils;
}
var tracker = new function() {
this.ws_track = function(params) {
params["from_extension"] = true;
params["platform"] = common.sys.platform;
params["version"] = utils.get_version();
var uid = controller.load_param("uid");
if (uid) {
params["uid"] = uid;
}
if (params["e"] === "install") {
utils.send_get_request(common.config.urls.apis.wstrack, params, function(data) {}, 'json');
}
};
};
if (typeof exports !== 'undefined') {
exports.tracker = tracker;
}
Not requiring the controller causes it to be undefined. How can I successfully require the controller from the tracker file? Combining the files is not an option since the controller file is utilized across all browsers, while each browser has its own unique tracker. (Mozilla did not approve our Chrome tracker).
Update: By moving the controller code to the controller itself and calling the tracker from there, I was able to resolve the issue (the tracker no longer depends on the controller). If you have any alternative solutions, please share them with me.