I'm working on a Chrome extension and I'm looking how to find out (from the background page) if the popup page is open or not. I looked into message passing but I'm not sure if that's gonna help me at this or if there's a simpler way.
Thanks!
The syntax to open a popup is: window. open(url, name, params) : url. An URL to load into the new window.
The width and height Parameters Width and height are the only required properties for a popup window. This line in our popup script creates a popup that is 400 wide and 200 high: window. open(href, windowname, 'width=400,height=200,scrollbars=yes');
You can use the following chrome API call from your background page fetch if the popup view is open:
var views = chrome.extension.getViews({ type: "popup" });
//views => [] //popup is closed
//views => [DOMWindow] //popup is open
If it returns an empty array then your popup is not open, if it returns an array with your popups DOMWindow object, then your popup is open.
If you have multiple popups in one plugin then you could check for the existence of some global variable in the returned DOMWindow to disambiguate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With