How to keep Google Chrome Extension popup open?

2019-01-06 20:55发布

问题:

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 stays open?

回答1:

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.



回答2:

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.



回答3:

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.



回答4:

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.



回答5:

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



回答6:

Best way to workaround this is to:
- Right click inside the addon popup
- inspect (or CTRK+Shift+I)

a new window will open with the inspect... just keep that window and addon popup will never close