minor error handling fix
This commit is contained in:
@@ -498,25 +498,26 @@ let suppressObserver = false;
|
|||||||
|
|
||||||
async function refreshToolbar() {
|
async function refreshToolbar() {
|
||||||
suppressObserver = true;
|
suppressObserver = true;
|
||||||
let {
|
|
||||||
sites = [],
|
|
||||||
workspaces = [],
|
|
||||||
shortcuts = [],
|
|
||||||
presets = [],
|
|
||||||
toolbarPosition = "bottom-right",
|
|
||||||
theme = "system"
|
|
||||||
} = await chrome.storage.local.get([
|
|
||||||
"sites",
|
|
||||||
"workspaces",
|
|
||||||
"shortcuts",
|
|
||||||
"presets",
|
|
||||||
"toolbarPosition",
|
|
||||||
"theme"
|
|
||||||
]);
|
|
||||||
const currentUrl = window.location.href;
|
|
||||||
const site = sites.find(s => matchUrl(currentUrl, s.urlPattern));
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (!chrome?.runtime?.id) return;
|
||||||
|
let {
|
||||||
|
sites = [],
|
||||||
|
workspaces = [],
|
||||||
|
shortcuts = [],
|
||||||
|
presets = [],
|
||||||
|
toolbarPosition = "bottom-right",
|
||||||
|
theme = "system"
|
||||||
|
} = await chrome.storage.local.get([
|
||||||
|
"sites",
|
||||||
|
"workspaces",
|
||||||
|
"shortcuts",
|
||||||
|
"presets",
|
||||||
|
"toolbarPosition",
|
||||||
|
"theme"
|
||||||
|
]);
|
||||||
|
const currentUrl = window.location.href;
|
||||||
|
const site = sites.find(s => matchUrl(currentUrl, s.urlPattern));
|
||||||
|
|
||||||
if (!site) {
|
if (!site) {
|
||||||
const toolbar = document.getElementById("sitecompanion-toolbar");
|
const toolbar = document.getElementById("sitecompanion-toolbar");
|
||||||
if (toolbar) toolbar.remove();
|
if (toolbar) toolbar.remove();
|
||||||
@@ -551,6 +552,12 @@ async function refreshToolbar() {
|
|||||||
const resolvedTheme = resolveThemeValue(theme, workspace, site);
|
const resolvedTheme = resolveThemeValue(theme, workspace, site);
|
||||||
const themeMode = resolveThemeMode(resolvedTheme);
|
const themeMode = resolveThemeMode(resolvedTheme);
|
||||||
createToolbar(siteShortcuts, resolvedPosition, themeMode);
|
createToolbar(siteShortcuts, resolvedPosition, themeMode);
|
||||||
|
} catch (error) {
|
||||||
|
const message = String(error?.message || "");
|
||||||
|
if (message.includes("Extension context invalidated")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.warn("SiteCompanion toolbar refresh failed:", error);
|
||||||
} finally {
|
} finally {
|
||||||
window.setTimeout(() => {
|
window.setTimeout(() => {
|
||||||
suppressObserver = false;
|
suppressObserver = false;
|
||||||
@@ -565,7 +572,13 @@ function scheduleToolbarRefresh() {
|
|||||||
if (refreshTimer) return;
|
if (refreshTimer) return;
|
||||||
refreshTimer = window.setTimeout(() => {
|
refreshTimer = window.setTimeout(() => {
|
||||||
refreshTimer = null;
|
refreshTimer = null;
|
||||||
void refreshToolbar();
|
refreshToolbar().catch((error) => {
|
||||||
|
const message = String(error?.message || "");
|
||||||
|
if (message.includes("Extension context invalidated")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.warn("SiteCompanion toolbar refresh failed:", error);
|
||||||
|
});
|
||||||
}, 200);
|
}, 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user