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]: Method "setIsMobile" not working in Java #31510

Closed
pawel747 opened this issue Jul 1, 2024 · 3 comments
Closed

[Bug]: Method "setIsMobile" not working in Java #31510

pawel747 opened this issue Jul 1, 2024 · 3 comments

Comments

@pawel747
Copy link

pawel747 commented Jul 1, 2024

Version

1.44.0

Steps to reproduce

I have the code:
try (Playwright playwright = Playwright.create()) { Browser.NewContextOptions contextOptions = new Browser.NewContextOptions() .setIsMobile(true) .setHasTouch(true);

Based on the documentation, I understand that this code should start emulating and a window should open for the mobile version.

Expected behavior

I see a "small window" for the mobile version.

Actual behavior

I see the standard window for the desktop version.

Additional context

No response

Environment

System:
MacOS Sonoma 14.3.1 (23D60)
@mxschmitt
Copy link
Member

mxschmitt commented Jul 2, 2024

As per the documentation what isMobile is doing:

Whether the meta viewport tag is taken into account and touch events are enabled.

So this does not affect the viewport/screen size. If you want to change the viewport, you can follow this: https://playwright.dev/java/docs/emulation#devices

@pawel747
Copy link
Author

pawel747 commented Jul 3, 2024

Thanks for the answer. However, I don't understand whether anything other than resolution needs to be set. I entered the values ​​corresponding to desktop. To change the appearance to the mobile version, do I have to substitute values ​​in the viewport in some way or is it enough to set a flag?

My current code:
Browser.NewContextOptions contextOptions = new Browser.NewContextOptions() .setViewportSize(1280, 1024) .setHasTouch(true) .setIsMobile(true);

@mxschmitt
Copy link
Member

mxschmitt commented Jul 3, 2024

Looks good, in a nutshell its e.g. for an iPhone 15 Pro max the following:

"iPhone 14 Pro Max": {
"userAgent": "Mozilla/5.0 (iPhone; CPU iPhone OS 16_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.4 Mobile/15E148 Safari/604.1",
"screen": {
"width": 430,
"height": 932
},
"viewport": {
"width": 430,
"height": 740
},
"deviceScaleFactor": 3,
"isMobile": true,
"hasTouch": true,
"defaultBrowserType": "webkit"
},

So you could emulate screen, userAgent, deviceScaleRatio as well.

Probably related to microsoft/playwright-java#939 - maybe its available in junit already with the bindings.

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