Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use --run-script to inject JavaScript after a page loads, then control capture timing with either a fixed --javascript-delay or a page-set window.status value passed through --window-status. JavaScript is enabled by default, but adding --enable-javascript makes your intent explicit. The same pattern works for PDF output and, with an important version caveat, image output.

The basic commands

These commands cover the common cases. Replace the input URL or HTML file and output path with your own values.

wkhtmltopdf --enable-javascript --javascript-delay 1000 input.html output.pdf

The command enables JavaScript and waits 1,000 milliseconds after page loading before producing the PDF.

wkhtmltopdf --enable-javascript --run-script "document.body.dataset.rendered='true';" input.html output.pdf

--run-script runs the supplied snippet after the page is done loading. It is repeatable, so you can pass more than one post-load script:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Philips 24 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 241V8LB
  • CRISP CLARITY: This 23.8″ Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
  • WORK SEAMLESSLY: This sleek monitor is virtually bezel-free on three sides, so the screen looks even bigger for the viewer. This minimalistic design also allows for seamless multi-monitor setups that enhance your workflow and boost productivity
  • A BETTER READING EXPERIENCE: For busy office workers, EasyRead mode provides a more paper-like experience for when viewing lengthy documents
wkhtmltopdf 
  --enable-javascript 
  --run-script "document.querySelector('#status').textContent='ready';" 
  --run-script "document.body.classList.add('captured');" 
  input.html output.pdf

For an image, use the corresponding executable:

wkhtmltoimage --enable-javascript --javascript-delay 1000 input.html output.png

How wkhtmltopdf executes JavaScript

JavaScript is on by default

The documented command-line behavior allows web pages to run JavaScript by default. Use --enable-javascript when you want the command line to state that requirement explicitly. Use --disable-javascript when you need a static render or want to prevent page scripts from running.

Enabling JavaScript does not by itself guarantee that every asynchronous operation will finish before capture. A page can still be waiting for an Ajax request, a chart library, a timer, or a client-side rendering step when the renderer takes its snapshot.

Injecting code after load

--run-script <js> is intended for additional code that should run after the page has finished loading. Typical uses include adding a CSS class, replacing text, triggering a component, or setting a marker that your own page can observe.

Quote the entire shell argument. In POSIX shells, single quotes make JavaScript punctuation easy to preserve:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
wkhtmltopdf --enable-javascript 
  --run-script 'document.querySelector("#chart").classList.add("print-mode");' 
  input.html output.pdf

In the Windows command prompt, double quotes surround the argument and JavaScript’s inner quotes must be escaped or changed to single quotes:

wkhtmltopdf --enable-javascript --run-script "document.body.dataset.rendered='true';" input.html output.pdf

Keep injected code short and deterministic. If it starts asynchronous work, pair it with an explicit completion strategy rather than assuming the renderer will wait for it.

Rank #2
Philips 22 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 221V8LB
  • CRISP CLARITY: This 22 inch class (21.5″ viewable) Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • 100HZ FAST REFRESH RATE: 100Hz brings your favorite movies and video games to life. Stream, binge, and play effortlessly
  • SMOOTH ACTION WITH ADAPTIVE-SYNC: Adaptive-Sync technology ensures fluid action sequences and rapid response time. Every frame will be rendered smoothly with crystal clarity and without stutter
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors

Make the renderer wait for asynchronous work

Fixed delay with --javascript-delay

Pass a number of milliseconds when the page needs a known settling period:

wkhtmltopdf --enable-javascript --javascript-delay 1500 https://example.com report.pdf

A delay is simple and works well when the page’s work has predictable duration. It is less reliable when network speed or data size varies: too short produces an incomplete document, while too long adds needless latency to every conversion.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Page-signaled completion with --window-status

For variable-duration work, have the page set window.status only after the final DOM update:

<script>
  fetch('/data.json')
    .then(response => response.json())
    .then(data => {
      document.querySelector('#result').textContent = data.value;
      window.status = 'ready-for-capture';
    });
</script>

Then wait for that exact value:

wkhtmltopdf --enable-javascript 
  --window-status ready-for-capture 
  https://example.com/report.html report.pdf

This approach ties capture to the page’s actual state instead of an arbitrary number of milliseconds. Set the status after images, charts, fonts, and other required DOM changes have completed—not merely when the request has started.

Using window.print()

The libwkhtmltox API reference describes rendering as waiting for the configured JavaScript delay or until JavaScript calls window.print(). Where your packaged binary honors that behavior, a page can call window.print() as its completion signal. Test this with the exact binary you deploy, because wkhtmltopdf and wkhtmltoimage builds can differ in timing behavior.

Choosing a completion method

Situation Recommended control Trade-off
Static page with a predictable render time --javascript-delay <milliseconds> Easy to configure, but the value may be too short or unnecessarily long.
Data arrives at an unpredictable time Page sets window.status; CLI uses --window-status <value> More deterministic, but the page must set the value on every successful path.
Code already uses print-oriented completion window.print() where supported by the binary Behavior is renderer/build dependent and should be validated before production use.

wkhtmltoimage timing and the version caveat

The image command accepts the same JavaScript and delay flags:

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Dell 24 Monitor - SE2426H - 23.8-inch FHD (1920x1080) 144Hz 1ms Display, in-Plane Switching (IPS) Technology, AMD FreeSync™, TÜV 3-Star 2X HDMI, Tilt
  • Clear visuals. Fluid motion: A 144Hz refresh rate and 1ms MPRT deliver smooth, tear‑free motion across work, gaming, and streaming for clearer, more fluid viewing.
  • Eye comfort: TÜV Rheinland 3‑star* certification reduces harmful blue light while preserving stunning color quality without compromise. *TÜV Rheinland 3-star eye comfort certification.
  • Wide viewing angle: Get consistent views across a wide 178° /178° viewing angle.
  • In-Plane Switching (IPS): See excellent color accuracy and consistency across wide viewing angles with In-plane Switching (IPS) technology.
  • Ultra-thin bezels: Maximize your viewing experience with thin bezels.
wkhtmltoimage --enable-javascript 
  --run-script "document.body.dataset.rendered='true';" 
  --javascript-delay 1000 input.html output.png

However, issue #2142 records historical wkhtmltoimage builds that rendered before delayed DOM updates because --javascript-delay and --window-status were ignored. This is a binary-specific caveat, not a guarantee that every current package has the bug.

Check the exact wkhtmltoimage executable, package version, and distribution you deploy. If timing is critical, create a small fixture page that changes visible text only after a delay, then verify that the captured image contains the changed text. If the binary does not honor the timing flags, make the page render synchronously or use a conservative fallback delay after confirming what that build actually does.

Local HTML, scripts, and assets

Pages loaded from local files often reference local JavaScript, CSS, fonts, or images. Review local-file access deliberately rather than assuming a file URL can read any path.

  • --disable-local-file-access prevents local file access.
  • --enable-local-file-access enables it when your conversion requires local resources.

Use the narrowest access arrangement appropriate for your deployment and keep untrusted input away from a process that can read sensitive local files. A page can have JavaScript enabled while still failing because its script or asset is inaccessible as a local file.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Debug JavaScript and long-running scripts

Expose errors first

Add --debug-javascript while diagnosing missing elements, syntax errors, failed promises, and other browser-side warnings:

wkhtmltopdf --enable-javascript --debug-javascript 
  --javascript-delay 2000 input.html output.pdf

Run the same input outside the conversion pipeline when possible and confirm that the script is actually present in the loaded page, not just in a source file that the renderer cannot reach.

Rank #4
Samsung 27" Essential S3 (S36GD) Series FHD 1800R Curved Computer Monitor
  • CURVED FOR ENHANCED ENGAGEMENT: An immersive viewing experience with a curved monitor that wraps more closely around your field of vision; It creates a wider view, enhancing depth perception and minimizing peripheral distraction
  • SMOOTH PERFORMANCE FOR SEAMLESS CONTENT: Stay in the action when playing games, watching videos, or working on creative projects; The 100Hz refresh rate reduces lag and motion blur so you don't miss a thing in fast-paced moments¹
  • MORE GAMING POWER: Gain the edge with optimizable game settings; Color and image contrast can be adjusted to see scenes more vividly and spot enemies hiding in the dark; Game Mode adjusts any game to fill the screen so you can view every detail²
  • KEEP IT EASY ON THE EYES: Care for your eyes and stay comfortable, even during long sessions; Advanced eye comfort technology certified by TÜV reduces eye strain by minimizing blue light and reducing irritating screen flicker²
  • INCREASED VERSATILITY: Connect to more; Plug devices straight into your monitor for increased flexibility, making your computing environment even more convenient

Check slow-script handling

wkhtmltopdf and wkhtmltoimage include controls that can stop scripts considered too slow. If legitimate rendering work is being terminated, test with --no-stop-slow-scripts:

wkhtmltopdf --enable-javascript --no-stop-slow-scripts 
  --javascript-delay 3000 input.html output.pdf

Do not disable the safeguard reflexively. First determine whether the page has an accidental infinite loop or an unexpectedly expensive operation. A long delay does not repair a script that never reaches its completion state.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The libwkhtmltox API equivalents

If you embed the renderer instead of invoking the CLI, the same concepts are exposed as settings:

CLI option libwkhtmltox setting Purpose
--enable-javascript or --disable-javascript web.enableJavascript Controls whether page JavaScript executes.
--javascript-delay <milliseconds> load.jsdelay Sets the post-load wait before rendering.
--window-status <value> Use the corresponding window-status load setting in your binding Waits for a page-controlled status value where supported.

The API reference describes load.jsdelay as waiting that amount or until JavaScript calls window.print(). Binding names and configuration syntax vary, so inspect the API wrapper you use rather than copying CLI syntax into application code.

A repeatable production workflow

  1. Prove the page state. Add a visible marker or log message immediately before setting window.status. Confirm that all required data and DOM updates happen first.
  2. Start with explicit flags. Use --enable-javascript, a completion strategy, and --debug-javascript during development.
  3. Test both output types. A PDF conversion succeeding does not prove that the installed image binary honors the same timing controls.
  4. Test slow and failed paths. Simulate a delayed request, an empty response, and a script error. Decide whether the conversion should fail, capture a fallback state, or continue without optional content.
  5. Remove diagnostic options after validation. Keep the chosen delay or status protocol, but avoid leaving verbose debugging enabled in routine jobs unless you need its output.

Troubleshooting

The PDF or image contains the initial, unmodified DOM

  • Confirm JavaScript was not disabled by a global option or wrapper setting.
  • Check that --run-script is quoted correctly and runs after the intended page loads.
  • If the page is asynchronous, replace a guess with --window-status or increase the delay after measuring the real work.
  • For images, verify whether the exact wkhtmltoimage build honors delay and status; issue #2142 documents builds that did not.

The command waits indefinitely

  • Inspect the page code for a branch that never sets the expected status.
  • Use --debug-javascript to find exceptions that stop the completion code.
  • Check whether a request is blocked, unreachable, or waiting on a resource that never resolves.
  • Review slow-script handling; only use --no-stop-slow-scripts when the long work is intentional and bounded.

A local script or image is missing

  • Check whether local-file access has been disabled.
  • Enable local access deliberately with --enable-local-file-access when the input is trusted and requires it.
  • Verify file paths and permissions from the account that actually runs wkhtmltopdf or wkhtmltoimage.

The script works in a browser but not in wkhtmltopdf

  • Use the renderer’s debug output to identify unsupported or failing code.
  • Confirm every remote resource is reachable from the conversion host.
  • Replace browser-only timing assumptions with a visible, deterministic completion marker.
  • Record the renderer binary and package version; behavior is not uniform across builds.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If you need a current website screenshot rather than a local wkhtmltopdf pipeline, ScreenshotNeo provides a single HTTP request and also supports custom JavaScript, selector waits, fixed delays, network-idle waits, cookies, headers, device presets, full-page capture, PDFs, and more. Its cleanup step accepts cookie or consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture.

Use the ScreenshotNeo API documentation for the complete option list. A basic call is:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

Python:

import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)

Node.js:

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

Only clean shots are billed. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and each response identifies the result with X-Page-Verdict and X-Billed headers. An MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients. The Free plan includes 1,000 screenshots per month without a card; paid plans start at $5 for 3,000 screenshots. Create a free ScreenshotNeo account.

Best Value
Sceptre New 22-Inch Gaming Monitor, FHD 1080p, Up to 144Hz, HDMI, DisplayPort, Built-in Speakers, Machine Black (E225W-FW144 Series, 2026)
  • 【INTEGRATED SPEAKERS】Whether you're at work or in the midst of an intense gaming session, our built-in speakers provide rich and seamless audio, all while keeping your desk clutter-free.
  • 【EASY ON THE EYES】 Protect your eyes and enhance your comfort with Blue-Light Shift technology. This feature reduces harmful blue light emissions from your screen, helping to alleviate eye strain during long hours of use and promoting healthier viewing habits.
  • 【WIDEN YOUR PERSPECTIVE】Our sleek minimal bezel design ensures undivided attention. The nearly bezel-free display seamlessly connects in a dual monitor arrangement, delivering an unobstructed view that lets you focus on more at once, completely distraction-free.

FAQ

Can I pass more than one custom script?

Yes. The --run-script option is repeatable. Keep each snippet independently quoted and make their order explicit when one depends on another.

Does a successful JavaScript exit prove the page is ready?

No. A script can finish while a separate request or rendering task is still pending. Signal readiness only after the content that must appear in the output has been updated.

Why record the exact wkhtml binary in deployment?

JavaScript timing behavior, especially for wkhtmltoimage, has varied between packaged builds. Reproducing a conversion requires the same executable and configuration, not just the same command-line text.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Frequently Asked Questions

Can I pass more than one custom script?

Yes. The --run-script option is repeatable. Keep each snippet independently quoted and make their order explicit when one depends on another.

Does a successful JavaScript exit prove the page is ready?

No. A script can finish while a separate request or rendering task is still pending. Signal readiness only after the content that must appear in the output has been updated.

Why record the exact wkhtml binary in deployment?

JavaScript timing behavior, especially for wkhtmltoimage, has varied between packaged builds. Reproducing a conversion requires the same executable and configuration, not just the same command-line text.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.