mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-16 23:10:29 +00:00
Merge pull request #33499 from uchida/add-definitions-for-createBrowserFetcher-and-BrowserFetcher
[@types/puppeteer] Add definitions for create browser fetcher and browser fetcher
This commit is contained in:
Vendored
+38
@@ -31,6 +31,8 @@ export interface JSONObject {
|
||||
}
|
||||
export type SerializableOrJSHandle = Serializable | JSHandle;
|
||||
|
||||
export type Platform = "mac" | "win32" | "win64" | "linux";
|
||||
|
||||
/** Defines `$eval` and `$$eval` for Page, Frame and ElementHandle. */
|
||||
export interface Evalable {
|
||||
/**
|
||||
@@ -2187,6 +2189,40 @@ export interface CoverageEntry {
|
||||
ranges: Array<{start: number, end: number}>;
|
||||
}
|
||||
|
||||
/** BrowserFetcher can download and manage different versions of Chromium. */
|
||||
export interface BrowserFetcher {
|
||||
/** The method initiates a HEAD request to check if the revision is available. */
|
||||
canDownload(revision: string): Promise<boolean>;
|
||||
/** The method initiates a GET request to download the revision from the host. */
|
||||
download(revision: string, progressCallback?: (downloadBytes: number, totalBytes: number) => void): Promise<RevisionInfo>;
|
||||
localRevisions(): Promise<string[]>;
|
||||
platform(): Platform;
|
||||
remove(revision: string): Promise<void>;
|
||||
revisionInfo(revision: string): RevisionInfo;
|
||||
}
|
||||
|
||||
export interface RevisionInfo {
|
||||
/** The revision the info was created from */
|
||||
revision: string;
|
||||
/** Path to the extracted revision folder */
|
||||
folderPath: string;
|
||||
/** Path to the revision executable */
|
||||
executablePath: string;
|
||||
/** URL this revision can be downloaded from */
|
||||
url: string;
|
||||
/** whether the revision is locally available on disk */
|
||||
local: boolean;
|
||||
}
|
||||
|
||||
export interface FetcherOptions {
|
||||
/** A download host to be used. Defaults to `https://storage.googleapis.com`. */
|
||||
host?: string;
|
||||
/** A path for the downloads folder. Defaults to `<root>/.local-chromium`, where `<root>` is puppeteer's package root. */
|
||||
path?: string;
|
||||
/** Possible values are: `mac`, `win32`, `win64`, `linux`. Defaults to the current platform. */
|
||||
platform?: Platform;
|
||||
}
|
||||
|
||||
/** Attaches Puppeteer to an existing Chromium instance */
|
||||
export function connect(options?: ConnectOptions): Promise<Browser>;
|
||||
/** The default flags that Chromium will be launched with */
|
||||
@@ -2195,3 +2231,5 @@ export function defaultArgs(options?: ChromeArgOptions): string[];
|
||||
export function executablePath(): string;
|
||||
/** The method launches a browser instance with given arguments. The browser will be closed when the parent node.js process is closed. */
|
||||
export function launch(options?: LaunchOptions): Promise<Browser>;
|
||||
/** This methods attaches Puppeteer to an existing Chromium instance. */
|
||||
export function createBrowserFetcher(options?: FetcherOptions): BrowserFetcher;
|
||||
|
||||
@@ -618,3 +618,28 @@ puppeteer.launch().then(async browser => {
|
||||
);
|
||||
console.log('there are', numMatchingEls, 'banana paragaphs');
|
||||
});
|
||||
|
||||
(async () => {
|
||||
const rev = '630727';
|
||||
const defaultFetcher = puppeteer.createBrowserFetcher();
|
||||
const options: puppeteer.FetcherOptions = {
|
||||
host: 'https://storage.googleapis.com',
|
||||
path: '/tmp/.local-chromium',
|
||||
platform: 'linux',
|
||||
};
|
||||
const browserFetcher = puppeteer.createBrowserFetcher(options);
|
||||
const canDownload = await browserFetcher.canDownload(rev);
|
||||
if (canDownload) {
|
||||
const revisionInfo = await browserFetcher.download(rev);
|
||||
const localRevisions = await browserFetcher.localRevisions();
|
||||
const browser = await puppeteer.launch({executablePath: revisionInfo.executablePath});
|
||||
browser.close();
|
||||
if (localRevisions.includes(rev)) {
|
||||
await browserFetcher.remove(rev);
|
||||
}
|
||||
await browserFetcher.download(rev, (download, total) => {
|
||||
console.log('downloadBytes:', download, 'totalBytes:', total);
|
||||
});
|
||||
await browserFetcher.remove(rev);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user