Skip to content

Commit

Permalink
set initlal viewport for interactive shots (#128)
Browse files Browse the repository at this point in the history
* set initlal viewport for interactive shots
  • Loading branch information
mhalle committed Feb 5, 2024
1 parent c1ade5e commit a34a84a
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions shot_scraper/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,8 @@ def shot(
if interactive or devtools:
use_existing_page = True
page = context.new_page()
if width or height:
page.set_viewport_size(_get_viewport(width, height))
page.goto(url)
context = page
click.echo(
Expand Down Expand Up @@ -1051,6 +1053,14 @@ def _check_and_absolutize(filepath):
# On Windows, instantiating a Path object on `http://` or `https://` will raise an exception
return False

def _get_viewport(width, height):
if width or height:
return {
"width": width or 1280,
"height": height or 720,
}
else:
return {}

def take_shot(
context_or_page,
Expand Down Expand Up @@ -1125,16 +1135,11 @@ def on_response(response):
if log_console:
page.on("console", console_log)

viewport = {}
full_page = True
if shot.get("width") or shot.get("height"):
viewport = {
"width": shot.get("width") or 1280,
"height": shot.get("height") or 720,
}
viewport = _get_viewport(shot.get("width"), shot.get("height"))
if viewport:
page.set_viewport_size(viewport)
if shot.get("height"):
full_page = False

full_page = not shot.get("height")

if not use_existing_page:
# Load page and check for errors
Expand Down

0 comments on commit a34a84a

Please sign in to comment.