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?

Xan
  • 74,770
  • 16
  • 179
  • 206
jprim
  • 1,293
  • 2
  • 16
  • 21
  • if there isn't, i'm kind of glad – Jason Nov 10 '10 at 17:03
  • It is for a setup wizard where oauth windows open. If it stays open, it is a much better experience than putting it on a full page. – jprim Nov 10 '10 at 17:10
  • have you tried doing it on the options page instead? also, you may want to dig into the chromed bird twitter extension to see how they do it: https://chrome.google.com/extensions/detail/encaiiljifbdbjlphpgpiimidegddhic – Jason Nov 10 '10 at 17:56
  • Hi Jason, yes but I want it to appear in the popup. Chromed bird does not keep the popup open when coming back from another tab or window. Where do you see this? – jprim Nov 10 '10 at 20:22

9 Answers9

49

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.

Mohamed Mansour
  • 39,445
  • 10
  • 116
  • 90
  • 7
    This isn't an answer to this question, even if it's the official docs. For example the pop-up does stay open when it's being inspected, so that's one horrible answer but actually an answer to this question. – irth Nov 26 '14 at 07:41
  • 3
    8 years later... this is a horrible design IMO. I have several extension windows which are rendered USELESS because I would need to copy-paste multiple pieces of data into them in order to get them to work. That's impossible to do without losing focus and having the window close. Bad times. – David Dombrowsky Aug 06 '21 at 03:30
  • 2
    Even if you inspect the popup, it will close if you refresh any tab – sdfsdf Jun 17 '22 at 21:37
16

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.

Flimm
  • 136,138
  • 45
  • 251
  • 267
  • 3
    The only problem with this solution is that the window won't stay on top when it loses focus. – Xan Jun 01 '15 at 09:41
12

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.

lipeiran
  • 526
  • 13
  • 33
Komal Waseem
  • 1,089
  • 3
  • 17
  • 24
5

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

GratefulGuest
  • 777
  • 7
  • 15
  • 2
    Here's a neat react boilerplate to accomplish a similar type of injection https://github.com/satendra02/react-chrome-extension – oflisback Sep 05 '19 at 07:54
3

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.

  • 2
    This flag ceased to exist starting with version 54. http://www.ghacks.net/2016/10/19/google-removes-panel-support-from-chrome/ – Daniel F Mar 01 '17 at 14:31
  • @DanielF It works right now ! :D With my 113.0.5672.63 official Chrome . Or i misunderstood Your comment. So if You don't want to use devTools You can also use this code: chrome.windows.create( {url: 'popup/popup.html',type: 'panel',width: 850,height: 800,top: 0,left: 0} ) where You set starting constraints of Your window, It is as full waponized as Your popup. It is also not binded with Your tab so You can even call that fnction from popup and also trigger it from popups event. – Bujaq May 06 '23 at 19:26
1

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

Community
  • 1
  • 1
Derlin
  • 9,572
  • 2
  • 32
  • 53
1

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.

Besworks
  • 4,123
  • 1
  • 18
  • 34
  • 4
    doesn't work. If you click a new tab, the popup closes. – Rokit Nov 15 '20 at 05:42
  • 1
    Using `CTRL+Shift+I` won't work as expected, the dev tools that open via this shortcut will be for the current tab, not the popup. – Besworks Jun 06 '22 at 20:44
1

One option is open a new tab with this url,

chrome-extension://<extension-id>/popup.html

where <extension-id is the id of the extension. You can find it in the extension manager.

It keeps open for any reason. It also output the console.log in the background script.

One drawback: because the "tab" popup is always opened, you can see the codes work from start to end. However, the "real" popup is closed whenever you have some event in other places of the browser. When it closes, the codes in the popup.js terminate immediately! That's why you see there are different console.log in the "tab" and the "real". Use it with caution!

Anh-Thi DINH
  • 1,845
  • 1
  • 23
  • 17
0

As of Chrome 114 one alternative would be the SidePanel API:

https://developer.chrome.com/docs/extensions/reference/sidePanel/#type-PanelBehavior

This would open your UI in the side panel and remain visible across interactions and tabs.

Kong
  • 8,792
  • 15
  • 68
  • 98