cannot create item with duplicate context menu id in extension

In Chrome, you should create the context menu just once after install/update.

Use onInstalled event:

chrome.runtime.onInstalled.addListener(() => {
  chrome.contextMenus.create({
    id: "zm_mark_down_preview_beta",
    title: 'preview and edit',
    contexts: ["editable"]
  });
});

Alternatively, you can simply suppress the error by accessing lastError in the callback:

chrome.contextMenus.create({
  id: "zm_mark_down_preview_beta",
  title: 'preview and edit',
  contexts: ["editable"]
}, () => chrome.runtime.lastError);

Leave a Comment