/** * Custom JS injector — run user-provided JavaScript in the context of each crawled page. * * Use cases: * - Extract custom data points not captured by standard extractors * - Set localStorage/sessionStorage values before crawl * - Override fetch() to intercept API calls * - Simulate user events (keydown, focus, etc.) * - Bypass specific anti-bot checks * * Security: scripts run in the page context (sandboxed by Chromium's renderer). * They cannot access the Node.js process or file system. * ZeTa validates scripts are strings before injection. */ import type { Page } from 'playwright'; export interface JsInjectionOpts { /** Script to run on every page BEFORE navigation (via page.addInitScript) */ initScript?: string; /** Script to run on every page AFTER navigation completes (via page.evaluate) */ postLoadScript?: string; /** Key-value pairs to set in localStorage before page load */ localStorage?: Record; /** Key-value pairs to set in sessionStorage before page load */ sessionStorage?: Record; /** Cookie key-value pairs to add before page load */ cookies?: Array<{ name: string; value: string; domain?: string; path?: string; }>; } export interface JsInjectionResult { initScriptApplied: boolean; postLoadResult: unknown; storageSet: boolean; cookiesSet: number; error?: string; } export declare function injectCustomJs(page: Page, opts: JsInjectionOpts): Promise; /** Safe string validator — ensures script is a string, not an object/function reference */ export declare function validateScript(script: unknown): string;