Hi,
I am working on porting over a Chrome extension to Firefox. However with the temporary add on installed in Firefox, I keep getting “ReferenceError: chrome is not defined”. I am trying to send a message from my content script to my background.js file in the extension. Everything works perfectly in Chrome but that message that I’m trying to send allows the extension to know if I’m logged into the website and am verified to use the our API. Because of this, due to other code that processes, the extension pops up, it just can’t log me in. Is there any reason you all can think of why chrome would be undefined in Firefox if it should be compatible with Chrome? I tried browser.runtime as well and get the same issue “ReferenceError: browser is not defined. Any help would be greatly appreciated.
Thank you,
Daniel
If it helps here is my background.js
chrome.runtime.onMessageExternal.addListener(
function(request, sender, sendResponse) {
if (request) {
if (request.message) {
if (request.message == “version”) {
sendResponse({version: 1.0});
}
}
if (request.token == “not added”) {
window.token_string = “”;
localStorage.setItem(“giftibly_token”, “”);
}
else{
window.token_string = request.token;
localStorage.setItem(“giftibly_token”, token_string);
}
}
return true;
}
);
var isChromium = window.chrome,
winNav = window.navigator,
vendorName = winNav.vendor;
if (isChromium !== null && typeof isChromium !== “undefined” && vendorName === “Google Inc.”) { //if Chrome
chrome.extension.onConnect.addListener(function(port) {
port.onMessage.addListener(function(msg) {
console.log(msg);
if(msg == “token not added”){
port.postMessage(token_string);
}
});
});
}
else{
browser.runtime.onConnect.addListener(function(port) { //if not Chrome
port.onMessage.addListener(function(msg) {
console.log(msg);
if(msg == “token not added”){
port.postMessage(token_string);
}
});
});
}
And my content script. The turbolinks:load function is due to my project using Ruby on Rails.