How to keep Google Chrome Extension popup open?

前端 未结 7 1891
情话喂你
情话喂你 2020-11-27 21:15

If I open my extension popup then I open another window or tab following the popup does not stay open if I return to it.

Is there a way to force it so the popup stay

相关标签:
7条回答
  • 2020-11-27 21:49

    In an answer to a FAQ here: http://developer.chrome.com/extensions/faq.html#faq-persist-popups

    Popups automatically close when the user focuses on some portion of the browser outside of the popup. There is no way to keep the popup open after the user has clicked away.

    0 讨论(0)
  • 2020-11-27 21:54

    As a user, you currently cannot force the the popup to stay open. That is a UI decision the UI team made. If you want to want to force a setup, you can have other way to show this by changing the popup icon, open a new tab when it requests, or new popup view for registration.

    As a developer, inspect the popup, and it will stay open.

    0 讨论(0)
  • 2020-11-27 21:59

    This answer to How do I prevent Chrome developer tools from closing when the current browser window closes? what very helpful in my case:


    Not a perfect solution, but you can add breakpoints on the events Window.close and unload by turning on the checkboxes at:

    Developer tools -> "Sources" tab -> Event Listener Breakpoints -> Window -> close
    

    And

    Event Listener Breakpoints -> Load -> unload
    

    Try to mark both and see which one works best for you

    0 讨论(0)
  • 2020-11-27 22:07

    You cannot stop the Chrome pop-up from closing, unless you're in developer mode. You could consider this alternative, though:

    Launching a normal pop-up instead:

    In your popup.html file, load a Javascript file that runs this:

    var popupWindow = window.open(
        chrome.extension.getURL("normal_popup.html"),
        "exampleName",
        "width=400,height=400"
    );
    window.close(); // close the Chrome extension pop-up
    

    This will open the file normal_popup.html in your extension in a normal pop-up window, which won't close when it loses focus. Because the name parameter is the same, the pop-up window will get reused if the user launches popup.html again.

    0 讨论(0)
  • 2020-11-27 22:07

    If you enable panels at "chrome://flags/#enable-panels" you can use something like:

    chrome.windows.create({
        url:"popup.html",
        type:"panel",
        width:300,
        height:200
    });
    

    to open a panel window instead which will stay on top all the time as long as you don't move it from the bottom of the screen.

    0 讨论(0)
  • 2020-11-27 22:10

    As others have said, this is a deliberate limitation of popup UI.

    Instead, you could inject some HTML into the page which loads the content you want in your popup into an element which hovers over the existing page. You will have to implement the close functionality yourself, but it will persist.

    Have a look at e.g. how keyframes.app has done it: https://github.com/mitchas/Keyframes.app/blob/master/Keyframes.app%20(Extension)/src/inject/ui.js

    0 讨论(0)
提交回复
热议问题