Context menu items are context-aware and only appear when relevant
Why it matters
Context menu items registered with contexts: ['all'] appear on every right-click — blank page areas, the New Tab page, chrome:// settings, PDFs — cluttering the menu with options that cannot function in those contexts. Users right-clicking to copy text wade past irrelevant extension entries, and Chrome Web Store reviewers flag menu-spamming extensions as a policy concern under the single-purpose and minimal-permission guidelines. On pages where the extension has no host permission, clicking the item produces a silent no-op and looks broken.
Severity rationale
Info because over-broad contexts degrade polish and discoverability without breaking core functionality.
Remediation
Scope every chrome.contextMenus.create call to the narrowest context that makes sense: ['selection'] for text actions, ['image'] for image actions, ['link'] for link actions. Add documentUrlPatterns to exclude pages where the extension cannot operate. In background.js:
chrome.contextMenus.create({
id: 'search-selection',
title: 'Search "%s"',
contexts: ['selection'],
documentUrlPatterns: ['https://*/*', 'http://*/*'],
});
Detection
-
ID:
context-menus-aware -
Severity:
info -
What to look for: Examine
chrome.contextMenus.createcalls. For each menu item, check thecontextsarray — does it specify the narrowest context in which the item makes sense? For example, a "Search selected text" item should usecontexts: ['selection'], notcontexts: ['all']. An "Open image in extension" item should usecontexts: ['image']. Check whether menu items are conditionally shown or hidden based on page context (URL patterns viadocumentUrlPatterns, or dynamic visibility updates). Count all instances found and enumerate each. -
Pass criteria: All context menu items specify appropriate
contextsarrays that limit their appearance to when they are actually usable. Image-specific actions usecontexts: ['image']. Text-action items usecontexts: ['selection']. Items not relevant to the current page are hidden viadocumentUrlPatternsor dynamicupdatePropertiescalls. At least 1 implementation must be confirmed. -
Fail criteria: Context menu items use
contexts: ['all']when a more specific context applies, causing them to appear in all right-click menus everywhere regardless of relevance. Extension adds many menu items that clutter the context menu on all pages regardless of whether the extension can do anything useful there. -
Skip (N/A) when: The extension does not register any context menu items (no
chrome.contextMenus.createcalls and nocontextMenuspermission in manifest). -
Detail on fail: Describe the over-broad contexts. Example:
"'Analyze Image' context menu item uses contexts:['all'] — appears on every right-click including on blank page areas and text, where it serves no purpose"or"3 extension menu items appear on all pages including the browser's New Tab page and settings pages where the extension cannot function." -
Remediation: Narrow context menu item scope with specific
contextsanddocumentUrlPatterns:chrome.contextMenus.create({ id: 'analyze-image', title: 'Analyze with MyExtension', contexts: ['image'], // Only on right-clicked images }); chrome.contextMenus.create({ id: 'search-selection', title: 'Search "%s" in MyExtension', contexts: ['selection'], // Only when text is selected documentUrlPatterns: ['https://*/*', 'http://*/*'], });
Taxons
History
- 2026-04-18·v1.0.0·Initial import from extension-ux-performance·automated