Skip to content

Commit 2005c6c

Browse files
improve context menu handling
- clear existing menus before creating, maybe resolves #139 - added error logging
1 parent ed0c79a commit 2005c6c

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

src/background.js

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -281,26 +281,33 @@ async function createBookmarkFromContextMenu(tab) {
281281

282282
// LIFECYCLE METHODS //
283283

284-
function handleInstalled(details) {
284+
async function handleInstalled(details) {
285285
if (details.reason === "install") {
286286
// set uninstall URL
287287
chrome.runtime.setUninstallURL("https://forms.gle/6vJPx6eaMV5xuxQk9");
288288
// todo: detect existing speed dial folder
289289
} else if (details.reason === 'update') {
290-
if (details.previousVersion < '3.3') {
291-
const url = chrome.runtime.getURL("updated.html");
292-
chrome.tabs.create({ url });
293-
}
290+
if (details.previousVersion < '3.3') {
291+
const url = chrome.runtime.getURL("updated.html");
292+
chrome.tabs.create({ url });
293+
}
294294
// perform any migrations here...
295295
}
296-
// create context menu
297-
chrome.contextMenus.create({
298-
"title": "Add to Speed Dial",
299-
"contexts": ['page'],
300-
"documentUrlPatterns": ['https://*/*', 'http://*/*'],
301-
"id": "addToSpeedDial"
302-
});
303296

297+
try {
298+
// remove existing menus to avoid issues with previous versions
299+
await chrome.contextMenus.removeAll();
300+
301+
// create context menu
302+
chrome.contextMenus.create({
303+
title: "Add to Speed Dial",
304+
contexts: ["page"],
305+
documentUrlPatterns: ["https://*/*", "http://*/*"],
306+
id: "addToSpeedDial",
307+
});
308+
} catch (error) {
309+
console.log("Error managing context menus:", error.message);
310+
}
304311
}
305312

306313

0 commit comments

Comments
 (0)