diff options
author | Lars-Dominik Braun <lars@6xq.net> | 2019-06-18 17:18:31 +0200 |
---|---|---|
committer | Lars-Dominik Braun <lars@6xq.net> | 2019-06-18 17:19:51 +0200 |
commit | 2e3385203f89a2eda1798f9bc8e3ad573aec372c (patch) | |
tree | 554de59696bbf4139e3a2668eca5edc05fbb991a /crocoite | |
parent | 9c1de8ebb7b9e00bc6afc9f2ed2978a003d9abd8 (diff) | |
download | crocoite-2e3385203f89a2eda1798f9bc8e3ad573aec372c.tar.gz crocoite-2e3385203f89a2eda1798f9bc8e3ad573aec372c.tar.bz2 crocoite-2e3385203f89a2eda1798f9bc8e3ad573aec372c.zip |
behavior: Fix screenshots
Chrome’s behavior wrt screeshots changed in some version, so now
artificially extending the viewport via device metrics is required.
Diffstat (limited to 'crocoite')
-rw-r--r-- | crocoite/behavior.py | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/crocoite/behavior.py b/crocoite/behavior.py index d079603..bdae5f9 100644 --- a/crocoite/behavior.py +++ b/crocoite/behavior.py @@ -281,13 +281,26 @@ class Screenshot (Behavior): name = 'screenshot' - # see https://github.com/GoogleChrome/puppeteer/blob/230be28b067b521f0577206899db01f0ca7fc0d2/examples/screenshots-longpage.js # Hardcoded max texture size of 16,384 (crbug.com/770769) maxDim = 16*1024 async def onfinish (self): tab = self.loader.tab + # this is required to make the browser render more than just the small + # actual viewport (i.e. entire page). see + # https://github.com/GoogleChrome/puppeteer/blob/45873ea737b4ebe4fa7d6f46256b2ea19ce18aa7/lib/Page.js#L805 + metrics = await tab.Page.getLayoutMetrics () + contentSize = metrics['contentSize'] + + await tab.Emulation.setDeviceMetricsOverride ( + width=0, height=0, deviceScaleFactor=0, mobile=False, + viewport={'x': 0, + 'y': 0, + 'width': contentSize['width'], + 'height': contentSize['height'], + 'scale': 1}) + tree = await tab.Page.getFrameTree () try: url = URL (tree['frameTree']['frame']['url']).with_fragment (None) @@ -295,9 +308,6 @@ class Screenshot (Behavior): self.logger.error ('frame without url', tree=tree) url = None - - metrics = await tab.Page.getLayoutMetrics () - contentSize = metrics['contentSize'] width = min (contentSize['width'], self.maxDim) # we’re ignoring horizontal scroll intentionally. Most horizontal # layouts use JavaScript scrolling and don’t extend the viewport. @@ -308,6 +318,8 @@ class Screenshot (Behavior): data = b64decode (ret['data']) yield ScreenshotEvent (url, yoff, data) + await tab.Emulation.clearDeviceMetricsOverride () + class Click (JsOnload): """ Generic link clicking """ |