Reputation: 96
I'm creating a Firefox webextension with a popup that needs to be resized programmatically depending on the content after the page is rendered.
I have the following code using browser.windows.create to create a popup window:
browser.windows.create({
type : 'popup',
url : `page.html`,
});
Inside page.html
, after it's rendered, I am trying to resize using:
window.resizeTo(<width>,<height>);
However this does not do anything. From window.resizeTo doc, it footnote says that:
Note: It's not possible to resize a window or tab that wasn’t created by window.open(). It's also not possible to resize when the window has multiple tabs.
I'm guessing this is due to the first reason, since the window was not created using window.open()
, it is not resizable. Is there an alternative?
I'm trying to avoid using browser.windows.update, it adds complexity since I have to send a message with the dimensions. Is there anything I'm doing wrong or any suggestions how to handle this?
Upvotes: 0
Views: 188
Reputation: 73686
page.html
is an extension page (just like browser_action popup or an options page) so it has access to browser
and you can call browser.windows.update
directly just like you call window.resizeTo
now, no need for messaging.
browser.windows.update(browser.windows.WINDOW_ID_CURRENT, {
width: 500,
height: 500,
});
Upvotes: 1