Skip to content

Commit a34a84a

Browse files
authored
set initlal viewport for interactive shots (#128)
* set initlal viewport for interactive shots
1 parent c1ade5e commit a34a84a

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

shot_scraper/cli.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,8 @@ def shot(
349349
if interactive or devtools:
350350
use_existing_page = True
351351
page = context.new_page()
352+
if width or height:
353+
page.set_viewport_size(_get_viewport(width, height))
352354
page.goto(url)
353355
context = page
354356
click.echo(
@@ -1051,6 +1053,14 @@ def _check_and_absolutize(filepath):
10511053
# On Windows, instantiating a Path object on `http://` or `https://` will raise an exception
10521054
return False
10531055

1056+
def _get_viewport(width, height):
1057+
if width or height:
1058+
return {
1059+
"width": width or 1280,
1060+
"height": height or 720,
1061+
}
1062+
else:
1063+
return {}
10541064

10551065
def take_shot(
10561066
context_or_page,
@@ -1125,16 +1135,11 @@ def on_response(response):
11251135
if log_console:
11261136
page.on("console", console_log)
11271137

1128-
viewport = {}
1129-
full_page = True
1130-
if shot.get("width") or shot.get("height"):
1131-
viewport = {
1132-
"width": shot.get("width") or 1280,
1133-
"height": shot.get("height") or 720,
1134-
}
1138+
viewport = _get_viewport(shot.get("width"), shot.get("height"))
1139+
if viewport:
11351140
page.set_viewport_size(viewport)
1136-
if shot.get("height"):
1137-
full_page = False
1141+
1142+
full_page = not shot.get("height")
11381143

11391144
if not use_existing_page:
11401145
# Load page and check for errors

0 commit comments

Comments
 (0)