Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
mohamedkhallouq
GitHub Repository: mohamedkhallouq/content
Path: blob/main/files/en-us/mozilla/add-ons/webextensions/api/pageaction/setpopup/index.md
6567 views
---
title: pageAction.setPopup() slug: Mozilla/Add-ons/WebExtensions/API/pageAction/setPopup page-type: webextension-api-function tags: - API - Add-ons - Extensions - Method - Non-standard - Reference - WebExtensions - pageAction - setPopup browser-compat: webextensions.api.pageAction.setPopup
---

{{AddonSidebar()}}

Sets the HTML document to be opened as a popup when the user clicks on the page action's icon.

Syntax

browser.pageAction.setPopup( details // object )

Parameters

  • details

    • : object.

      • tabId

        • : integer. The ID of the tab for which you want to set the popup.

      • popup

        • : string or null. URL to the HTML file to show in a popup.

          If an empty string ("") is passed here, the popup is disabled, and the extension will receive {{WebExtAPIRef("pageAction.onClicked")}} events.

          If null is passed here, the popup is reset to the popup that was specified in the page_action manifest key.

Browser compatibility

{{Compat}}

Examples

Listen for {{WebExtAPIRef("tabs.onUpdated")}} events, and switch the popup if the loading status changes:

browser.tabs.onUpdated.addListener((tabId, changeInfo, tabInfo) => { if (changeInfo.status) { browser.pageAction.show(tabId); if (changeInfo.status === "loading") { browser.pageAction.setPopup({ tabId, popup: "/popup/loading.html" }); } else { browser.pageAction.setPopup({ tabId, popup: "/popup/complete.html" }); } } });

{{WebExtExamples}}

Note: This API is based on Chromium's chrome.pageAction API. This documentation is derived from page_action.json in the Chromium code.