Open Chrome Extension Popup Programmatically
In this article
To programmatically open a Chrome extension's popup, you can call chrome.action.openPopup() (for Manifest V3) or chrome.browserAction.openPopup() (for Manifest V2) from within your extension's background script or service worker. This method is only available in response to a user gesture (like a keyboard shortcut or a click on the extension's context menu), not from arbitrary timers or page scripts. This guide walks you through the exact steps, common pitfalls, and troubleshooting for both MV2 and MV3.
What You'll Need
- A Chrome extension project with a manifest file (
manifest.json) and a popup HTML file. - Basic familiarity with JavaScript and Chrome extension APIs.
- Chrome browser (the API is not available in Firefox or Safari).
Step-by-Step
- Identify your manifest version. Open your
manifest.json. If you see"manifest_version": 3, you're on MV3. If it's2, you're on MV2. The API name differs:chrome.actionfor MV3,chrome.browserActionfor MV2. - Set up a background script or service worker. In your manifest, declare a background script (MV2) or service worker (MV3). For MV3, add
"background": { "service_worker": "background.js" }. For MV2, use"background": { "scripts": ["background.js"] }. - Add the necessary permission (MV3 only). In MV3, the
actionAPI does not require a special permission, but you must ensure the popup is defined in the manifest under"action"(or"browser_action"for MV2). Example:"action": { "default_popup": "popup.html" }. - Write the code to open the popup. In your background script, call the API. For MV3:
chrome.action.openPopup(). For MV2:chrome.browserAction.openPopup(). This method returns a Promise (MV3) or accepts a callback (MV2). Example (MV3):chrome.action.openPopup().then(() => { console.log('Popup opened'); }).catch((err) => { console.error('Failed to open popup:', err); }); - Trigger the call from a user gesture. The API only works when called during a user gesture, such as:
- A keyboard shortcut (via
chrome.commands). - A click on the extension's context menu item (
chrome.contextMenus). - A click on the extension's action button (though that already opens the popup).
"commands"section to your manifest and listen in the background script. - A keyboard shortcut (via
- Test your implementation. Load the unpacked extension via
chrome://extensions(enable Developer mode), then trigger the gesture (e.g., press the shortcut). The popup should appear.
Common Mistakes
- Calling without a user gesture. The most common error: calling
openPopup()from a timer or after an async operation that loses the gesture context. The API will reject with an error like "This API can only be called in response to a user gesture." - Using the wrong API for your manifest version. Mixing
chrome.actionwith MV2 orchrome.browserActionwith MV3 will fail. Always check your manifest version. - Not defining a popup in the manifest. If you don't set
default_popup, the API has nothing to open and will throw an error. - Calling from a content script. Content scripts do not have access to
chrome.actionorchrome.browserAction. You must send a message to the background script to trigger the call. - Expecting it to work on page load. Opening the popup automatically when a page loads is not allowed; it would be intrusive and is blocked by Chrome.
Tips
- Use async/await in MV3 for cleaner code:
await chrome.action.openPopup(); - Check for errors by adding a
.catch()or try/catch to log why the popup didn't open. - For keyboard shortcuts, define a command in the manifest like:
"commands": { "open-popup": { "suggested_key": { "default": "Ctrl+Shift+Y" }, "description": "Open popup" } }and listen in the background script. - For context menus, create a menu item with
chrome.contextMenus.createand callopenPopup()inside theonClickedlistener. - If you need to open the popup from a page action (toolbar icon), note that clicking the icon already opens it; you don't need to call the API.
Troubleshooting
Popup doesn't open at all. Check the console in the background service worker (chrome://extensions → Inspect views). Look for errors like "This API can only be called in response to a user gesture" or "Cannot read properties of undefined." Ensure you're using the correct API name for your manifest version.
Works in development but not in production. If you're using a keyboard shortcut, ensure the shortcut is not conflicting with another extension or Chrome default. Also, if you're using a context menu, ensure the menu item is created before the click.
Popup opens but is blank. Verify your popup HTML file path is correct in the manifest. Also check for JavaScript errors in the popup's own console (right-click the popup → Inspect).
Error: "Cannot access 'chrome.action'" — This usually means you're in an MV2 extension or you're trying to access it from a content script. Move the call to the background script.
Error: "This API is not available" — The API is only available in Chrome 88+ for MV3. If you're using an older Chrome, update or use MV2.
Frequently Asked Questions
Can I open the popup automatically when the extension is installed?
No. The API requires a user gesture. You cannot open it on installation or page load.
Can I open the popup from a content script?
No. Content scripts lack access to chrome.action. Send a message to the background script, which then calls openPopup() in response to the message, but note that the message must originate from a user gesture (e.g., a click on the page).
Does openPopup() work in Firefox?
No. This API is Chrome-specific. Firefox has a similar browser.browserAction.openPopup() but it's not identical and may have different restrictions.
Can I open the popup with a delay after a user gesture?
No. The gesture must be active at the moment of the call. If you use setTimeout or an asynchronous operation that takes time, the gesture is lost and the call fails.
What if I want to open the popup from a keyboard shortcut?
Define a command in the manifest and listen for it in the background script. Inside the listener, call openPopup(). That listener is considered a user gesture.
Is there a way to open the popup from a webpage (not the extension)?
No. Web pages cannot access extension APIs. Only the extension's own background script or popup can call openPopup().