simonw / shot-scraper

A command-line utility for taking automated screenshots of websites
https://shot-scraper.datasette.io
Apache License 2.0
1.67k stars 73 forks source link

add a device option to specify device name for convenience #129

Closed nohzafk closed 8 months ago

nohzafk commented 11 months ago

Device name is a built-in name according to Playwright devices

For example, specify -d "iPhone 14 Prox Max" will update context_args with

{'default_browser_type': 'webkit',
 'device_scale_factor': 3,
 'has_touch': True,
 'is_mobile': True,
 'user_agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 16_0 like Mac OS X) '
               'AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.4 '
               'Mobile/15E148 Safari/604.1',
 'viewport': {'height': 740, 'width': 430}}

Specifying device name will override width, height, and retina options.

Using the device name to take screenshots on Apple devices is more convenient than manually specifying the width, height, and device_scale_factor.

simonw commented 10 months ago

This is a neat idea for a feature.

nohzafk commented 10 months ago

I closed the pull request to test the feature. Also add a device-ratio option to allow capturing only a portion of the webpage, i use it to create a screenshot of a given URL to display in my blog posts. For example, --device 'iPad Mini' --device-ratio 3:1