fix(chrome): clip diagram snapshots against the resized layout - #57
Merged
Conversation
Two ways a diagram snapshot could still come out cut: Emulation.setDeviceMetricsOverride is applied asynchronously, so measuring the diagram right after resizing the viewport could read the pre-resize layout. Text above the diagram re-wraps when the viewport width changes, moving the diagram up or down, and the clip then landed off it: surrounding page text pulled in at one edge, part of the diagram lost at the other. Wait for window.innerWidth to report the new width before measuring. A diagram past the viewport cap relied on CaptureBeyondViewport, and past roughly 16384 px the browser stops growing its capture surface and returns an image cut off at the right and bottom. Raise the viewport cap to 8192 CSS px and lower the device scale when 2x would exceed that surface limit, so an outsized diagram is captured whole (softer) instead of chopped.
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.
Follow-up to #56: large diagrams could still come out with the bottom cut, and with part of the surrounding page text baked into the top of the image.
Two causes
Clip measured against a stale layout.
Emulation.setDeviceMetricsOverrideis applied asynchronously, so measuring the diagram straight after resizing the viewport could read the pre-resize layout. Text above the diagram re-wraps when the viewport width changes, moving the diagram up or down; the clip then landed off it, pulling in surrounding page text at one edge and losing part of the diagram at the other.measureAfterResizenow waits forwindow.innerWidthto report the new width before measuring.Capture surface limit. Anything past the 4096 CSS px viewport cap relied on
CaptureBeyondViewport, and past roughly 16384 px the browser stops growing its capture surface and returns an image cut off at the right and bottom. The viewport cap goes to 8192 CSS px, andcaptureScalelowers the device scale when 2x would exceed the surface limit, so an outsized diagram is captured whole (softer) rather than chopped.Checks
Node 200) present — was 194x35710, past the surface limitNode 40present at the right edge-flattenand docxNew
TestCaptureScale;go test ./...green.