createContextMenu
April 11, 2026 · View on GitHub
It wraps chrome.contextMenus.create and chrome.contextMenus.onClicked and resolves many of its issues:
- it returns a promise (the native one only supports callbacks)
- it does not throw if you call it twice with the same
id - it does not throw if the API is not available on the platform (Firefox Android, Safari iOS)
- it does throw helpfully if you forgot to add the
contextMenuspermission - it enables the
onclickhandler even in service workers
import createContextMenu from 'webext-tools/create-context-menu.js';
createContextMenu({
id: 'example-context-menu',
title: 'Open example.org',
contexts: ['action'],
onclick(_, tab) {
void chrome.tabs.create({url: 'https://example.org', openerTabId: tab.id});
},
});
Compatibility
- Any browser
Permissions
contextMenuspermission
Context
- Background
API
createContextMenu(settings)
Creates a context menu.
settings
See the native CreateProperties type, disregard the "not available" note regarding onclick because it works here.