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] device* media queries are not triggered with viewport emulation #1291

Closed
tomgallagher opened this issue Mar 9, 2020 · 6 comments
Closed
Labels
upstream This is a bug in something playwright depends on, like a browser.

Comments

@tomgallagher
Copy link

If you want to test sites with media queries, setting the viewport is not enough.

I've found that I also need to change the window size to accommodate media queries and accurately reflect what a user would see with certain screen sizes

await chromium.launch({args: [ --window-size=${someWidth},${someHeight}]});

That's easy enough thanks to your helpful device dictionary.

Am I missing something here?

Is it possible to change the default window size on all browser instances launched by Playwright?

Failing that, are there comparable flags for Firefox and Webkit?

@aslushnikov
Copy link
Collaborator

If you want to test sites with media queries, setting the viewport is not enough.

@tomgallagher to the best of my knowledge, viewport emulation should be enough 🤔 can you give an example?

@aslushnikov aslushnikov changed the title Media Queries, Window Sizes and Viewports [Question] [Question] Media Queries, Window Sizes and Viewports Mar 9, 2020
@tomgallagher
Copy link
Author

Hi, thanks for getting back

By way of an example, go to this site

There's a sub-header banner that has the following media rule

@media screen and (max-width: 767px) {
    .installButtonSegment {
        display: none;
        width: 100vw;
    }
}

It does not show in retrieved screenshot when the viewport is set and browser context confirmed as:

viewport: {
      width: 1366,
      height: 768,
      deviceScaleFactor: 1,
      isMobile: false
}

But it shows when launching the browser with:

chromium.launch({args: ['--no-sandbox', --window-size=1366,768] });
`

aslushnikov added a commit to aslushnikov/playwright that referenced this issue Mar 9, 2020
@aslushnikov aslushnikov changed the title [Question] Media Queries, Window Sizes and Viewports [Bug] device* media queries are not triggered with viewport emulation Mar 9, 2020
@aslushnikov
Copy link
Collaborator

@tomgallagher thank you for the great repro! This is fixed on Chromium now; the viewport now emulates screen sizes as well so screenshots are consistent.

We'll fix this in other browsers as well!

@tomgallagher
Copy link
Author

Good stuff! 😄

@aslushnikov aslushnikov added bug upstream This is a bug in something playwright depends on, like a browser. labels Mar 10, 2020
@dgozman
Copy link
Contributor

dgozman commented Apr 1, 2020

#1565 fixed this for Firefox.

@dgozman
Copy link
Contributor

dgozman commented Apr 1, 2020

I believe this is now fixed in all browsers 🎉

@dgozman dgozman closed this as completed Apr 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
upstream This is a bug in something playwright depends on, like a browser.
Projects
None yet
Development

No branches or pull requests

3 participants