[Scripted Browser] issue with resizing browser window

Hi All,

I couldn’t find a similar topic, maybe it’s just me! :slight_smile:

The use case: I’ve been trying to simulate a mobile device & run a synthetic test on a website from Dublin public location.

For simplicity I’ve removed most of the script, and tried running even just the following:

  return $browser.get('https://www.google.com').then(function(){})

But it produces the following error:
failed to change window state to normal, current state is maximized

I’ve tried running setPosition(), the same error is shown. Looking through some fora, it’d seem that Chrome since certain version doesn’t allow JS to control the browser window.

Could you advise?
Thank you & best regards,

Hi, @maciej.piekos: You may find this thread helpful:

Hi @philweber,

Thank you very much. I’ve read that thread, but running in a popup seems like a workaround, I had hoped that we might have resolved the issue since then.

Windows management might get a bit tricky in this case, i.e. if my popup opens another window. We’ll see where it opens.

Thank you, nevertheless. Are you aware if there are any plans on allowing users to choose the window size / maximized?

Best regards,

I think it is a limitation with Google Chrome. Chrome does not allow JavaScript to resize the main browser window (try it here: http://resizemybrowser.com/). I am not aware of any plans to allow you to choose initial window size.

This might work, not perfect, but once window is there you can size it.

//$browser.addHeader('User-Agent', 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1');
$browser.get("https://your.real.site").then(function() {
  $browser.manage().window().setSize(480, 640);
//remove all related cookie that might affect appearance/size

Thanks @moti.ferentz :smiley: :smiley:

1 Like