Below is the code snippet of background.js (background_server) file of chrome extension
//fetch the data stored in chrom.storage.local
let allGroupNames = [];
let storedGroupsData = {}
const urlHistoryMap = new Map();
const fetchStoredData = async () => {
try {
storedGroupsData = (await chrome.storage.local.get('storedGroupsData')).storedGroupsData || {};
allGroupNames = Object.keys(storedGroupsData);
} catch (error) {
console.log(error);
}
};
// url and tabID of the opened tabs
const fetchOpenedTabs = async () => {
try {
// urlHistoryMap.clear();
const response = await chrome.tabs.query({});
const data = await response;
data.map((item) => {
if (!Array.from(urlHistoryMap.values()).includes(item.url)) {
urlHistoryMap.set(item.id, item.url)
}
})
// console.log(urlHistoryMap);
} catch (error) {
console.log(error);
}
}
fetchStoredData();
fetchOpenedTabs();
// onUpdate event
chrome.tabs.onUpdated.Listener(){
// code
}
What will be the order of execution of fetchStoredData()
, fetchOpenedTabs()
and chrome.tabs.onUpdated.Listener(){}
? I want fetchStoredData()
and fetchOpenedTabs()
to run before the chrome.tabs.onUpdated.Listener(){}