chrome.runtime.onStartup.addListener(checkExistingTabs);
chrome.runtime.onInstalled.addListener(info => {
if (info.reason === 'update' || info.reason === 'install') {
chrome.sidePanel.setPanelBehavior({openPanelOnActionClick: true});
chrome.sidePanel.setOptions({enabled: false});
checkExistingTabs();
}
});
chrome.webNavigation.onCommitted.addListener(info => {
if (!info.frameId) enableForTabId(info.tabId);
}, { url: HOSTS.map(h => ({hostEquals: h})) });
async function checkExistingTabs() {
for (const tab of await chrome.tabs.query({ url: HOSTS.map(h => `*://${h}/*`) })) {
enableForTabId(tab.id);
}
}
function enableForTabId(tabId) {
return chrome.sidePanel.setOptions({
tabId,
enabled: true,
path: 'sidepanel.html',
});
}