-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
[Feature] Support browser zoom #2497
Comments
I think this is doable today with setting the device pixel ratio. But its not a great api. We should match the buttons you get in a browser. I think something like Chromium will remember the zoom for an origin. Is this important behavior? If so, we'd need to tap into the real browser zoom instead of just device pixel ratio. |
(This comment is related to the bug originally reported here: #2768) I've been doing some digging into the issue of Playwright clicks not happening correctly when page zoom is not 100%. Indeed, if I patch Playwright's server/input.ts
become:
The click action then works as expected. (My full patch adds a EDIT: devicePixelRatio is an unreliable value for zoom. I've switched to getting zoom factor via extension call |
Very desirable. Adding to research, this attempt isn't able to emulate zoom either: await page.keyboard.down('Control');
for (let i = 0; i < 7; i++) {
await page.keyboard.press('+');
}
await page.keyboard.up('Control'); |
Would love this feature as I am sometimes on a monitor with a low resolution |
I am waiting for this to work. Any news on when zoom will be handled correct by click and other operations? |
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This would also enable testing of high resolution displays, as the browser zoom is equivalent to display scaling. So this would be very much appreciated. |
As a point, the accessibility requirement is to zoom TEXT to 200%, not the full layout, which would be equivalent to resize the width to 50% Currently chrome doesn't support text scaling, but firefox and safari does, so probably would be nice if emulateMedia would support this in those browsers Also, this text scaling can be configured in OS level, like "prefers-reduced-motion" or light/dark themes, which can be emulated with playwright, so maybe there is a way there |
any info on how to perform chromezoomusinf playwright ? |
Any updates? |
+1 |
I found a workaround to achieve setting native zoom level in Chromium (and not through the CSS You can achieve it by browsing to zoom_level = "1.25"
driver.goto("chrome://settings")
driver.evaluate(f"chrome.settingsPrivate.setDefaultZoom({zoom_level});") Hope this helps (: |
@jpjagt Sadly, using Playwright, |
I experienced the same issue and asked ChatGPT for advice. They recommended the following solution: from playwright.sync_api import sync_playwright
def setup_edge_browser(zoom_level: float):
# Start Playwright and launch Microsoft Edge browser in headless mode
with sync_playwright() as p:
browser = p.chromium.launch(channel="msedge", headless=True)
context = browser.new_context()
# Setting the viewport to simulate zoom by scaling the dimensions
viewport_width = context.viewport['width']
viewport_height = context.viewport['height']
context.set_viewport_size(width=int(viewport_width / zoom_level), height=int(viewport_height / zoom_level))
# Now you can use context.new_page() to open new pages with the updated viewport, simulating the zoom effect
# ...
# Don't forget to close the browser
browser.close()
# Example usage: set up Edge with a zoom level of 90%
setup_edge_browser(zoom_level=0.9) It resolved my issue, and I hope it can help you as well. |
Would love to be able to do this, combined with |
(Logging a feature request – please vote if your scenario needs it and help us prioritize!)
To support accessibility requirements, web developers often need to test their application on higher zoom levels like 200%. Relevant WCAG doc: "Ensuring that there is no loss of content or functionality when the text resizes and text containers do not change their width".
To support this, the Playwright API needs to be able to emulate a higher zoom level, preferably at the browser context level.
The text was updated successfully, but these errors were encountered: