Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for --wait-for and --timeout to pdf command #161

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/pdf.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ Options:
-j, --javascript TEXT Execute this JS prior to creating the PDF
--wait INTEGER Wait this many milliseconds before taking the
screenshot
--wait-for TEXT Wait until this JS expression returns true
--timeout INTEGER Wait this many milliseconds before failing
--media-screen Use screen rather than print styles
--landscape Use landscape orientation
--format [Letter|Legal|Tabloid|Ledger|A0|A1|A2|A3|A4|A5|A6]
Expand Down
11 changes: 11 additions & 0 deletions shot_scraper/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,12 @@ def javascript(
@click.option(
"--wait", type=int, help="Wait this many milliseconds before taking the screenshot"
)
@click.option("--wait-for", help="Wait until this JS expression returns true")
@click.option(
"--timeout",
type=int,
help="Wait this many milliseconds before failing",
)
@click.option(
"--media-screen", is_flag=True, help="Use screen rather than print styles"
)
Expand Down Expand Up @@ -840,6 +846,8 @@ def pdf(
output,
javascript,
wait,
wait_for,
timeout,
media_screen,
landscape,
format_,
Expand Down Expand Up @@ -880,6 +888,7 @@ def pdf(
bypass_csp=bypass_csp,
auth_username=auth_username,
auth_password=auth_password,
timeout=timeout,
)
page = context.new_page()
if log_console:
Expand All @@ -890,6 +899,8 @@ def pdf(
time.sleep(wait / 1000)
if javascript:
_evaluate_js(page, javascript)
if wait_for:
page.wait_for_function(wait_for)

kwargs = {
"landscape": landscape,
Expand Down
Loading