NoobCoder
NoobCoder

Reputation: 167

Error when creating context menus in Chrome extension

I'm getting the following error. The extension is working fine as I want it to but what's with the error?

Extension Error

Upvotes: 0

Views: 221

Answers (2)

Xan
Xan

Reputation: 77591

Context items persist between extension reloads - something not very obvious.

So you're getting this when this code is executed a second time.

A common pattern is clear-then-register:

chrome.contextMenus.removeAll(function() {
  chrome.contextMenus.create(contextMenuItem);
  // Add more
});

If you're using an Event page (persistent: false background page), you probably don't want to execute that every time the page is woken up; wrap it in chrome.runtime.onStartup or even chrome.runtime.onInstalled (to register once per update).

Upvotes: 1

Peter Bode
Peter Bode

Reputation: 222

Have you added the menu to the permissions-part of your manifest.json? More info can be found here.

Upvotes: 0

Related Questions