scraping-master
Version:
An awesome package that makes scraping easy
132 lines (112 loc) • 4.01 kB
TypeScript
import {
Browser as PuppeteerBrowser,
Page,
ScreenshotOptions,
ClickOptions,
WaitForOptions,
HTTPResponse,
Cookie,
CookieParam,
WaitForSelectorOptions,
EvaluateFn,
PageEvent
} from 'puppeteer';
declare namespace Browser {
/**
* Initializes the browser instance. This must be called before any other browser operations.
* Throws an error if license validation fails.
*/
function init(): Promise<void>;
/**
* Navigates to a specified URL.
* @param url The URL to navigate to.
*/
function goto(url: string): Promise<void>;
/**
* Fills out and submits a login form.
* @param fields An array of objects, each with a `selector` and `value` for the fields to fill.
* @param submitButton An object with a `selector` for the submit button.
*/
function login(fields: { selector: string; value: string; }[], submitButton: { selector: string; }): Promise<void>;
/**
* Waits for a selector to appear on the page.
* @param selector A selector of an element to wait for.
* @param options Optional waiting parameters.
*/
function waitForSelector(selector: string, options?: WaitForSelectorOptions): Promise<void>;
/**
* Closes the browser instance.
*/
function close(): Promise<void>;
/**
* Executes a function in the browser context.
* @param fn The function to execute.
* @param args Arguments to pass to the function.
*/
function evaluate<T extends EvaluateFn>(fn: T, ...args: Parameters<T>): Promise<ReturnType<T>>;
/**
* Takes a screenshot of the page.
* @param options Screenshot options.
* @returns A promise which resolves to a buffer with the screenshot.
*/
function screenshot(options?: ScreenshotOptions): Promise<Buffer>;
/**
* Gets the text content of an element.
* @param selector The selector of the element.
* @returns The trimmed text content of the element.
*/
function getText(selector: string): Promise<string>;
/**
* Clicks an element on the page.
* @param selector The selector of the element to click.
* @param options Optional click parameters.
*/
function click(selector: string, options?: ClickOptions): Promise<void>;
/**
* Focuses on an element.
* @param selector The selector of the element to focus.
*/
function focus(selector: string): Promise<void>;
/**
* Waits for a navigation to complete.
* @param options Optional waiting parameters.
*/
function waitForNavigation(options?: WaitForOptions): Promise<HTTPResponse | null>;
/**
* Sets a cookie.
* @param cookie The cookie to set.
*/
function setCookie(cookie: CookieParam): Promise<void>;
/**
* Gets the cookies for the current page.
*/
function getCookies(): Promise<Cookie[]>;
/**
* Reloads the current page.
*/
function reload(): Promise<void>;
/**
* Types text into an element.
* @param selector The selector of the element to type into.
* @param text The text to type.
*/
function type(selector: string, text: string): Promise<void>;
/**
* Pauses execution for a specified number of milliseconds.
* @param ms The number of milliseconds to wait.
*/
function delay(ms: number): Promise<void>;
/**
* Listens for a one-time event.
* @param event The event to listen for.
* @param callback The callback function to execute when the event is triggered.
*/
function once(event: PageEvent, callback: (...args: any[]) => void): void;
/**
* Checks if the browser can exit.
* All processes have completed.
* @return True if the browser can exit, false otherwise.
*/
function canExit(): boolean;
}
export = Browser;