Skip to content

[Feature Request] chrome.contextMenus entry to switch profiles from right-click #110

Description

@chirag127

Summary

Add a chrome.contextMenus entry so users can right-click on any page and switch profiles (or toggle a specific extension) without opening the popup.

Motivation

The popup is the only way to switch profiles today. For users on multiple monitors or with the extension icon hidden behind Chrome's "puzzle piece" pinning menu, opening the popup is 2 clicks + a small target. A right-click context menu on the page itself is a single fluent gesture and always available regardless of icon visibility.

Proposed change

Manifest additions:

"permissions": ["management", "storage", "contextMenus"]

In the service worker (js/migration.js or a new background.js):

chrome.runtime.onInstalled.addListener(rebuildMenu);
chrome.storage.onChanged.addListener((changes) => {
  if (changes.profiles) rebuildMenu();
});

async function rebuildMenu() {
  await chrome.contextMenus.removeAll();
  chrome.contextMenus.create({
    id: 'extensity-root',
    title: 'Extensity',
    contexts: ['page', 'action'],
  });
  const { profiles = {} } = await chrome.storage.sync.get('profiles');
  for (const name of Object.keys(profiles)) {
    chrome.contextMenus.create({
      id: `switch:${name}`,
      parentId: 'extensity-root',
      title: `Switch to: ${name}`,
      contexts: ['page', 'action'],
    });
  }
}

chrome.contextMenus.onClicked.addListener((info) => {
  if (info.menuItemId.startsWith('switch:')) {
    const name = info.menuItemId.slice('switch:'.length);
    // reuse existing profile-apply logic
    applyProfileByName(name);
  }
});

contexts: ['action'] scopes an additional right-click on the toolbar icon itself — same menu, from the icon.

Additive, not overlapping

Notes

  • Adds one new permission (contextMenus). Chrome shows this on update; the copy in the permission dialog is minimal.
  • MV3-compatible; contextMenus API works from a service worker with the chrome.runtime.onInstalled bootstrap pattern shown above.
  • Doesn't require polling — chrome.storage.onChanged rebuilds the menu when the profile list changes.

Thanks for the great work on Extensity!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions