summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crocoite/behavior.py20
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 """