From 9cff3074e52b91c49298f80fd3e73d77f1f1c7dd Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Wed, 22 Nov 2017 09:37:19 +0100 Subject: Emulate different screen sizes Causes the browser to load CSS assets and srcset, for example. --- crocoite/cli.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'crocoite') diff --git a/crocoite/cli.py b/crocoite/cli.py index 9a22d24..f9e0fd2 100644 --- a/crocoite/cli.py +++ b/crocoite/cli.py @@ -321,6 +321,29 @@ def main (): 'X-Chrome-Viewport': viewport}) writer.write_record (record) + def emulateScreenMetrics (tab): + """ + Emulate different screen sizes, causing the site to fetch assets (img + srcset and css, for example) for different screen resolutions. + """ + sizes = [ + {'width': 1920, 'height': 1080, 'deviceScaleFactor': 1.5, 'mobile': False}, + {'width': 1920, 'height': 1080, 'deviceScaleFactor': 2, 'mobile': False}, + # very dense display + {'width': 1920, 'height': 1080, 'deviceScaleFactor': 4, 'mobile': False}, + # just a few samples: + # 1st gen iPhone (portrait mode) + {'width': 320, 'height': 480, 'deviceScaleFactor': 1.8, 'mobile': True}, + # 6th gen iPhone (portrait mode) + {'width': 750, 'height': 1334, 'deviceScaleFactor': 326/90, 'mobile': True}, + ] + for s in sizes: + tab.Emulation.setDeviceMetricsOverride (**s) + tab.wait (1) + # wait until assets finished loading + while len (requests) != 0: + tab.wait (1) + logging.basicConfig (level=logging.DEBUG) parser = argparse.ArgumentParser(description='Save website to WARC using Google Chrome.') @@ -415,6 +438,8 @@ def main (): while len (requests) != 0: tab.wait (1) + emulateScreenMetrics (tab) + tab.Page.stopLoading () tab.Network.disable () tab.Page.disable () -- cgit v1.2.3