开发者

How to keep Google Chrome Extension popup open?

If I open my extension popup then I open another window or tab following the popup does not stay open if I ret开发者_如何学Gourn to it.

Is there a way to force it so the popup stays open?


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.


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.


In an answer to a FAQ here: https://developer.chrome.com/docs/extensions/mv3/faq/#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.


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


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.


Best way to workaround this is to :

  • Right-Click inside the popup
  • Click: Inspect

Or just press CTRL+Shift+I

A new window will open with the Developer Tools... just keep that window open and the popup will never close.


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜