Getting windowType of addon popup

I need to detect in which window opened popup page: in regular popup, in sidebar or in menu as iframe.

How can I do it? browser.windows.getCurrent() return regular window. Not addon.

thank you.

That’s a good question. The browser.windows.getCurrent() will return the parent window as the pop-up doesn’t have its own window, that’s why the window.type is normal, not popup.

But I know how to detect if script runs in aniframe:

const isInIframe = () => { try { return window.self !== window.top } catch (e) { return true } };
1 Like

Nice solution, thanks.

BTW, very much related is the question whether an add-on is in the overflow menu. (Do you mean that with “in menu as iframe”?)
Because if you use some page in your add-on in an iframe, you likely know this. :smile:

The much more low-tech approach is to add a query param depending on the view and reading that.

1 Like

@rugkx yes, “in menu as iframe” = “in the overflow menu”.

@freaktechnik for panel view it works, because I can setup it in manifest.json. But for “overflow menu” - not :confused: And CSS media conditions is also bad solution. Anytime in future size of overflow menu can be changed.

to juraj.masiar: I meant “in the overflow menu”. But to detect iframes I use window != window.parent.

But if you’re concerned about it breaking when the width of the overflow menu changes, how would that not break any other solution you’d create? Either your solution is responsive enough to handle it, in which case media conditions are fine, or your extension isn’t fit to handle it either way.

I expect some command via API, which has, at least, back compatibility after changes.