Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hello wonderful people!
I noticed that pages in Termium looked really tiny on my mac's retina display. After digging into it a bit, I found that the terminal reports its size in physical pixels, and Termium is using those dimensions directly as the browser's CSS viewport. So the browser was basically laying out pages for a screen twice as wide as it should be, making everything look half the size and there was no way to work around it.
I thought the simplest fix would be to let it know about the display scale, so I added a
--scaleoption that accepts values from 1 to 4 and defaults to 1.On a Retina display, you'd typically use
--scale 2.Getting the viewport right turned out to be only part of the job, though. Mouse clicks and wheel input also need to account for the scale, and Chromium's screenshot capture session needs the same viewport settings. Otherwise, the screenshots end up with the wrong dimensions. I updated those parts too, while keeping the default behaviour unchanged and making sure older clients still work.
I went with integer scales mainly to avoid changing behaviour outside the scope of this fix. The client already accepts only frames that exactly match the requested size, and since screenshots always span whole CSS pixels, rounding the viewport down to a multiple of an integer scale keeps that match exact.
Supporting fractional scales would have meant reworking how frames are accepted and drawn, which felt like a separate change.
Since the capture session now sends
Emulation.setDeviceMetricsOverridebefore taking a screenshot when the scale isn't 1, I also made the existing retry for a briefly inactive compositor recognise the "Not attached to an active page" error from either command, not just fromPage.captureScreenshot.I've run lint, typecheck, the server unit tests, Go race tests, and the integration suite locally on my Apple Silicon and they all pass. I also added a test using a real Chromium instance with a 1601×1001 viewport to check the CSS dimensions,
devicePixelRatio, screenshot size, and mouse and wheel input.Removing either the capture-session override or the wheel conversion makes the test fail, which seems like a good sign that those cases are covered.