Fix Viewport resizing upon page.screenshot #125
Merged
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.
Issue
Currently, Puppetteer resizes the viewport when
page.screenshot(...)
is being triggered. On modern development hardware, you barely notice it in non-headless mode, unless for example you manually throttle Chromium (await page.emulateCPUThrottling(6);
). The issue with the viewport resizing is that in HomeAssistant, some dashboards reload / redraw themselves upon resize action. Which results in a beautiful race condition upon taking the screenshot. Issues like #95 are the consequence. The resizing seems weird and unnecessary, given that the dimensions are defined already...Approach
I found a workaround on StackOverflow how to prevent the re-sizing of the viewport. It works on my machine as expected, but please verify with your own dashboard.