cloudflare
Version:
The official TypeScript library for the Cloudflare API
475 lines • 16.2 kB
text/typescript
import { APIResource } from "../../core/resource.mjs";
import { APIPromise } from "../../core/api-promise.mjs";
import { RequestOptions } from "../../internal/request-options.mjs";
export declare class BaseSnapshot extends APIResource {
static readonly _key: readonly ['browserRendering', 'snapshot'];
/**
* Returns the page's HTML content and screenshot. Control page loading with
* `gotoOptions` and `waitFor*` options. Customize screenshots with `viewport`,
* `fullPage`, `clip` and others.
*
* @example
* ```ts
* const snapshot =
* await client.browserRendering.snapshot.create({
* account_id: 'account_id',
* url: 'https://www.example.com/',
* formats: ['content', 'screenshot'],
* });
* ```
*/
create(params: SnapshotCreateParams, options?: RequestOptions): APIPromise<SnapshotCreateResponse>;
}
export declare class Snapshot extends BaseSnapshot {
}
export interface SnapshotCreateResponse {
/**
* Accessibility tree node
*/
accessibilityTree?: SnapshotCreateResponse.AccessibilityTree;
/**
* HTML content.
*/
content?: string;
/**
* Markdown content. Prefixed with YAML frontmatter (e.g. `title`) when the page
* provides that metadata.
*/
markdown?: string;
/**
* Base64 encoded image.
*/
screenshot?: string;
}
export declare namespace SnapshotCreateResponse {
/**
* Accessibility tree node
*/
interface AccessibilityTree {
role: string;
autocomplete?: string;
checked?: boolean | 'mixed';
children?: Array<unknown>;
description?: string;
disabled?: boolean;
expanded?: boolean;
focused?: boolean;
haspopup?: string;
invalid?: string;
keyshortcuts?: string;
level?: number;
modal?: boolean;
multiline?: boolean;
multiselectable?: boolean;
name?: string;
orientation?: string;
pressed?: boolean | 'mixed';
readonly?: boolean;
required?: boolean;
roledescription?: string;
selected?: boolean;
value?: string | number;
valuemax?: number;
valuemin?: number;
valuetext?: string;
}
}
export type SnapshotCreateParams = SnapshotCreateParams.Variant0 | SnapshotCreateParams.Variant1;
export declare namespace SnapshotCreateParams {
interface Variant0 {
/**
* Path param: Account ID.
*/
account_id: string;
/**
* Body param
*/
url: string;
/**
* Query param: Cache TTL default is 5s. Set to 0 to disable.
*/
cacheTTL?: number;
/**
* Body param: The maximum duration allowed for the browser action to complete
* after the page has loaded (such as taking screenshots, extracting content, or
* generating PDFs). If this time limit is exceeded, the action stops and returns a
* timeout error.
*/
actionTimeout?: number;
/**
* Body param: Adds a script element into the page with the desired URL or content.
*/
addScriptTag?: Array<Variant0.AddScriptTag>;
/**
* Body param: Adds a `<link rel="stylesheet">` tag into the page with the desired
* URL or a `<style type="text/css">` tag with the content.
*/
addStyleTag?: Array<Variant0.AddStyleTag>;
/**
* Body param: Only allow requests that match the provided regex patterns, eg.
* '/^.\*\.(css)'. Reject rules are applied first.
*/
allowRequestPattern?: Array<string>;
/**
* Body param: Only allow requests that match the provided resource types, eg.
* 'image' or 'script'. Reject rules are applied first.
*/
allowResourceTypes?: Array<'document' | 'stylesheet' | 'image' | 'media' | 'font' | 'script' | 'texttrack' | 'xhr' | 'fetch' | 'prefetch' | 'eventsource' | 'websocket' | 'manifest' | 'signedexchange' | 'ping' | 'cspviolationreport' | 'preflight' | 'other'>;
/**
* Body param: Provide credentials for HTTP authentication.
*/
authenticate?: Variant0.Authenticate;
/**
* Body param: Attempt to proceed when 'awaited' events fail or timeout.
*/
bestAttempt?: boolean;
/**
* Body param: Check [options](https://pptr.dev/api/puppeteer.page.setcookie).
*/
cookies?: Array<Variant0.Cookie>;
/**
* Body param
*/
emulateMediaType?: string;
/**
* Body param
*/
formats?: Array<'content' | 'screenshot' | 'markdown' | 'accessibilityTree'>;
/**
* Body param: Check [options](https://pptr.dev/api/puppeteer.gotooptions).
*/
gotoOptions?: Variant0.GotoOptions;
/**
* Body param
*/
html?: string;
/**
* Body param: Block undesired requests that match the provided regex patterns, eg.
* '/^.\*\.(css)'.
*/
rejectRequestPattern?: Array<string>;
/**
* Body param: Block undesired requests that match the provided resource types, eg.
* 'image' or 'script'.
*/
rejectResourceTypes?: Array<'document' | 'stylesheet' | 'image' | 'media' | 'font' | 'script' | 'texttrack' | 'xhr' | 'fetch' | 'prefetch' | 'eventsource' | 'websocket' | 'manifest' | 'signedexchange' | 'ping' | 'cspviolationreport' | 'preflight' | 'other'>;
/**
* Body param
*/
screenshotOptions?: Variant0.ScreenshotOptions;
/**
* Body param
*/
setExtraHTTPHeaders?: {
[]: string;
};
/**
* Body param
*/
setJavaScriptEnabled?: boolean;
/**
* Body param
*/
userAgent?: string;
/**
* Body param: Check [options](https://pptr.dev/api/puppeteer.page.setviewport).
*/
viewport?: Variant0.Viewport;
/**
* Body param: Wait for the selector to appear in page. Check
* [options](https://pptr.dev/api/puppeteer.page.waitforselector).
*/
waitForSelector?: Variant0.WaitForSelector;
/**
* Body param: Waits for a specified timeout before continuing.
*/
waitForTimeout?: number;
}
namespace Variant0 {
interface AddScriptTag {
id?: string;
content?: string;
type?: string;
url?: string;
}
interface AddStyleTag {
content?: string;
url?: string;
}
/**
* Provide credentials for HTTP authentication.
*/
interface Authenticate {
password: string;
username: string;
}
interface Cookie {
/**
* Cookie name.
*/
name: string;
value: string;
domain?: string;
expires?: number;
httpOnly?: boolean;
partitionKey?: string;
path?: string;
priority?: 'Low' | 'Medium' | 'High';
sameParty?: boolean;
sameSite?: 'Strict' | 'Lax' | 'None';
secure?: boolean;
sourcePort?: number;
sourceScheme?: 'Unset' | 'NonSecure' | 'Secure';
url?: string;
}
/**
* Check [options](https://pptr.dev/api/puppeteer.gotooptions).
*/
interface GotoOptions {
referer?: string;
referrerPolicy?: string;
timeout?: number;
waitUntil?: 'load' | 'domcontentloaded' | 'networkidle0' | 'networkidle2' | Array<'load' | 'domcontentloaded' | 'networkidle0' | 'networkidle2'>;
}
interface ScreenshotOptions {
captureBeyondViewport?: boolean;
clip?: ScreenshotOptions.Clip;
fromSurface?: boolean;
fullPage?: boolean;
omitBackground?: boolean;
optimizeForSpeed?: boolean;
quality?: number;
type?: 'png' | 'jpeg' | 'webp';
}
namespace ScreenshotOptions {
interface Clip {
height: number;
width: number;
x: number;
y: number;
scale?: number;
}
}
/**
* Check [options](https://pptr.dev/api/puppeteer.page.setviewport).
*/
interface Viewport {
height: number;
width: number;
deviceScaleFactor?: number;
hasTouch?: boolean;
isLandscape?: boolean;
isMobile?: boolean;
}
/**
* Wait for the selector to appear in page. Check
* [options](https://pptr.dev/api/puppeteer.page.waitforselector).
*/
interface WaitForSelector {
selector: string;
hidden?: true;
timeout?: number;
visible?: true;
}
}
interface Variant1 {
/**
* Path param: Account ID.
*/
account_id: string;
/**
* Body param
*/
html: string;
/**
* Query param: Cache TTL default is 5s. Set to 0 to disable.
*/
cacheTTL?: number;
/**
* Body param: The maximum duration allowed for the browser action to complete
* after the page has loaded (such as taking screenshots, extracting content, or
* generating PDFs). If this time limit is exceeded, the action stops and returns a
* timeout error.
*/
actionTimeout?: number;
/**
* Body param: Adds a script element into the page with the desired URL or content.
*/
addScriptTag?: Array<Variant1.AddScriptTag>;
/**
* Body param: Adds a `<link rel="stylesheet">` tag into the page with the desired
* URL or a `<style type="text/css">` tag with the content.
*/
addStyleTag?: Array<Variant1.AddStyleTag>;
/**
* Body param: Only allow requests that match the provided regex patterns, eg.
* '/^.\*\.(css)'. Reject rules are applied first.
*/
allowRequestPattern?: Array<string>;
/**
* Body param: Only allow requests that match the provided resource types, eg.
* 'image' or 'script'. Reject rules are applied first.
*/
allowResourceTypes?: Array<'document' | 'stylesheet' | 'image' | 'media' | 'font' | 'script' | 'texttrack' | 'xhr' | 'fetch' | 'prefetch' | 'eventsource' | 'websocket' | 'manifest' | 'signedexchange' | 'ping' | 'cspviolationreport' | 'preflight' | 'other'>;
/**
* Body param: Provide credentials for HTTP authentication.
*/
authenticate?: Variant1.Authenticate;
/**
* Body param: Attempt to proceed when 'awaited' events fail or timeout.
*/
bestAttempt?: boolean;
/**
* Body param: Check [options](https://pptr.dev/api/puppeteer.page.setcookie).
*/
cookies?: Array<Variant1.Cookie>;
/**
* Body param
*/
emulateMediaType?: string;
/**
* Body param
*/
formats?: Array<'content' | 'screenshot' | 'markdown' | 'accessibilityTree'>;
/**
* Body param: Check [options](https://pptr.dev/api/puppeteer.gotooptions).
*/
gotoOptions?: Variant1.GotoOptions;
/**
* Body param: Block undesired requests that match the provided regex patterns, eg.
* '/^.\*\.(css)'.
*/
rejectRequestPattern?: Array<string>;
/**
* Body param: Block undesired requests that match the provided resource types, eg.
* 'image' or 'script'.
*/
rejectResourceTypes?: Array<'document' | 'stylesheet' | 'image' | 'media' | 'font' | 'script' | 'texttrack' | 'xhr' | 'fetch' | 'prefetch' | 'eventsource' | 'websocket' | 'manifest' | 'signedexchange' | 'ping' | 'cspviolationreport' | 'preflight' | 'other'>;
/**
* Body param
*/
screenshotOptions?: Variant1.ScreenshotOptions;
/**
* Body param
*/
setExtraHTTPHeaders?: {
[]: string;
};
/**
* Body param
*/
setJavaScriptEnabled?: boolean;
/**
* Body param
*/
url?: string;
/**
* Body param
*/
userAgent?: string;
/**
* Body param: Check [options](https://pptr.dev/api/puppeteer.page.setviewport).
*/
viewport?: Variant1.Viewport;
/**
* Body param: Wait for the selector to appear in page. Check
* [options](https://pptr.dev/api/puppeteer.page.waitforselector).
*/
waitForSelector?: Variant1.WaitForSelector;
/**
* Body param: Waits for a specified timeout before continuing.
*/
waitForTimeout?: number;
}
namespace Variant1 {
interface AddScriptTag {
id?: string;
content?: string;
type?: string;
url?: string;
}
interface AddStyleTag {
content?: string;
url?: string;
}
/**
* Provide credentials for HTTP authentication.
*/
interface Authenticate {
password: string;
username: string;
}
interface Cookie {
/**
* Cookie name.
*/
name: string;
value: string;
domain?: string;
expires?: number;
httpOnly?: boolean;
partitionKey?: string;
path?: string;
priority?: 'Low' | 'Medium' | 'High';
sameParty?: boolean;
sameSite?: 'Strict' | 'Lax' | 'None';
secure?: boolean;
sourcePort?: number;
sourceScheme?: 'Unset' | 'NonSecure' | 'Secure';
url?: string;
}
/**
* Check [options](https://pptr.dev/api/puppeteer.gotooptions).
*/
interface GotoOptions {
referer?: string;
referrerPolicy?: string;
timeout?: number;
waitUntil?: 'load' | 'domcontentloaded' | 'networkidle0' | 'networkidle2' | Array<'load' | 'domcontentloaded' | 'networkidle0' | 'networkidle2'>;
}
interface ScreenshotOptions {
captureBeyondViewport?: boolean;
clip?: ScreenshotOptions.Clip;
fromSurface?: boolean;
fullPage?: boolean;
omitBackground?: boolean;
optimizeForSpeed?: boolean;
quality?: number;
type?: 'png' | 'jpeg' | 'webp';
}
namespace ScreenshotOptions {
interface Clip {
height: number;
width: number;
x: number;
y: number;
scale?: number;
}
}
/**
* Check [options](https://pptr.dev/api/puppeteer.page.setviewport).
*/
interface Viewport {
height: number;
width: number;
deviceScaleFactor?: number;
hasTouch?: boolean;
isLandscape?: boolean;
isMobile?: boolean;
}
/**
* Wait for the selector to appear in page. Check
* [options](https://pptr.dev/api/puppeteer.page.waitforselector).
*/
interface WaitForSelector {
selector: string;
hidden?: true;
timeout?: number;
visible?: true;
}
}
}
export declare namespace Snapshot {
export { type SnapshotCreateResponse as SnapshotCreateResponse, type SnapshotCreateParams as SnapshotCreateParams, };
}
//# sourceMappingURL=snapshot.d.mts.map