Summary of How to create a window that is like default popup?

  • stackoverflow.com
  • Article
  • Summarized Content

    Here is a meta title, meta description, and a detailed summary with headings and bullet points:

    Creating a Chrome Extension Popup Window

    The user has a browser action button in their Chrome extension and wants to open a custom popup window when the button is clicked. The default behavior when setting default_popup in the manifest.json file is to show a basic popup like this:

    default_popup

    Handling the Browser Action Click Event

    To open a custom window, the extension listens for the chrome.browserAction.onClicked event and decides which HTML file to open based on some computation:

    chrome.browserAction.onClicked.addListener(function(tab) {
        if(...)
            url = "1.html";
        else
            url = "2.html";
        chrome.windows.create({url: url, type: "popup"});
    });

    Issue with Custom Popup Window

    While this code opens a new popup window, the created window has borders and is not positioned at the location of the browser action button, unlike the default popup provided by default_popup.

    Desired Behavior for Custom Chrome Popup

    • Look and feel should match the default browser action popup
    • Window should open at the location of the browser action button
    • No borders or extra UI elements around the window

    Potential Solutions

    • Use the default_popup setting and find a way to catch the event before the default popup runs, then redirect to the desired HTML file.
    • Always show one popup (e.g., 1.html) first, and then navigate to the other HTML file (2.html) if needed, assuming both popups have the same size.
    • Investigate if there are any undocumented Chrome extension APIs or workarounds to create a window with the desired look and behavior.

    Difficulty in Replicating Default Popup

    Achieving the exact same look and feel as the default browser action popup can be challenging due to the limited customization options provided by the Chrome extension APIs. However, the solutions mentioned above can help create a custom popup window that closely resembles the default behavior.

    Ask anything...

    Sign Up Free to ask questions about anything you want to learn.