Enhance Website Screenshots with Script URL JavaScript Injection

Discover how to take your website screenshots to the next level by injecting custom JavaScript code.

With script URL JavaScript injection, you can dynamically modify and interact with elements on the webpage before capturing the screenshot. This allows for tailored adjustments such as hiding menus, customizing forms, logging in, and triggering SPA states before AddScreenshots captures the result.


Use Cases for JavaScript Injection

  • Populate forms: Fill search boxes, login forms, or filters to showcase dynamic results.
  • Dismiss pop-ups: Click consent banners or modal close buttons automatically.
  • Navigate widgets: Trigger tabs, accordions, or custom tooltips prior to capture.
  • Chain automations: Combine with click elements and scroll wait for full workflow coverage.

How to Use script_url

  1. Host your JavaScript: Upload the script to a public URL (e.g. GitHub, S3, or your CDN).
  2. Add the parameter: Append &script_url=YOUR_SCRIPT to any Screenshot API request or template.
  3. Return values: Optionally pipe outputs into JSON/Base64 responses for downstream processing.
  4. Store the capture: Deliver screenshots straight to S3, Azure, or other supported storage targets.

Custom Script Example

Below is an example of using a JavaScript file to interact with a website:

// Line breaks added for readability https://api.addscreenshots.com/screenshots
?apikey=
YOUR_API_KEY
&script_url=https://example.com/google.js
&url=google.com

The JavaScript contained in the demo will enter the search criteria 'Car Rental' and click on the search button:

document.querySelector('input[name=q]').value = 'Car Rental';
document.querySelector('input[name=btnK]').click();

Screenshot with JavaScript Injection

Ready to automate interactive screenshots? Explore plans or create your API key and deploy script_url injections today.