For some reason, Chrome doesn't load background tabs until Activated, selected, or both. I am writing a script with Manifest v3 to allow tabs to load when opened in the background that will Activate them and return to the original tab so they load. Currently, it is not working. Are there better workarounds than having a background process always running and sending a message to activate these tabs and return to current tab?
chrome.tabs.onCreated.addListener(newTab => newTabCreated(newTab));
async function newTabCreated(newTab) {
try {
const currentTab = await getCurrentTab();
await chrome.tabs.update(newTab.id, { active: true });
await chrome.tabs.update(currentTab.id, { active: true });
const loadedStatus = await chrome.tabs.query({status: "complete"});
loadedStatus.forEach(element => {
JSON.stringify(console.log(element));
});
console.log(`
current tab id: ` + JSON.stringify(currentTab.id) + `
new tab id: `+ JSON.stringify(newTab.id));
} catch (error) {
console.log("Error: " + error);
}
}
async function getCurrentTab() {
let queryOptions = { active: true, currentWindow: true };
const [tab] = await chrome.tabs.query(queryOptions);
return tab;
}