Skip to main content
Version: 4.0 (RC)

crawlee-playwright.api

Public API Report File for "@crawlee/playwright"

Do not edit this file. It is a report generated by API Extractor.


import type { AnyNode } from 'domhandler';
import type { Awaitable } from '@crawlee/types';
import { BasicCrawler } from '@crawlee/basic';
import type { BasicCrawlerOptions } from '@crawlee/basic';
import type { BatchAddRequestsResult } from '@crawlee/types';
import type { Browser } from 'playwright';
import { BrowserCrawler } from '@crawlee/browser';
import { BrowserCrawlerOptions } from '@crawlee/browser';
import type { BrowserCrawlingContext } from '@crawlee/browser';
import type { BrowserHook } from '@crawlee/browser';
import type { BrowserLaunchContext } from '@crawlee/browser';
import type { BrowserPool } from '@crawlee/browser-pool';
import type { BrowserPoolHooks } from '@crawlee/browser-pool';
import type { BrowserPoolOptions } from '@crawlee/browser-pool';
import type { BrowserType } from 'playwright';
import { Cheerio } from 'cheerio';
import { CheerioAPI } from 'cheerio';
import { Configuration } from '@crawlee/browser';
import type { ContextPipeline } from '@crawlee/browser';
import type { ContextPipeline as ContextPipeline_2 } from '@crawlee/core';
import type { CrawlingContext } from '@crawlee/browser';
import type { CrawlingContext as CrawlingContext_2 } from '@crawlee/core';
import { Dictionary } from '@crawlee/types';
import type { Download } from 'playwright';
import type { EnqueueLinksOptions } from '@crawlee/core';
import type { GetUserDataFromRequest } from '@crawlee/browser';
import type { GetUserDataFromRequest as GetUserDataFromRequest_2 } from '@crawlee/core';
import { IRequestManager } from '@crawlee/browser';
import type { LaunchOptions } from 'playwright';
import type { LoadedRequest } from '@crawlee/browser';
import type { Page } from 'playwright';
import { PlaywrightPlugin } from '@crawlee/browser-pool';
import type { RecoverableStatePersistenceOptions } from '@crawlee/core';
import type { RemoteBrowserPool } from '@crawlee/browser-pool';
import type { RemoteBrowserPoolOptions } from '@crawlee/browser-pool';
import type { Request as Request_2 } from '@crawlee/core';
import { Request as Request_3 } from '@crawlee/browser';
import type { RequestHandler } from '@crawlee/browser';
import type { RequestTransform } from '@crawlee/browser';
import type { Response as Response_2 } from 'playwright';
import type { RouterHandler } from '@crawlee/browser';
import type { RouterRoutes } from '@crawlee/browser';
import type { RouterRoutes as RouterRoutes_2 } from '@crawlee/core';
import type { RouteSchemas } from '@crawlee/browser';
import type { RoutesFromSchemas } from '@crawlee/browser';
import type { SkippedRequestCallback } from '@crawlee/browser';
import type { StorageTransactionView } from '@crawlee/core';
import type { UrlPatternInput } from '@crawlee/browser';
import { z } from 'zod';

// Not exported by the entry point; reachable only as a referenced type.
// @public (undocumented)
type AdaptiveHook<ContextExtension = Dictionary<never>> = BrowserHook<AdaptiveHookContext, ContextExtension>;

// Not exported by the entry point; reachable only as a referenced type.
// @public (undocumented)
interface AdaptiveHookContext extends Pick<AdaptivePlaywrightCrawlerContext, 'id' | 'session' | 'proxyInfo' | 'log'> {
// (undocumented)
gotoOptions?: PlaywrightGotoOptions;
// (undocumented)
page?: Page;
// (undocumented)
request: Request_3;
}

// @public
export class AdaptivePlaywrightCrawler<ContextExtension = Dictionary<never>, ExtendedContext extends AdaptivePlaywrightCrawlerContext = AdaptivePlaywrightCrawlerContext & ContextExtension, Routes extends Record<keyof Routes, Dictionary> = Record<string, GetUserDataFromRequest_2<AdaptivePlaywrightCrawlerContext['request']>>, StatisticStateExtension extends AdaptivePlaywrightCrawlerStatisticState = AdaptivePlaywrightCrawlerStatisticState> extends BasicCrawler<AdaptivePlaywrightCrawlerContext, ContextExtension, ExtendedContext, Routes, StatisticStateExtension> {
constructor(options?: AdaptivePlaywrightCrawlerOptions<ContextExtension, ExtendedContext, Routes, StatisticStateExtension>);
// (undocumented)
protected buildContextPipeline(): ContextPipeline_2<CrawlingContext_2, AdaptivePlaywrightCrawlerContext>;
// (undocumented)
protected init(): Promise<void>;
// (undocumented)
protected runRequestHandler(crawlingContext: CrawlingContext_2): Promise<void>;
// (undocumented)
teardown(): Promise<void>;
}

// @public (undocumented)
export interface AdaptivePlaywrightCrawlerContext<UserData extends Dictionary = any> extends CrawlingContext_2<UserData> {
// (undocumented)
enqueueLinks(options?: EnqueueLinksOptions): Promise<unknown>;
page: Page;
parseWithCheerio(selector?: string, timeoutMs?: number): Promise<CheerioAPI>;
querySelector(selector: string, timeoutMs?: number): Promise<Cheerio<AnyNode>>;
querySelectorAll(selector: string, timeoutMs?: number): Promise<Cheerio<AnyNode>>;
// (undocumented)
request: LoadedRequest<Request_3<UserData>>;
response: Response;
waitForSelector(selector: string, timeoutMs?: number): Promise<void>;
}

// @public (undocumented)
export interface AdaptivePlaywrightCrawlerOptions<ContextExtension = Dictionary<never>, ExtendedContext extends AdaptivePlaywrightCrawlerContext = AdaptivePlaywrightCrawlerContext & ContextExtension, Routes extends Record<keyof Routes, Dictionary> = Record<string, GetUserDataFromRequest_2<AdaptivePlaywrightCrawlerContext['request']>>, StatisticStateExtension extends AdaptivePlaywrightCrawlerStatisticState = AdaptivePlaywrightCrawlerStatisticState> extends Omit<BasicCrawlerOptions<AdaptivePlaywrightCrawlerContext, ContextExtension, ExtendedContext, Routes, StatisticStateExtension>, 'preNavigationHooks' | 'postNavigationHooks'> {
postNavigationHooks?: AdaptivePostNavigationHook<ContextExtension>[];
preNavigationHooks?: AdaptiveHook<ContextExtension>[];
renderingTypeDetectionRatio?: number;
renderingTypePredictor?: IRenderingTypePredictor;
resultChecker?: (result: StorageTransactionView) => boolean;
resultComparator?: (resultA: StorageTransactionView, resultB: StorageTransactionView) => boolean | 'equal' | 'different' | 'inconclusive';
shouldPropagateError?: (error: Error, context: PlaywrightCrawlingContext) => Awaitable<boolean>;
}

// @public
export type AdaptivePlaywrightCrawlerStatisticState = z.infer<typeof adaptiveStatisticStateSchema>;

// @public
export const adaptivePlaywrightCrawlerStatisticState: {
deserialize: z.ZodObject<{
httpOnlyRequestHandlerRuns: z.ZodDefault<z.ZodNumber>;
browserRequestHandlerRuns: z.ZodDefault<z.ZodNumber>;
renderingTypeMispredictions: z.ZodDefault<z.ZodNumber>;
}, z.core.$strip>;
};

// Not exported by the entry point; reachable only as a referenced type.
// @public (undocumented)
type AdaptivePostNavigationHook<ContextExtension = Dictionary<never>> = BrowserHook<Omit<AdaptiveHookContext, 'request'> & {
request: LoadedRequest<Request_3>;
}, ContextExtension>;

// Not exported by the entry point; reachable only as a referenced type.
// @public (undocumented)
const adaptiveStatisticStateSchema: z.ZodObject<{
httpOnlyRequestHandlerRuns: z.ZodDefault<z.ZodNumber>;
browserRequestHandlerRuns: z.ZodDefault<z.ZodNumber>;
renderingTypeMispredictions: z.ZodDefault<z.ZodNumber>;
}, z.core.$strip>;

// @public
function blockRequests(page: Page, options?: BlockRequestsOptions): Promise<void>;

// @public (undocumented)
interface BlockRequestsOptions {
extraUrlPatterns?: string[];
urlPatterns?: string[];
}

// Not exported by the entry point; reachable only as a referenced type.
// @public (undocumented)
type ClickOptions = Parameters<Page['click']>[1];

// @public (undocumented)
function closeCookieModals(page: Page): Promise<void>;

// @public (undocumented)
type CompiledScriptFunction = (params: CompiledScriptParams) => Promise<unknown>;

// @public (undocumented)
interface CompiledScriptParams {
// (undocumented)
page: Page;
// (undocumented)
request: Request_3;
}

// @public
function compileScript(scriptString: string, context?: Dictionary): CompiledScriptFunction;

// @public (undocumented)
export function createAdaptivePlaywrightRouter<Context extends AdaptivePlaywrightCrawlerContext = AdaptivePlaywrightCrawlerContext, Routes extends Record<keyof Routes, Dictionary> = Record<string, GetUserDataFromRequest_2<Context['request']>>>(routes?: RouterRoutes_2<Context, Routes>): RouterHandler<Context, Routes>;

// @public (undocumented)
export function createAdaptivePlaywrightRouter<Context extends AdaptivePlaywrightCrawlerContext = AdaptivePlaywrightCrawlerContext, UserData extends Dictionary = GetUserDataFromRequest_2<Context['request']>>(routes?: RouterRoutes_2<Context, Record<string, UserData>>): RouterHandler<Context, Record<string, UserData>>;

// @public (undocumented)
export function createAdaptivePlaywrightRouter<Context extends AdaptivePlaywrightCrawlerContext = AdaptivePlaywrightCrawlerContext, const Schemas extends RouteSchemas = RouteSchemas>(schemas: Schemas): RouterHandler<Context, RoutesFromSchemas<Schemas>>;

// @public
export function createPlaywrightRouter<Context extends PlaywrightCrawlingContext = PlaywrightCrawlingContext, Routes extends Record<keyof Routes, Dictionary> = Record<string, GetUserDataFromRequest<Context['request']>>>(routes?: RouterRoutes<Context, Routes>): RouterHandler<Context, Routes>;

// @public (undocumented)
export function createPlaywrightRouter<Context extends PlaywrightCrawlingContext = PlaywrightCrawlingContext, UserData extends Dictionary = GetUserDataFromRequest<Context['request']>>(routes?: RouterRoutes<Context, Record<string, UserData>>): RouterHandler<Context, Record<string, UserData>>;

// @public (undocumented)
export function createPlaywrightRouter<Context extends PlaywrightCrawlingContext = PlaywrightCrawlingContext, const Schemas extends RouteSchemas = RouteSchemas>(schemas: Schemas): RouterHandler<Context, RoutesFromSchemas<Schemas>>;

// @public
function enqueueLinksByClickingElements(options: EnqueueLinksByClickingElementsOptions): Promise<BatchAddRequestsResult>;

// @public (undocumented)
interface EnqueueLinksByClickingElementsOptions {
clickOptions?: ClickOptions;
exclude?: readonly UrlPatternInput[];
forefront?: boolean;
include?: UrlPatternInput[];
label?: string;
maxWaitForPageIdleSecs?: number;
onSkippedRequest?: SkippedRequestCallback;
page: Page;
requestManager: IRequestManager;
selector: string;
skipNavigation?: boolean;
transformRequestFunction?: RequestTransform;
userData?: Dictionary;
waitForPageIdleSecs?: number;
}

// @public
export function fullResultComparator(resultA: StorageTransactionView, resultB: StorageTransactionView): boolean;

// @public
function gotoExtended(page: Page, request: Request_3, gotoOptions?: PlaywrightDirectNavigationOptions): Promise<Response_2 | null>;

// @public
export function handleCloudflareChallengeHook(options?: HandleCloudflareChallengeOptions): PlaywrightHook;

// @public (undocumented)
interface HandleCloudflareChallengeOptions {
clickCallback?: (page: Page, boundingBox: {
x: number;
y: number;
}) => Promise<void>;
clickPositionCallback?: (page: Page) => Promise<{
x: number;
y: number;
} | null>;
isBlockedCallback?: (page: Page) => Promise<boolean>;
isChallengeCallback?: (page: Page) => Promise<boolean>;
preChallengeSleepSecs?: number;
sleepSecs?: number;
verbose?: boolean;
}

// @public
function infiniteScroll(page: Page, options?: InfiniteScrollOptions): Promise<void>;

// @public (undocumented)
interface InfiniteScrollOptions {
buttonSelector?: string;
maxScrollHeight?: number;
scrollDownAndUp?: boolean;
stopScrollCallback?: () => unknown | Promise<unknown>;
timeoutSecs?: number;
waitForSecs?: number;
}

// @public
function injectFile(page: Page, filePath: string, options?: InjectFileOptions): Promise<unknown>;

// @public (undocumented)
interface InjectFileOptions {
surviveNavigations?: boolean;
}

// @public
function injectJQuery(page: Page, options?: {
surviveNavigations?: boolean;
}): Promise<unknown>;

// @public
export interface IRenderingTypePredictor {
predict(request: Request_2): {
renderingType: RenderingType;
detectionProbabilityRecommendation: number;
};
storeResult(requests: Request_2 | Request_2[], renderingType: RenderingType): void;
}

// @public
export function launchPlaywright(launchContext?: PlaywrightLaunchContext, configuration?: Configuration): Promise<Browser>;

// @public
function parseWithCheerio(page: Page, ignoreShadowRoots?: boolean, ignoreIframes?: boolean): Promise<CheerioAPI>;

// @public
export type PlaywrightBrowserPool = BrowserPool<{
browserPlugins: [PlaywrightPlugin];
}, [PlaywrightPlugin]>;

// @public
export function playwrightBrowserPool(options?: PlaywrightBrowserPoolOptions): PlaywrightBrowserPool;

// @public (undocumented)
export interface PlaywrightBrowserPoolOptions extends Omit<BrowserPoolOptions, 'browserPlugins'>, BrowserPoolHooks<ReturnType<PlaywrightPlugin['createController']>, ReturnType<PlaywrightPlugin['createLaunchContext']>, Page> {
configuration?: Configuration;
headless?: boolean;
launchContext?: PlaywrightLaunchContext;
}

declare namespace playwrightClickElements {
export {
enqueueLinksByClickingElements,
clickElementsAndInterceptNavigationRequests,
clickElements,
EnqueueLinksByClickingElementsOptions
}
}

// @public (undocumented)
interface PlaywrightContextUtils {
blockRequests(options?: BlockRequestsOptions): Promise<void>;
closeCookieModals(): Promise<void>;
compileScript(scriptString: string, ctx?: Dictionary): CompiledScriptFunction;
enqueueLinksByClickingElements(options: Omit<EnqueueLinksByClickingElementsOptions, 'page' | 'requestManager'>): Promise<BatchAddRequestsResult>;
handleCloudflareChallenge(options?: HandleCloudflareChallengeOptions): Promise<Response_2 | undefined>;
infiniteScroll(options?: InfiniteScrollOptions): Promise<void>;
injectFile(filePath: string, options?: InjectFileOptions): Promise<unknown>;
injectJQuery(): Promise<unknown>;
listDownloads(): Promise<Download[]>;
parseWithCheerio(selector?: string, timeoutMs?: number): Promise<CheerioAPI>;
saveSnapshot(options?: SaveSnapshotOptions): Promise<void>;
waitForSelector(selector: string, timeoutMs?: number): Promise<void>;
}

// @public
export class PlaywrightCrawler<ContextExtension = Dictionary<never>, ExtendedContext extends PlaywrightCrawlingContext = PlaywrightCrawlingContext & ContextExtension, Routes extends Record<keyof Routes, Dictionary> = Record<string, GetUserDataFromRequest<PlaywrightCrawlingContext['request']>>, StatisticStateExtension extends object = {}> extends BrowserCrawler<Page, Response_2, LaunchOptions, PlaywrightCrawlingContext, ContextExtension, ExtendedContext, Routes, StatisticStateExtension> {
constructor(options?: PlaywrightCrawlerOptions<ContextExtension, ExtendedContext, Routes, StatisticStateExtension>);
// (undocumented)
protected buildContextPipeline(): ContextPipeline<CrawlingContext, PlaywrightCrawlingContext>;
// (undocumented)
protected navigationHandler(crawlingContext: PlaywrightCrawlingContext, gotoOptions: PlaywrightDirectNavigationOptions): Promise<Response_2 | null>;
}

// @public (undocumented)
export interface PlaywrightCrawlerOptions<ContextExtension = Dictionary<never>, ExtendedContext extends PlaywrightCrawlingContext = PlaywrightCrawlingContext & ContextExtension, Routes extends Record<keyof Routes, Dictionary> = Record<string, GetUserDataFromRequest<PlaywrightCrawlingContext['request']>>, StatisticStateExtension extends object = {}> extends BrowserCrawlerOptions<Page, Response_2, PlaywrightCrawlingContext, ContextExtension, ExtendedContext, Routes, StatisticStateExtension> {
headless?: boolean;
launchContext?: PlaywrightLaunchContext;
postNavigationHooks?: BrowserHook<PlaywrightCrawlingContext<GetUserDataFromRequest<ExtendedContext['request']>>, ContextExtension>[];
preNavigationHooks?: BrowserHook<PlaywrightCrawlingContext<GetUserDataFromRequest<ExtendedContext['request']>>, ContextExtension>[];
requestHandler?: RouterHandler<ExtendedContext, Routes> | RequestHandler<ExtendedContext>;
}

// @public (undocumented)
export interface PlaywrightCrawlingContext<UserData extends Dictionary = any> extends BrowserCrawlingContext<Page, Response_2, UserData, PlaywrightGotoOptions>, PlaywrightContextUtils {
}

// @public (undocumented)
export interface PlaywrightDirectNavigationOptions {
referer?: string;
timeout?: number;
waitUntil?: 'domcontentloaded' | 'load' | 'networkidle';
}

// @public (undocumented)
export type PlaywrightGotoOptions = NonNullable<Parameters<Page['goto']>[1]>;

// @public (undocumented)
export type PlaywrightHook<UserData extends Dictionary = any> = BrowserHook<PlaywrightCrawlingContext<UserData>>;

// @public
export interface PlaywrightLaunchContext extends BrowserLaunchContext<LaunchOptions, BrowserType> {
launcher?: BrowserType;
launchOptions?: LaunchOptions & Parameters<BrowserType['launchPersistentContext']>[1];
proxyUrl?: string;
useChrome?: boolean;
useIncognitoPages?: boolean;
userDataDir?: string;
}

declare namespace playwrightUtils {
export {
injectFile,
injectJQuery,
gotoExtended,
blockRequests,
compileScript,
infiniteScroll,
saveSnapshot,
parseWithCheerio,
closeCookieModals,
InjectFileOptions,
BlockRequestsOptions,
PlaywrightDirectNavigationOptions as DirectNavigationOptions,
CompiledScriptParams,
CompiledScriptFunction,
InfiniteScrollOptions,
SaveSnapshotOptions,
HandleCloudflareChallengeOptions,
PlaywrightContextUtils,
enqueueLinksByClickingElements,
playwrightUtils_2 as playwrightUtils
}
}

// @public
export function remotePlaywrightBrowserPool(options: RemotePlaywrightBrowserPoolOptions): RemoteBrowserPool<Page>;

// @public (undocumented)
export interface RemotePlaywrightBrowserPoolOptions extends Pick<PlaywrightBrowserPoolOptions, 'launchContext' | 'headless' | 'configuration'>, Omit<RemoteBrowserPoolOptions, 'browserPlugins'> {
}

// @public (undocumented)
export type RenderingType = 'clientOnly' | 'static';

// @public
export class RenderingTypePredictor implements IRenderingTypePredictor {
// (undocumented)
[Symbol.asyncDispose](): Promise<void>;
constructor(input: RenderingTypePredictorOptions);
initialize(): Promise<void>;
predict(input: Request_2): {
renderingType: RenderingType;
detectionProbabilityRecommendation: number;
};
storeResult(requests: Request_2 | Request_2[], renderingType: RenderingType): void;
teardown(): Promise<void>;
}

// Not exported by the entry point; reachable only as a referenced type.
// @public (undocumented)
interface RenderingTypePredictorOptions {
detectionRatio: number;
// (undocumented)
persistenceOptions?: Partial<RecoverableStatePersistenceOptions>;
}

// @public
function saveSnapshot(page: Page, options?: SaveSnapshotOptions): Promise<void>;

// @public (undocumented)
interface SaveSnapshotOptions {
configuration?: Configuration;
key?: string;
keyValueStoreName?: string | null;
saveHtml?: boolean;
saveScreenshot?: boolean;
screenshotQuality?: number;
}


export * from "@crawlee/browser";

// (No @packageDocumentation comment for this package)