chrome.runtime.onInstalled.addListener(({ reason }) => { if (reason === 'install') chrome.runtime.openOptionsPage(); }); chrome.action.onClicked.addListener(async tab => { const cfg = await chrome.storage.sync.get({ portal: '', norm: 0 }); if (cfg.portal && !(tab.url || '').startsWith(cfg.portal)) return chrome.tabs.create({ url: cfg.portal }); const target = { tabId: tab.id }; try { // MAIN — чтобы скрипту были видны BX и сессия портала await chrome.scripting.executeScript({ target, world: 'MAIN', func: c => { window.myTimeConfig = c; }, args: [cfg] }); await chrome.scripting.executeScript({ target, world: 'MAIN', files: ['mytime.js'] }); } catch { chrome.runtime.openOptionsPage(); // служебная страница браузера, туда скрипт не пустят } });