I am building a chrome extension and would like to detect when the active tab is changed and record it in a firestore database. I have written and debugged the code. It doesn't show any error, but it doesn't update either. It just does nothing. I have also tried this with onActivated instead of onUpdated but it still doesn't do anything. Here is my javascript code:
const firebaseConfig = {
apiKey: "xxxxxxx-I8oUvn4jR3foTWrZWSpmWMbikPtJjeg",
authDomain: "webxxxxr-xxxxx.firebaseapp.com",
projectId: "webxxxxr-xxxxx",
storageBucket: "webxxxxr-xxxxx.appspot.com",
messagingSenderId: "xxxxxxx85181",
appId: "x:xxxxxxx85181:x:xxxxxxxdbeaed13e83e274"
};
// Initialize Firebase
const app = firebase.initializeApp(firebaseConfig);
const db = app.firestore();
var idTag = "lcoddjhmpnblmfbbkbdgeamnpbclekof";
chrome.runtime.sendMessage(idTag, {getTargetData:true},
function(response) {
var id = response.targetData;
db.collection('browsers').doc(id).onSnapshot((doc) => {
if (doc.exists) {
chrome.tabs.onUpdated.addListener(handleActivated());
function handleActivated(activeInfo) {
chrome.tabs.getSelected(null, function(tab) {
db.collection('browsers').doc(id).update({
'tab': tab.url,
});
})
}
} else {
}
})
}
);