Skip to content

fix(context-menus): avoid duplicate id errors on service worker restart - #567

Merged
sebastienfontaine merged 1 commit into
masterfrom
fix/context-menus-duplicate-id
Oct 14, 2026
Merged

sebastienfontaine merged 1 commit into
masterfrom
fix/context-menus-duplicate-id

Conversation

@sebastienfontaine

Copy link
Copy Markdown
Contributor

Problem

After the service worker restarts, chrome://extensions/ shows an Errors button with 6 messages:

Unchecked runtime.lastError: Cannot create item with duplicate id rename-tab

(same for merge-windows, send-to-hive, tab-hive-reject-parent, tab-hive-reject-domain, tab-hive-reject-url).

Manifest V3 service workers are stopped and restarted often, and contextMenuService.initialize() runs at every startup. Context menus persist across restarts, so every create after the first startup fails. The menus keep working; it's only noise, but users see the Errors button. This predates the recent upgrades (same code in 1.1.6).

Found during the manual test campaign on 773bb42.

Fix

initialize() now calls chrome.contextMenus.removeAll() and creates the menus in its callback. The signature stays synchronous, so the call in background.ts is unchanged.

Tests

  • New: removeAll is called before any create.
  • New: initializing twice (service worker restart), with a stateful fake that rejects duplicate ids like Chrome, creates no duplicates and leaves exactly 6 menus.
  • Both fail without the fix. Full suite: 228 passed; ESLint, Prettier, vue-tsc and build OK.

Context menus persist across MV3 service worker restarts, but initialize()
recreated them at every startup, logging 'Cannot create item with duplicate
id' for each of the 6 menus. Clear them with removeAll() first.
@github-actions

Copy link
Copy Markdown

📦 Extension Build Ready!

Version: 1.1.6

📥 Download Extension (tabee.zip)

Installation

  1. Download and extract the zip file
  2. Open Chrome → chrome://extensions/
  3. Enable "Developer mode" (top right)
  4. Click "Load unpacked" → Select the extracted folder

Status

  • ✅ All tests passed
  • ✅ Build successful
  • ✅ Ready for testing

🤖 Auto-generated by GitHub Actions

@github-actions

Copy link
Copy Markdown

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 57.06% 594 / 1041
🔵 Statements 57.52% 627 / 1090
🔵 Functions 64.21% 122 / 190
🔵 Branches 52.71% 291 / 552
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/background/ContextMenuService.ts 100% 100% 100% 100%
Generated in workflow #473 for commit ca3be98 by the Vitest Coverage Report Action

@sebastienfontaine
sebastienfontaine merged commit 1f06be8 into master Oct 14, 2026
7 checks passed
@sebastienfontaine
sebastienfontaine deleted the fix/context-menus-duplicate-id branch October 14, 2026 20:00
@sebastienfontaine sebastienfontaine mentioned this pull request Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant