Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] args options ignored when launching firefox #910

Closed
hdorgeval opened this issue Feb 9, 2020 · 4 comments
Closed

[BUG] args options ignored when launching firefox #910

hdorgeval opened this issue Feb 9, 2020 · 4 comments

Comments

@hdorgeval
Copy link
Contributor

Context:

  • Playwright Version: [0.10.0]
  • Operating System: [Mac OS 10.15.3]
  • Extra: [any specific details about your environment]

Code Snippet

    // eslint-disable-next-line @typescript-eslint/no-var-requires
    const playwright = require('playwright');

    // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
    const browser = await playwright['firefox'].launch({
      headless: false,
      args: ['-height 666', '-width 888'],
    });
    const context = await browser.newContext();
    const page = await context.newPage();

    // eslint-disable-next-line no-undef
    const browserHeight = await page.evaluate(() => window.outerHeight);
    // eslint-disable-next-line no-undef
    const browserWidth = await page.evaluate(() => window.outerWidth);
    // eslint-disable-next-line no-console
    console.log(`expected browser height: 666; current browser height: ${browserHeight}`);
    // eslint-disable-next-line no-console
    console.log(`expected browser width: 888; current browser width: ${browserWidth}`);

    await browser.close();

Describe the bug

I expect that browser width and height to be the ones set in the options arg passed to the launch() method.

Works for chromium with the options set as

const options: LaunchOptions = {
      headless: false,
      args: ['--window-size=888,666'],
};
@pavelfeldman
Copy link
Member

The following snippet worked for me:

const browser = await playwright['firefox'].launch({
      headless: false,
     // either pass as a=b or 'a', 'b', no spaces inside
      args: ['-height=666', '-width=888'],
    });
// you want to opt-out from the default 800/600 viewport.
const context = await browser.newContext({ viewport: null });
const page = await context.newPage();

Note that the actual outer height is going to be higher than what you specify due to the toolbar. Please feel free to reopen if that did not address your issue.

@hdorgeval
Copy link
Contributor Author

@pavelfeldman : thank you very much for your fast answer 👍 It works for me also thanks to your snippet. Is there a similar snippet to be able to resize the webkit browser window?

@pavelfeldman
Copy link
Member

Resizing via page.setViewport (page.setViewportSize in 0.11+) should change the size of both Firefox and WebKit in headful mode. It would not work for Chromium though - Chromium uses lower level emulation capabilities for resize, so you still need the args.

Do you mind sharing more about your use case?

@hdorgeval
Copy link
Contributor Author

Hi @pavelfeldman , As you may notice, I am currently developing a Fluent API around Playwright.

In this API, I want to ensure that the browser window size is as near as possible to the physical size of the emulated device. For example, if I want to run a test by emulating an iPhone, I do not want to have a 'big' browser window with a 'small' active size in it (the viewport).

When I open a browser in the real life, the viewport size seems to fit exactly the browser window size, so in headfull scenarios the viewport should always be set by default to null in Playwright.

So in my opinion, viewport size should always be correlated to the browser window size and vice versa: setting up the viewport size, regardless of the opened browser window size, is only a way to overcome some display hardware limitation on CI environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants