ScreenshotNeo

BlogAI agents

How to Automate Screenshots of Indian Ecommerce Product Pages with an AI Agent

Capture authorized Indian ecommerce product pages with an AI agent using Playwright, structured page data, and repeatable screenshot settings.

By the ScreenshotNeo team4 October 20269 min read

Short answer: For pages you are authorized to access and capture, use Playwright to open the product URL, wait for a site-specific condition that confirms the needed content has rendered, and save a viewport, full-page, or element screenshot. Give the AI agent both a screenshot for visual evidence and a fresh accessibility snapshot for structured page information. First check the marketplace’s current terms and obtain any permission your use requires; the terms reviewed here restrict automated extraction or access on Amazon India and Flipkart.

This guide shows a permission-conscious workflow, complete Playwright code, capture choices, and ways to make results repeatable. It does not establish permission for any particular marketplace, account, or use.

1. Confirm access and intended use

Before opening a page automatically, record the marketplace, account or access path, expected request volume, what content the screenshot will contain, where it will be stored, and whether it will be shared or republished. Check the current terms and obtain written permission or use an officially authorized interface when required.

  • Amazon India: Its Terms of Use describe a limited site license that excludes data-mining, robots, and similar extraction tools, and restrict extracting substantial content for reuse without express written consent.
  • Flipkart: Its Terms of Use prohibit page-scraping and similar automated or manual processes to access, acquire, copy, or monitor site content through means not purposely made available.
  • Amazon Associates: The Associates Program Operating Agreement licenses Product Advertising Content and API use within stated limits; it is not general permission to automate screenshots of public product pages.

These are platform-specific terms, not a universal legal ruling. Terms and interfaces can change. If your use depends on interpreting a restriction, get qualified advice. Do not bypass CAPTCHAs, authentication controls, rate limits, or other access restrictions.

2. Choose the right evidence for the agent

A screenshot records appearance. An accessibility snapshot gives the agent structured information about accessible page content and controls. Use both when the agent must understand a page and preserve how it looked; neither replaces permission to access or retain the material.

Capture Use it for Trade-off
Viewport The initial visible area, such as the product name, price, and primary image if present there. Does not include content below the fold.
Full page A permitted record of a long, scrollable page. Can produce a large, tall image; dynamic or lazy content may need a suitable readiness condition.
Element A specific authorized product image or details region. Requires a reliable locator, and the selected region may omit context.

Playwright describes a full-page screenshot as capturing the full scrollable page as if it fit on a very tall screen. Its screenshot guide documents viewport, full-page, and element captures; the Page API documents additional screenshot options.

3. Set up a permissioned Playwright capture

This runnable Node.js example accepts an authorized product URL, uses a caller-provided readiness selector, takes a screenshot, and saves provenance metadata. It deliberately does not include marketplace-specific selectors or bypass logic. Install Playwright and its Chromium browser in your project first:

npm install playwright
npx playwright install chromium

Save as capture.mjs and run it with AUTHORIZED_PRODUCT_URL set to a URL you are permitted to capture. Set READY_SELECTOR to a stable, permissioned selector for the content needed in your capture. The selector is intentionally supplied by the operator because no universal, verified readiness selector exists for the marketplaces named here.

import { chromium } from 'playwright';
import { writeFile } from 'node:fs/promises';

const url = process.env.AUTHORIZED_PRODUCT_URL;
const readySelector = process.env.READY_SELECTOR;
if (!url || !readySelector) {
  throw new Error('Set AUTHORIZED_PRODUCT_URL and READY_SELECTOR for an authorized page.');
}

const viewport = { width: 1440, height: 1000 };
const browser = await chromium.launch({ headless: true });
try {
  const context = await browser.newContext({ viewport, deviceScaleFactor: 1 });
  const page = await context.newPage();
  const response = await page.goto(url, { waitUntil: 'domcontentloaded', timeout: 45_000 });
  if (!response || !response.ok()) {
    throw new Error(`Navigation did not return a successful response: ${response?.status() ?? 'no response'}`);
  }

  // Use a site-specific condition that is permitted and signals the required content.
  await page.locator(readySelector).waitFor({ state: 'visible', timeout: 30_000 });
  await page.screenshot({ path: 'product-page.png', fullPage: true, animations: 'disabled' });

  const metadata = {
    sourceUrl: page.url(),
    capturedAt: new Date().toISOString(),
    viewport,
    deviceScaleFactor: 1,
    browserVersion: browser.version(),
    readinessSelector: readySelector,
  };
  await writeFile('product-page.json', JSON.stringify(metadata, null, 2));
  await context.close();
} finally {
  await browser.close();
}

Example invocation:

AUTHORIZED_PRODUCT_URL='https://authorized.example/product' READY_SELECTOR='[data-product-title]' node capture.mjs

The example checks navigation and a visible locator, but a successful HTTP response alone does not prove that all desired product details have loaded. Choose a condition aligned with your use and permission. If you need a viewport shot, change fullPage: true to fullPage: false. For a selected region, use a permitted locator’s screenshot({ path: 'product-region.png' }) after confirming it identifies the intended content.

4. Make the AI agent use snapshots and screenshots correctly

For an agent workflow, navigate through an authorized browser session, inspect a fresh accessibility snapshot, and then capture the visual evidence. If the agent interacts with the page, take another snapshot after navigation or interaction before relying on a locator. Playwright MCP documents separate tools for structured snapshots and screenshots; snapshots support understanding and interaction, while screenshots preserve visual appearance.

  1. Pass the agent only URLs and credentials it is authorized to use.
  2. Have it inspect structured page information to identify relevant content and controls.
  3. Use a permissioned readiness condition rather than an arbitrary fixed delay whenever possible.
  4. Capture the viewport, full page, or a permitted element according to the evidence needed.
  5. Store the source URL, capture timestamp, viewport, browser/runtime version, and relevant authorization reference with the image.
  6. Limit access to stored images, set a retention period, and avoid capturing account or customer information unless expressly authorized.

Do not treat a screenshot as a precise interaction map: visual position can vary with viewport, device scale, browser, platform, and rendering state. Use structured page information for controls and fresh visual evidence when appearance matters.

5. Configure scope and rendering consistently

  • Viewport and device scale: Fix viewport width and height, browser version, platform, and device scale for comparisons. Device scale can make the output larger than CSS-pixel dimensions imply.
  • Full-page versus viewport: Full-page capture includes the scrollable page; viewport capture is smaller and focused on the visible fold. Use the minimum scope that answers the task.
  • Element or clip: Use a locator screenshot for a specific region, or clipping options when a fixed rectangle is the authorized subject. Confirm the crop contains enough context.
  • Format and scale: Playwright supports screenshot type and scale options, along with clipping and masking. Choose output format and dimensions based on the downstream use; keep them fixed for comparisons.
  • Dynamic and lazy content: A navigation event is not a guarantee that images, prices, or other page details have rendered. Wait for a legitimate, site-specific condition. Avoid adding long fixed sleeps as a substitute for a readiness signal.
  • Animations: Disable animations where appropriate for stable comparison captures. Do not modify page state in a way that misrepresents the evidence.
  • Masking: Mask sensitive data only where allowed and where masking does not undermine the evidentiary purpose. Keep an original only if your authorization and retention policy permit it.

6. Troubleshoot common capture failures

Symptom Likely cause Practical fix
Navigation times out The page is slow, keeps connections open, or access is restricted. Check URL and network access; use an appropriate navigation milestone and a bounded timeout. Do not evade restrictions. Resolve permission or access issues with the site.
Selector wait times out The selector is wrong, stale, hidden, or the expected content did not render. Inspect a fresh permitted snapshot, verify the selector against the authorized page, and choose a condition tied to the actual required content.
Screenshot is blank or incomplete Capture happened before relevant rendering, the page returned an error/interstitial, or content is outside the selected scope. Check the page state and response, wait for the required content condition, and choose viewport, full-page, or element scope deliberately.
Images are missing in a full-page image Images may load lazily as they approach the viewport. Use a permitted readiness strategy that confirms the required images have loaded; do not assume navigation completion means every image is ready.
Screenshot differs between runs Viewport, device scale, browser version, platform, fonts, timing, or page content changed. Fix the environment and options, record metadata, and compare captures made under the same conditions.
Access denied, CAPTCHA, or login wall The site has applied an access control or requires an authorized session. Stop automated access and use an approved access method or obtain permission. Do not attempt to defeat the control.
Output file is unexpectedly large Full-page scope or high device scale produced many pixels. Capture only the needed region or viewport and use a suitable scale and format.

7. Performance, reliability, and cost

With self-hosted Playwright, you manage browser installation, runtime resources, concurrency, storage, retries, and maintenance. Full-page captures and high device scale increase image dimensions and can take more time and storage than a viewport shot. Bound navigation and selector waits, and retry only transient failures; repeated attempts should not be used to get around rate limits or access controls.

Keep a reproducible record of the browser version, viewport, device scale, source URL, capture time, and capture options. Treat page content as mutable: a later screenshot may differ because the seller, price, inventory, or layout changed. For comparison or audit use, define a capture schedule and retention policy appropriate to your authorization. No universal timing, accuracy, or cost benchmark applies to every site and page.

Or skip the browser setup

ScreenshotNeo is a website screenshot API and MCP server from Yorker Media. Its API can return a screenshot or PDF from one GET request. Cookie and consent banners are accepted like a visitor, and more than 60 known consent platforms, newsletter popups, and chat widgets are removed before capture; each step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers report the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents and MCP clients.

Use it only for pages you are authorized to capture; an API does not change a marketplace’s terms or grant access permission. See the ScreenshotNeo API documentation for parameters and configuration.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
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)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

Replace the example target with a URL you are authorized to capture. ScreenshotNeo supports full-page and element capture, device and viewport settings, waits, custom CSS and JavaScript, request blocking, caching, async jobs, bulk capture, and other options. Plans include 1,000 screenshots per month free with no card; paid plans start at $5 for 3,000 screenshots. Sign up free and get 1,000 screenshots a month with no card.

FAQ

Can an AI agent decide whether a screenshot is allowed?

No. The operator must establish authorization and permitted scope. An agent can follow those constraints, but it cannot grant permission.

Should the agent use a screenshot or an accessibility snapshot?

Use a snapshot to understand structured content and controls, and a screenshot to preserve appearance. Combine them when the task needs both.

Does an Amazon Associates API key authorize public-page screenshots?

No general permission follows from the Associates content/API license. Follow its stated scope and separately establish permission for the intended page capture.

Is there one reliable selector for Indian marketplace product pages?

This research does not establish one. Selectors and readiness conditions must be verified for the authorized page and can change.