summaryrefslogtreecommitdiff
path: root/crocoite/behavior.py
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2019-03-21 15:04:32 +0100
committerLars-Dominik Braun <lars@6xq.net>2019-03-21 15:04:32 +0100
commit4643112b8f5f208f360e2e7c9431931b6526131e (patch)
tree2f4b00bc53eaef7c343f65796f49e02af0839c93 /crocoite/behavior.py
parent38078be63466f5cd78ad97963502e47b8435c07f (diff)
downloadcrocoite-4643112b8f5f208f360e2e7c9431931b6526131e.tar.gz
crocoite-4643112b8f5f208f360e2e7c9431931b6526131e.tar.bz2
crocoite-4643112b8f5f208f360e2e7c9431931b6526131e.zip
behavior: Test Screenshot
Diffstat (limited to 'crocoite/behavior.py')
-rw-r--r--crocoite/behavior.py17
1 files changed, 11 insertions, 6 deletions
diff --git a/crocoite/behavior.py b/crocoite/behavior.py
index 02fe2ea..dca9ea0 100644
--- a/crocoite/behavior.py
+++ b/crocoite/behavior.py
@@ -281,6 +281,10 @@ 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
@@ -291,16 +295,14 @@ class Screenshot (Behavior):
self.logger.error ('frame without url', tree=tree)
url = None
- # 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
+
metrics = await tab.Page.getLayoutMetrics ()
contentSize = metrics['contentSize']
- width = min (contentSize['width'], maxDim)
+ width = min (contentSize['width'], self.maxDim)
# we’re ignoring horizontal scroll intentionally. Most horizontal
# layouts use JavaScript scrolling and don’t extend the viewport.
- for yoff in range (0, contentSize['height'], maxDim):
- height = min (contentSize['height'] - yoff, maxDim)
+ for yoff in range (0, contentSize['height'], self.maxDim):
+ height = min (contentSize['height'] - yoff, self.maxDim)
clip = {'x': 0, 'y': yoff, 'width': width, 'height': height, 'scale': 1}
ret = await tab.Page.captureScreenshot (format='png', clip=clip)
data = b64decode (ret['data'])
@@ -323,6 +325,9 @@ class ExtractLinksEvent:
def __init__ (self, links):
self.links = links
+ def __repr__ (self):
+ return f'<ExtractLinksEvent {self.links!r}>'
+
class ExtractLinks (Behavior):
"""
Extract links from a page using JavaScript