Skip to content

Commit 025cbb8

Browse files
committed
fix: also wrap menus.mjs openSidePanel call in try/catch
contextMenus.onClicked.tab is optional per the Chrome API ('If the click did not take place in a tab, this parameter will be missing'). The openSidePanel action dereferences tab.windowId/tab.id, so it can throw synchronously, which the existing .catch() Promise handler would not catch. Mirror the pattern already used in src/background/commands.mjs by wrapping the call in try/catch. Addresses devin-ai-integration[bot] review on src/background/menus.mjs:23.
1 parent 0f82ecd commit 025cbb8

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

src/background/menus.mjs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,17 @@ const onClickMenu = (info, tab) => {
1515
// Keep the call synchronous to preserve the user-gesture requirement,
1616
// but observe the returned Promise so a rejected sidePanel.open() does
1717
// not become an unhandled rejection in the background script.
18-
const result = menuConfig.openSidePanel.action(true, tab)
18+
// Also wrap in try/catch because contextMenus.onClicked documents `tab`
19+
// as optional ("If the click did not take place in a tab, this parameter
20+
// will be missing"), so the openSidePanel action that dereferences
21+
// tab.windowId/tab.id can throw synchronously.
22+
let result
23+
try {
24+
result = menuConfig.openSidePanel.action(true, tab)
25+
} catch (error) {
26+
console.error('failed to open side panel', error)
27+
return
28+
}
1929
if (result && typeof result.catch === 'function') {
2030
result.catch((error) => {
2131
console.error('failed to open side panel', error)

0 commit comments

Comments
 (0)