@d-zero/puppeteer-dealer 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,28 @@
1
+ import type { Logger } from './types.js';
2
+ import type { Page } from 'puppeteer';
3
+ export type ChildProcessMethods<R> = {
4
+ eachPage: (params: EachPageParams, logger: Logger) => Promise<R>;
5
+ };
6
+ type EachPageParams = {
7
+ readonly page: Page;
8
+ readonly id: string;
9
+ readonly url: string;
10
+ readonly index: number;
11
+ };
12
+ export type ChildProcessCommonParams = {
13
+ readonly id: string;
14
+ readonly url: string;
15
+ readonly logger: Logger;
16
+ };
17
+ export type ChildProcessHandler<P, R> = (params: P) => Promise<ChildProcessMethods<R>> | ChildProcessMethods<R>;
18
+ export type ChildProcessCommands<P, R> = {
19
+ init: () => Promise<P>;
20
+ each: (id: string, url: string, index: number) => Promise<R>;
21
+ log: Logger;
22
+ };
23
+ /**
24
+ *
25
+ * @param handler
26
+ */
27
+ export declare function createChildProcess<P, R = void>(handler: ChildProcessHandler<P, R>): void;
28
+ export {};
@@ -0,0 +1,59 @@
1
+ import { ProcTalk } from '@d-zero/proc-talk';
2
+ import puppeteer from 'puppeteer';
3
+ import { log } from './debug.js';
4
+ const childLog = log.extend(`child:${process.pid}`);
5
+ /**
6
+ *
7
+ * @param handler
8
+ */
9
+ export function createChildProcess(handler) {
10
+ new ProcTalk({
11
+ type: 'child',
12
+ title: '@d-zero/puppeteer-dealer',
13
+ async process(options) {
14
+ const config = {
15
+ locale: 'ja-JP',
16
+ ...options,
17
+ };
18
+ childLog('Process started: %O', config);
19
+ const params = await this.call('init');
20
+ childLog('Params: %O', params);
21
+ const { eachPage } = await handler(params);
22
+ const launchOptions = {
23
+ headless: true,
24
+ args: [
25
+ //
26
+ `--lang=${config.locale}`,
27
+ '--no-zygote',
28
+ '--ignore-certificate-errors',
29
+ ],
30
+ ...config,
31
+ };
32
+ childLog('Launch options: %O', launchOptions);
33
+ const browser = await puppeteer.launch(launchOptions);
34
+ const page = await browser?.newPage();
35
+ if (!page) {
36
+ throw new Error('Failed to create page');
37
+ }
38
+ page.setDefaultNavigationTimeout(0);
39
+ if (config.locale) {
40
+ await page.setExtraHTTPHeaders({
41
+ 'Accept-Language': config.locale,
42
+ });
43
+ }
44
+ childLog('Page is ready');
45
+ this.bind('each', async (id, url, index) => {
46
+ const result = await eachPage({ page, id, url, index }, async (log) => {
47
+ await this.call('log', log);
48
+ });
49
+ return result;
50
+ });
51
+ return async () => {
52
+ childLog('Close page and browser');
53
+ await page.close();
54
+ await browser.close();
55
+ childLog('Cleanup done');
56
+ };
57
+ },
58
+ });
59
+ }
@@ -0,0 +1,17 @@
1
+ import type { Logger, PuppeteerDealerOptions } from './types.js';
2
+ import type { LaunchOptions } from 'puppeteer';
3
+ /**
4
+ *
5
+ * @param subModulePath
6
+ * @param params
7
+ * @param options
8
+ */
9
+ export declare function createProcess<P, R = void>(subModulePath: string, params: P, options?: PuppeteerDealerOptions & LaunchOptions): ChildProcessManager<P, R>;
10
+ export declare class ChildProcessManager<P, R> {
11
+ #private;
12
+ constructor(subModulePath: string, params: P, options?: PuppeteerDealerOptions & LaunchOptions);
13
+ close(): Promise<void>;
14
+ each(id: string, url: string, index: number): Promise<R>;
15
+ log(logger: Logger): void;
16
+ ready(): Promise<void>;
17
+ }
@@ -0,0 +1,33 @@
1
+ import { ProcTalk } from '@d-zero/proc-talk';
2
+ /**
3
+ *
4
+ * @param subModulePath
5
+ * @param params
6
+ * @param options
7
+ */
8
+ export function createProcess(subModulePath, params, options) {
9
+ return new ChildProcessManager(subModulePath, params, options);
10
+ }
11
+ export class ChildProcessManager {
12
+ #procTalk;
13
+ constructor(subModulePath, params, options) {
14
+ this.#procTalk = new ProcTalk({
15
+ type: 'main',
16
+ subModulePath,
17
+ options,
18
+ });
19
+ this.#procTalk.bind('init', () => Promise.resolve(params));
20
+ }
21
+ async close() {
22
+ await this.#procTalk.close();
23
+ }
24
+ async each(id, url, index) {
25
+ return await this.#procTalk.call('each', id, url, index);
26
+ }
27
+ log(logger) {
28
+ this.#procTalk.bind('log', logger);
29
+ }
30
+ async ready() {
31
+ await this.#procTalk.initialized();
32
+ }
33
+ }
package/dist/deal.d.ts CHANGED
@@ -1,4 +1,11 @@
1
- import type { PuppeteerDealerOptions, PuppeteerDealHandler, URLInfo } from './types.js';
1
+ import type { ChildProcessManager } from './create-main-process.js';
2
+ import type { URLInfo } from './types.js';
2
3
  import type { DealHeader } from '@d-zero/dealer';
3
- import type { PuppeteerLaunchOptions } from 'puppeteer';
4
- export declare function deal(list: readonly URLInfo[], header: DealHeader, handler: PuppeteerDealHandler, options?: PuppeteerDealerOptions & PuppeteerLaunchOptions): Promise<void>;
4
+ /**
5
+ *
6
+ * @param list
7
+ * @param header
8
+ * @param createProcess
9
+ * @param each
10
+ */
11
+ export declare function deal<T extends Record<string, unknown>, R = void>(list: readonly URLInfo[], header: DealHeader, createProcess: () => ChildProcessManager<T, R>, each?: (result: R) => void | Promise<void>): Promise<void>;
package/dist/deal.js CHANGED
@@ -1,93 +1,30 @@
1
1
  import { deal as coreDeal } from '@d-zero/dealer';
2
- import { createPage } from '@d-zero/puppeteer-page';
3
- import { delay } from '@d-zero/shared/delay';
4
2
  import c from 'ansi-colors';
5
- import { log } from './debug.js';
6
- export async function deal(list, header, handler, options) {
7
- const config = {
8
- locale: 'ja-JP',
9
- ...options,
10
- };
11
- const childPrecessIds = new Set();
12
- const cleanUp = () => {
13
- log('child process IDs: %o', childPrecessIds);
14
- for (const pid of childPrecessIds) {
15
- try {
16
- process.kill(pid);
17
- log('killed %d', pid);
18
- }
19
- catch (error) {
20
- log('Already dead: %d', pid);
21
- if (error instanceof Error && 'code' in error && error.code === 'ESRCH') {
22
- // ignore
23
- continue;
24
- }
25
- throw error;
26
- }
27
- }
28
- if (log.enabled) {
29
- log('process.getActiveResourcesInfo(): %o', process.getActiveResourcesInfo());
30
- }
31
- };
32
- process.on('exit', cleanUp);
33
- await coreDeal(list, ({ id, url }, update, index) => {
3
+ /**
4
+ *
5
+ * @param list
6
+ * @param header
7
+ * @param createProcess
8
+ * @param each
9
+ */
10
+ export function deal(list, header, createProcess, each) {
11
+ return coreDeal(list, ({ id, url }, update, index) => {
34
12
  const fileId = id || index.toString().padStart(3, '0');
35
13
  const lineHeader = `%braille% ${c.bgWhite(` ${fileId} `)} ${c.gray(url.toString())}: `;
36
14
  return async () => {
37
- const continued = await handler.beforeOpenPage?.(fileId, url.toString(), (log) => update(`${lineHeader}${log}`), index);
38
- if (continued === false) {
39
- return;
40
- }
41
- const page = await createPage({
42
- headless: true,
43
- args: [
44
- //
45
- `--lang=${config.locale}`,
46
- '--no-zygote',
47
- '--ignore-certificate-errors',
48
- ],
49
- ...config,
15
+ const processManager = createProcess();
16
+ update(`${lineHeader}Booting ChildProcess%dots%`);
17
+ await processManager.ready();
18
+ processManager.log((log) => {
19
+ update(`${lineHeader}${log}`);
50
20
  });
51
- if (page.pid !== null) {
52
- childPrecessIds.add(page.pid);
21
+ const result = await processManager.each(fileId, url.toString(), index);
22
+ if (each) {
23
+ await each(result);
53
24
  }
54
- await page.setDefaultNavigationTimeout(0);
55
- if (config.locale) {
56
- await page.setExtraHTTPHeaders({
57
- 'Accept-Language': config.locale,
58
- });
59
- }
60
- await handler
61
- .deal(page, fileId, url.toString(), (log) => update(`${lineHeader}${log}`), index)
62
- .catch(evaluationError(page, url.toString(), fileId, index));
63
- update(`${lineHeader} ${c.blue('✓')} Closing page%dots%`);
64
- await page.close();
65
- update(`${lineHeader} ${c.greenBright('✓')} Page process completed!`);
66
- await delay(600);
25
+ await processManager.close();
67
26
  };
68
27
  }, {
69
- ...config,
70
28
  header,
71
29
  });
72
- log('PuppeteerDealer.deal() completed');
73
- }
74
- function evaluationError(page, url, fileId, index) {
75
- return (error) => {
76
- if (error instanceof Error &&
77
- error.message.includes('Execution context was destroyed')) {
78
- error.message +=
79
- '\n' +
80
- c.red([
81
- `PuppeteerDealer.deal() failed:`,
82
- ` URL: ${url}`,
83
- ` ID: ${fileId}`,
84
- ` Index: ${index}`,
85
- ' Page:',
86
- ` url: ${page.url()}`,
87
- ` isClosed: ${page.isClosed()}`,
88
- ].join('\n'));
89
- throw error;
90
- }
91
- throw error;
92
- };
93
30
  }
package/dist/index.d.ts CHANGED
@@ -1,2 +1,4 @@
1
1
  export { deal } from './deal.js';
2
+ export { createChildProcess } from './create-child-process.js';
3
+ export { createProcess } from './create-main-process.js';
2
4
  export * from './types.js';
package/dist/index.js CHANGED
@@ -1,2 +1,4 @@
1
1
  export { deal } from './deal.js';
2
+ export { createChildProcess } from './create-child-process.js';
3
+ export { createProcess } from './create-main-process.js';
2
4
  export * from './types.js';
package/dist/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { DealOptions } from '@d-zero/dealer';
2
- import type { Page } from '@d-zero/puppeteer-page';
2
+ import type { Page } from 'puppeteer';
3
3
  export type PuppeteerDealerOptions = {
4
4
  readonly locale?: string;
5
5
  } & DealOptions;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@d-zero/puppeteer-dealer",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "Puppeteer handles each page",
5
5
  "author": "D-ZERO",
6
6
  "license": "MIT",
@@ -24,14 +24,17 @@
24
24
  "clean": "tsc --build --clean"
25
25
  },
26
26
  "dependencies": {
27
- "@d-zero/dealer": "1.2.0",
28
- "@d-zero/puppeteer-page": "0.2.0",
29
- "@d-zero/shared": "0.6.0",
27
+ "@d-zero/dealer": "1.3.1",
28
+ "@d-zero/proc-talk": "0.4.0",
29
+ "@d-zero/shared": "0.8.0",
30
30
  "ansi-colors": "4.1.3",
31
- "debug": "4.3.7"
31
+ "debug": "4.4.1"
32
32
  },
33
33
  "devDependencies": {
34
- "puppeteer": "23.6.1"
34
+ "puppeteer": "24.9.0"
35
35
  },
36
- "gitHead": "1eb1c03400580040119121e11ffb33acd876fe1b"
36
+ "peerDependencies": {
37
+ "puppeteer": "24.8.2"
38
+ },
39
+ "gitHead": "4e9cc7b87e0fef91b6f2d4edfb66ca9134b2491b"
37
40
  }
@@ -1,5 +0,0 @@
1
- import type { Page, PuppeteerLaunchOptions } from 'puppeteer';
2
- export declare function createPage(options?: PuppeteerLaunchOptions): Promise<{
3
- page: Page;
4
- pid: number;
5
- }>;
@@ -1,7 +0,0 @@
1
- import { ChildProcessHostedPuppeteerPage } from './puppeteer-page-main-process.js';
2
- export async function createPage(options) {
3
- const page = new ChildProcessHostedPuppeteerPage(options);
4
- await page.initialized();
5
- const pid = page.pid;
6
- return { page, pid };
7
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,29 +0,0 @@
1
- /* use as a sub-process */
2
- import { ProcTalk } from '@d-zero/proc-talk';
3
- import puppeteer from 'puppeteer';
4
- process.title = '@d-zero/puppeteer-dealer:child-process';
5
- new ProcTalk({
6
- type: 'child',
7
- async process(options) {
8
- this.log('Starting puppeteer: %O', options);
9
- const browser = await puppeteer.launch(options);
10
- const page = await browser?.newPage();
11
- const cleanUp = async () => {
12
- this.log('Cleanup start');
13
- await page?.close();
14
- await browser?.close();
15
- this.log('Cleanup done');
16
- };
17
- this.bind('evaluate', page.evaluate.bind(page));
18
- this.bind('goto', page.goto.bind(page));
19
- this.bind('title', page.title.bind(page));
20
- this.bind('setDefaultNavigationTimeout', page.setDefaultNavigationTimeout.bind(page));
21
- this.bind('setViewport', page.setViewport.bind(page));
22
- this.bind('screenshot', page.screenshot.bind(page));
23
- this.bind('reload', page.reload.bind(page));
24
- this.bind('on', page.on.bind(page));
25
- this.bind('close', async () => {
26
- await cleanUp();
27
- });
28
- },
29
- });
@@ -1,84 +0,0 @@
1
- import type { Browser, BrowserContext, CDPSession, Cookie, CookieParam, Coverage, Credentials, DeleteCookiesRequest, Device, DeviceRequestPrompt, EvaluateFunc, EvaluateFuncWith, EventsWithWildcard, FileChooser, Frame, GoToOptions, HandleFor, HTTPResponse, JSHandle, Keyboard, MediaFeature, Metrics, Mouse, NetworkConditions, NewDocumentScriptEvaluation, NodeFor, PageEvents, PDFOptions, Protocol, PuppeteerLaunchOptions, Target, Touchscreen, Tracing, Viewport, WaitForOptions, WaitTimeoutOptions, WebWorker } from 'puppeteer';
2
- import type { ParseSelector } from 'typed-query-selector/parser.js';
3
- import { ProcTalk } from '@d-zero/proc-talk';
4
- import { Page } from 'puppeteer';
5
- export declare class ChildProcessHostedPuppeteerPage extends Page {
6
- #private;
7
- readonly process: ProcTalk<Page, PuppeteerLaunchOptions>;
8
- get mouse(): Mouse;
9
- get tracing(): Tracing;
10
- get coverage(): Coverage;
11
- get keyboard(): Keyboard;
12
- get touchscreen(): Touchscreen;
13
- get pid(): number;
14
- constructor(options?: PuppeteerLaunchOptions);
15
- initialized(): Promise<void>;
16
- url(): string;
17
- waitForDevicePrompt(options?: WaitTimeoutOptions): Promise<DeviceRequestPrompt>;
18
- setViewport(viewport: Viewport | null): Promise<void>;
19
- viewport(): Viewport | null;
20
- pdf(options?: PDFOptions): Promise<Uint8Array>;
21
- title(): Promise<string>;
22
- close(options?: {
23
- runBeforeUnload?: boolean;
24
- }): Promise<void>;
25
- isClosed(): boolean;
26
- emulate(device: Device): Promise<void>;
27
- emit<Key extends keyof PageEvents>(type: Key, event: EventsWithWildcard<PageEvents>[Key]): boolean;
28
- emulateCPUThrottling(factor: number | null): Promise<void>;
29
- emulateIdleState(overrides?: {
30
- isUserActive: boolean;
31
- isScreenUnlocked: boolean;
32
- }): Promise<void>;
33
- emulateMediaFeatures(features?: MediaFeature[]): Promise<void>;
34
- emulateMediaType(type?: string): Promise<void>;
35
- emulateTimezone(timezoneId?: string): Promise<void>;
36
- emulateVisionDeficiency(type?: Protocol.Emulation.SetEmulatedVisionDeficiencyRequest['type']): Promise<void>;
37
- removeScriptToEvaluateOnNewDocument(identifier: string): Promise<void>;
38
- evaluate<Params extends unknown[], Func extends EvaluateFunc<Params> = EvaluateFunc<Params>>(pageFunction: Func | string, ...args: Params): Promise<Awaited<ReturnType<Func>>>;
39
- evaluateHandle<Params extends unknown[], Func extends EvaluateFunc<Params> = EvaluateFunc<Params>>(pageFunction: Func | string, ...args: Params): Promise<HandleFor<Awaited<ReturnType<Func>>>>;
40
- evaluateOnNewDocument<Params extends unknown[], Func extends (...args: Params) => unknown = (...args: Params) => unknown>(pageFunction: Func | string, ...args: Params): Promise<NewDocumentScriptEvaluation>;
41
- $eval<Selector extends string, Params extends unknown[], Func extends EvaluateFuncWith<NodeFor<Selector>, Params> = EvaluateFuncWith<ParseSelector<Selector, Element>, Params>>(selector: Selector, pageFunction: Func | string, ...args: Params): Promise<Awaited<ReturnType<Func>>>;
42
- $$eval<Selector extends string, Params extends unknown[], Func extends EvaluateFuncWith<Array<NodeFor<Selector>>, Params> = EvaluateFuncWith<ParseSelector<Selector, Element>[], Params>>(selector: Selector, pageFunction: Func | string, ...args: Params): Promise<Awaited<ReturnType<Func>>>;
43
- setCacheEnabled(enabled?: boolean): Promise<void>;
44
- setBypassCSP(enabled: boolean): Promise<void>;
45
- setJavaScriptEnabled(enabled: boolean): Promise<void>;
46
- goBack(options?: WaitForOptions): Promise<HTTPResponse | null>;
47
- goForward(options?: WaitForOptions): Promise<HTTPResponse | null>;
48
- goto(url: string, options?: GoToOptions): Promise<HTTPResponse | null>;
49
- reload(options?: WaitForOptions): Promise<HTTPResponse | null>;
50
- metrics(): Promise<Metrics>;
51
- setUserAgent(userAgent: string, userAgentMetadata?: Protocol.Emulation.UserAgentMetadata): Promise<void>;
52
- setExtraHTTPHeaders(headers: Record<string, string>): Promise<void>;
53
- authenticate(credentials: Credentials | null): Promise<void>;
54
- removeExposedFunction(name: string): Promise<void>;
55
- exposeFunction(name: string, pptrFunction: Function | {
56
- default: Function;
57
- }): Promise<void>;
58
- setCookie(...cookies: CookieParam[]): Promise<void>;
59
- deleteCookie(...cookies: DeleteCookiesRequest[]): Promise<void>;
60
- cookies(...urls: string[]): Promise<Cookie[]>;
61
- queryObjects<Prototype>(prototypeHandle: JSHandle<Prototype>): Promise<JSHandle<Prototype[]>>;
62
- setDefaultTimeout(timeout: number): void;
63
- getDefaultTimeout(): number;
64
- setDefaultNavigationTimeout(timeout: number): void;
65
- setOfflineMode(enabled: boolean): Promise<void>;
66
- emulateNetworkConditions(networkConditions: NetworkConditions | null): Promise<void>;
67
- setDragInterception(enabled: boolean): Promise<void>;
68
- setBypassServiceWorker(bypass: boolean): Promise<void>;
69
- setRequestInterception(value: boolean): Promise<void>;
70
- workers(): WebWorker[];
71
- frames(): Frame[];
72
- createPDFStream(options?: PDFOptions): Promise<ReadableStream<Uint8Array>>;
73
- createCDPSession(): Promise<CDPSession>;
74
- mainFrame(): Frame;
75
- browser(): Browser;
76
- bringToFront(): Promise<void>;
77
- browserContext(): BrowserContext;
78
- target(): Target;
79
- setGeolocation(): Promise<void>;
80
- waitForFileChooser(): Promise<FileChooser>;
81
- isJavaScriptEnabled(): boolean;
82
- isDragInterceptionEnabled(): boolean;
83
- isServiceWorkerBypassed(): boolean;
84
- }
@@ -1,358 +0,0 @@
1
- var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
2
- function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
3
- var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
4
- var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
5
- var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
6
- var _, done = false;
7
- for (var i = decorators.length - 1; i >= 0; i--) {
8
- var context = {};
9
- for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
10
- for (var p in contextIn.access) context.access[p] = contextIn.access[p];
11
- context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
12
- var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
13
- if (kind === "accessor") {
14
- if (result === void 0) continue;
15
- if (result === null || typeof result !== "object") throw new TypeError("Object expected");
16
- if (_ = accept(result.get)) descriptor.get = _;
17
- if (_ = accept(result.set)) descriptor.set = _;
18
- if (_ = accept(result.init)) initializers.unshift(_);
19
- }
20
- else if (_ = accept(result)) {
21
- if (kind === "field") initializers.unshift(_);
22
- else descriptor[key] = _;
23
- }
24
- }
25
- if (target) Object.defineProperty(target, contextIn.name, descriptor);
26
- done = true;
27
- };
28
- var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
29
- var useValue = arguments.length > 2;
30
- for (var i = 0; i < initializers.length; i++) {
31
- value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
32
- }
33
- return useValue ? value : void 0;
34
- };
35
- import path from 'node:path';
36
- import { ProcTalk } from '@d-zero/proc-talk';
37
- import { raceWithTimeout } from '@d-zero/shared/race-with-timeout';
38
- import { Page } from 'puppeteer';
39
- import { log } from './debug.js';
40
- const SUB_PROCESS_PATH = path.resolve(import.meta.dirname, 'puppeteer-page-child-process.js');
41
- let ChildProcessHostedPuppeteerPage = (() => {
42
- let _classDecorators = [UnsafeDefineMethods(['screenshot', 'on'])];
43
- let _classDescriptor;
44
- let _classExtraInitializers = [];
45
- let _classThis;
46
- let _classSuper = Page;
47
- var ChildProcessHostedPuppeteerPage = class extends _classSuper {
48
- static { _classThis = this; }
49
- static {
50
- const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
51
- __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
52
- ChildProcessHostedPuppeteerPage = _classThis = _classDescriptor.value;
53
- if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
54
- __runInitializers(_classThis, _classExtraInitializers);
55
- }
56
- process;
57
- #url = 'about:blank';
58
- get mouse() {
59
- throw new Error('Not implemented');
60
- }
61
- get tracing() {
62
- throw new Error('Not implemented');
63
- }
64
- get coverage() {
65
- throw new Error('Not implemented');
66
- }
67
- get keyboard() {
68
- throw new Error('Not implemented');
69
- }
70
- get touchscreen() {
71
- throw new Error('Not implemented');
72
- }
73
- get pid() {
74
- return this.process.pid;
75
- }
76
- constructor(options) {
77
- super();
78
- this.process = new ProcTalk({
79
- type: 'main',
80
- subModulePath: SUB_PROCESS_PATH,
81
- options,
82
- });
83
- }
84
- async initialized() {
85
- return await this.process.initialized();
86
- }
87
- url() {
88
- return this.#url;
89
- }
90
- waitForDevicePrompt(options) {
91
- void options;
92
- throw new Error('Not implemented');
93
- }
94
- async setViewport(viewport) {
95
- return await this.process.call('setViewport', viewport);
96
- }
97
- viewport() {
98
- throw new Error('Not implemented');
99
- }
100
- pdf(options) {
101
- void options;
102
- throw new Error('Not implemented');
103
- }
104
- async title() {
105
- return await this.process.call('title');
106
- }
107
- async close(options) {
108
- const TIME_OUT = 30_000;
109
- log('Closing page(%d)', this.process.pid);
110
- const { timeout } = await raceWithTimeout(async () => {
111
- await this.process.call('close', options);
112
- }, TIME_OUT);
113
- if (timeout) {
114
- log('Timeout(%dms) closing page', TIME_OUT);
115
- }
116
- const closed = this.process.close();
117
- if (!closed) {
118
- log('Need force killing process(%d)', this.process.pid);
119
- }
120
- log('Closed page(%d)', this.process.pid);
121
- }
122
- isClosed() {
123
- throw new Error('Not implemented');
124
- }
125
- emulate(device) {
126
- void device;
127
- throw new Error('Not implemented');
128
- }
129
- emit(type, event) {
130
- void type;
131
- void event;
132
- throw new Error('Not implemented');
133
- }
134
- emulateCPUThrottling(factor) {
135
- void factor;
136
- throw new Error('Not implemented');
137
- }
138
- emulateIdleState(overrides) {
139
- void overrides;
140
- throw new Error('Not implemented');
141
- }
142
- emulateMediaFeatures(features) {
143
- void features;
144
- throw new Error('Not implemented');
145
- }
146
- emulateMediaType(type) {
147
- void type;
148
- throw new Error('Not implemented');
149
- }
150
- emulateTimezone(timezoneId) {
151
- void timezoneId;
152
- throw new Error('Not implemented');
153
- }
154
- emulateVisionDeficiency(type) {
155
- void type;
156
- throw new Error('Not implemented');
157
- }
158
- removeScriptToEvaluateOnNewDocument(identifier) {
159
- void identifier;
160
- throw new Error('Not implemented');
161
- }
162
- evaluate(pageFunction, ...args) {
163
- return this.process.call('evaluate',
164
- // @ts-ignore
165
- pageFunction, ...args);
166
- }
167
- evaluateHandle(pageFunction, ...args) {
168
- void pageFunction;
169
- void args;
170
- throw new Error('Not implemented');
171
- }
172
- evaluateOnNewDocument(pageFunction, ...args) {
173
- void pageFunction;
174
- void args;
175
- throw new Error('Not implemented');
176
- }
177
- $eval(selector, pageFunction, ...args) {
178
- void selector;
179
- void pageFunction;
180
- void args;
181
- throw new Error('Not implemented');
182
- }
183
- $$eval(selector, pageFunction, ...args) {
184
- void selector;
185
- void pageFunction;
186
- void args;
187
- throw new Error('Not implemented');
188
- }
189
- setCacheEnabled(enabled) {
190
- void enabled;
191
- throw new Error('Not implemented');
192
- }
193
- setBypassCSP(enabled) {
194
- void enabled;
195
- throw new Error('Not implemented');
196
- }
197
- setJavaScriptEnabled(enabled) {
198
- void enabled;
199
- throw new Error('Not implemented');
200
- }
201
- goBack(options) {
202
- void options;
203
- throw new Error('Not implemented');
204
- }
205
- goForward(options) {
206
- void options;
207
- throw new Error('Not implemented');
208
- }
209
- async goto(url, options) {
210
- this.#url = url;
211
- return await this.process.call('goto', url, options);
212
- }
213
- async reload(options) {
214
- return await this.process.call('reload', options);
215
- }
216
- metrics() {
217
- throw new Error('Not implemented');
218
- }
219
- setUserAgent(userAgent, userAgentMetadata) {
220
- void userAgent;
221
- void userAgentMetadata;
222
- throw new Error('Not implemented');
223
- }
224
- setExtraHTTPHeaders(headers) {
225
- void headers;
226
- throw new Error('Not implemented');
227
- }
228
- authenticate(credentials) {
229
- void credentials;
230
- throw new Error('Not implemented');
231
- }
232
- removeExposedFunction(name) {
233
- void name;
234
- throw new Error('Not implemented');
235
- }
236
- exposeFunction(name,
237
- // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
238
- pptrFunction) {
239
- void name;
240
- void pptrFunction; // cspell: disable-line
241
- throw new Error('Not implemented');
242
- }
243
- setCookie(...cookies) {
244
- void cookies;
245
- throw new Error('Not implemented');
246
- }
247
- deleteCookie(...cookies) {
248
- void cookies;
249
- throw new Error('Not implemented');
250
- }
251
- cookies(...urls) {
252
- void urls;
253
- throw new Error('Not implemented');
254
- }
255
- queryObjects(prototypeHandle) {
256
- void prototypeHandle;
257
- throw new Error('Not implemented');
258
- }
259
- setDefaultTimeout(timeout) {
260
- void timeout;
261
- throw new Error('Not implemented');
262
- }
263
- getDefaultTimeout() {
264
- throw new Error('Not implemented');
265
- }
266
- setDefaultNavigationTimeout(timeout) {
267
- this.process.callSync('setDefaultNavigationTimeout', timeout);
268
- }
269
- setOfflineMode(enabled) {
270
- void enabled;
271
- throw new Error('Not implemented');
272
- }
273
- emulateNetworkConditions(networkConditions) {
274
- void networkConditions;
275
- throw new Error('Not implemented');
276
- }
277
- setDragInterception(enabled) {
278
- void enabled;
279
- throw new Error('Not implemented');
280
- }
281
- setBypassServiceWorker(bypass) {
282
- void bypass;
283
- throw new Error('Not implemented');
284
- }
285
- setRequestInterception(value) {
286
- void value;
287
- throw new Error('Not implemented');
288
- }
289
- workers() {
290
- throw new Error('Not implemented');
291
- }
292
- frames() {
293
- throw new Error('Not implemented');
294
- }
295
- createPDFStream(options) {
296
- void options;
297
- throw new Error('Not implemented');
298
- }
299
- createCDPSession() {
300
- throw new Error('Not implemented');
301
- }
302
- mainFrame() {
303
- throw new Error('Not implemented. `Frame` is returned empty object due to it cannot be serialized');
304
- // return this.process.callSync('mainFrame');
305
- }
306
- browser() {
307
- throw new Error('Not implemented');
308
- }
309
- bringToFront() {
310
- throw new Error('Not implemented');
311
- }
312
- browserContext() {
313
- throw new Error('Not implemented');
314
- }
315
- target() {
316
- throw new Error('Not implemented');
317
- }
318
- setGeolocation() {
319
- throw new Error('Not implemented');
320
- }
321
- waitForFileChooser() {
322
- throw new Error('Not implemented');
323
- }
324
- isJavaScriptEnabled() {
325
- throw new Error('Not implemented');
326
- }
327
- isDragInterceptionEnabled() {
328
- throw new Error('Not implemented');
329
- }
330
- isServiceWorkerBypassed() {
331
- throw new Error('Not implemented');
332
- }
333
- };
334
- return ChildProcessHostedPuppeteerPage = _classThis;
335
- })();
336
- export { ChildProcessHostedPuppeteerPage };
337
- function UnsafeDefineMethods(methods) {
338
- return (Constructor) => {
339
- const addMethod = (name) => {
340
- Object.defineProperty(
341
- // @ts-ignore
342
- Constructor.prototype, name, {
343
- value: async function (...args) {
344
- if (this.process) {
345
- return await this.process.call(name, ...args);
346
- }
347
- // @ts-ignore
348
- return Page.prototype[name]?.call?.(this, ...args);
349
- },
350
- writable: false,
351
- enumerable: false,
352
- configurable: false,
353
- });
354
- };
355
- // eslint-disable-next-line unicorn/no-array-for-each
356
- methods.forEach(addMethod);
357
- };
358
- }
@@ -1,84 +0,0 @@
1
- import type { Browser, BrowserContext, CDPSession, Cookie, CookieParam, Coverage, Credentials, DeleteCookiesRequest, Device, DeviceRequestPrompt, EvaluateFunc, EvaluateFuncWith, EventsWithWildcard, FileChooser, Frame, GoToOptions, HandleFor, HTTPResponse, JSHandle, Keyboard, MediaFeature, Metrics, Mouse, NetworkConditions, NewDocumentScriptEvaluation, NodeFor, PageEvents, PDFOptions, Protocol, PuppeteerLaunchOptions, Target, Touchscreen, Tracing, Viewport, WaitForOptions, WaitTimeoutOptions, WebWorker } from 'puppeteer';
2
- import type { ParseSelector } from 'typed-query-selector/parser.js';
3
- import { ProcTalk } from '@d-zero/proc-talk';
4
- import { Page } from 'puppeteer';
5
- export declare class ExPage extends Page {
6
- #private;
7
- readonly process: ProcTalk<Page, PuppeteerLaunchOptions>;
8
- get mouse(): Mouse;
9
- get tracing(): Tracing;
10
- get coverage(): Coverage;
11
- get keyboard(): Keyboard;
12
- get touchscreen(): Touchscreen;
13
- get pid(): number;
14
- constructor(options?: PuppeteerLaunchOptions);
15
- initialized(): Promise<void>;
16
- url(): string;
17
- waitForDevicePrompt(options?: WaitTimeoutOptions): Promise<DeviceRequestPrompt>;
18
- setViewport(viewport: Viewport | null): Promise<void>;
19
- viewport(): Viewport | null;
20
- pdf(options?: PDFOptions): Promise<Uint8Array>;
21
- title(): Promise<string>;
22
- close(options?: {
23
- runBeforeUnload?: boolean;
24
- }): Promise<void>;
25
- isClosed(): boolean;
26
- emulate(device: Device): Promise<void>;
27
- emit<Key extends keyof PageEvents>(type: Key, event: EventsWithWildcard<PageEvents>[Key]): boolean;
28
- emulateCPUThrottling(factor: number | null): Promise<void>;
29
- emulateIdleState(overrides?: {
30
- isUserActive: boolean;
31
- isScreenUnlocked: boolean;
32
- }): Promise<void>;
33
- emulateMediaFeatures(features?: MediaFeature[]): Promise<void>;
34
- emulateMediaType(type?: string): Promise<void>;
35
- emulateTimezone(timezoneId?: string): Promise<void>;
36
- emulateVisionDeficiency(type?: Protocol.Emulation.SetEmulatedVisionDeficiencyRequest['type']): Promise<void>;
37
- removeScriptToEvaluateOnNewDocument(identifier: string): Promise<void>;
38
- evaluate<Params extends unknown[], Func extends EvaluateFunc<Params> = EvaluateFunc<Params>>(pageFunction: Func | string, ...args: Params): Promise<Awaited<ReturnType<Func>>>;
39
- evaluateHandle<Params extends unknown[], Func extends EvaluateFunc<Params> = EvaluateFunc<Params>>(pageFunction: Func | string, ...args: Params): Promise<HandleFor<Awaited<ReturnType<Func>>>>;
40
- evaluateOnNewDocument<Params extends unknown[], Func extends (...args: Params) => unknown = (...args: Params) => unknown>(pageFunction: Func | string, ...args: Params): Promise<NewDocumentScriptEvaluation>;
41
- $eval<Selector extends string, Params extends unknown[], Func extends EvaluateFuncWith<NodeFor<Selector>, Params> = EvaluateFuncWith<ParseSelector<Selector, Element>, Params>>(selector: Selector, pageFunction: Func | string, ...args: Params): Promise<Awaited<ReturnType<Func>>>;
42
- $$eval<Selector extends string, Params extends unknown[], Func extends EvaluateFuncWith<Array<NodeFor<Selector>>, Params> = EvaluateFuncWith<ParseSelector<Selector, Element>[], Params>>(selector: Selector, pageFunction: Func | string, ...args: Params): Promise<Awaited<ReturnType<Func>>>;
43
- setCacheEnabled(enabled?: boolean): Promise<void>;
44
- setBypassCSP(enabled: boolean): Promise<void>;
45
- setJavaScriptEnabled(enabled: boolean): Promise<void>;
46
- goBack(options?: WaitForOptions): Promise<HTTPResponse | null>;
47
- goForward(options?: WaitForOptions): Promise<HTTPResponse | null>;
48
- goto(url: string, options?: GoToOptions): Promise<HTTPResponse | null>;
49
- reload(options?: WaitForOptions): Promise<HTTPResponse | null>;
50
- metrics(): Promise<Metrics>;
51
- setUserAgent(userAgent: string, userAgentMetadata?: Protocol.Emulation.UserAgentMetadata): Promise<void>;
52
- setExtraHTTPHeaders(headers: Record<string, string>): Promise<void>;
53
- authenticate(credentials: Credentials | null): Promise<void>;
54
- removeExposedFunction(name: string): Promise<void>;
55
- exposeFunction(name: string, pptrFunction: Function | {
56
- default: Function;
57
- }): Promise<void>;
58
- setCookie(...cookies: CookieParam[]): Promise<void>;
59
- deleteCookie(...cookies: DeleteCookiesRequest[]): Promise<void>;
60
- cookies(...urls: string[]): Promise<Cookie[]>;
61
- queryObjects<Prototype>(prototypeHandle: JSHandle<Prototype>): Promise<JSHandle<Prototype[]>>;
62
- setDefaultTimeout(timeout: number): void;
63
- getDefaultTimeout(): number;
64
- setDefaultNavigationTimeout(timeout: number): void;
65
- setOfflineMode(enabled: boolean): Promise<void>;
66
- emulateNetworkConditions(networkConditions: NetworkConditions | null): Promise<void>;
67
- setDragInterception(enabled: boolean): Promise<void>;
68
- setBypassServiceWorker(bypass: boolean): Promise<void>;
69
- setRequestInterception(value: boolean): Promise<void>;
70
- workers(): WebWorker[];
71
- frames(): Frame[];
72
- createPDFStream(options?: PDFOptions): Promise<ReadableStream<Uint8Array>>;
73
- createCDPSession(): Promise<CDPSession>;
74
- mainFrame(): Frame;
75
- browser(): Browser;
76
- bringToFront(): Promise<void>;
77
- browserContext(): BrowserContext;
78
- target(): Target;
79
- setGeolocation(): Promise<void>;
80
- waitForFileChooser(): Promise<FileChooser>;
81
- isJavaScriptEnabled(): boolean;
82
- isDragInterceptionEnabled(): boolean;
83
- isServiceWorkerBypassed(): boolean;
84
- }
@@ -1,358 +0,0 @@
1
- var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
2
- function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
3
- var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
4
- var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
5
- var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
6
- var _, done = false;
7
- for (var i = decorators.length - 1; i >= 0; i--) {
8
- var context = {};
9
- for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
10
- for (var p in contextIn.access) context.access[p] = contextIn.access[p];
11
- context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
12
- var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
13
- if (kind === "accessor") {
14
- if (result === void 0) continue;
15
- if (result === null || typeof result !== "object") throw new TypeError("Object expected");
16
- if (_ = accept(result.get)) descriptor.get = _;
17
- if (_ = accept(result.set)) descriptor.set = _;
18
- if (_ = accept(result.init)) initializers.unshift(_);
19
- }
20
- else if (_ = accept(result)) {
21
- if (kind === "field") initializers.unshift(_);
22
- else descriptor[key] = _;
23
- }
24
- }
25
- if (target) Object.defineProperty(target, contextIn.name, descriptor);
26
- done = true;
27
- };
28
- var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
29
- var useValue = arguments.length > 2;
30
- for (var i = 0; i < initializers.length; i++) {
31
- value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
32
- }
33
- return useValue ? value : void 0;
34
- };
35
- import path from 'node:path';
36
- import { ProcTalk } from '@d-zero/proc-talk';
37
- import { raceWithTimeout } from '@d-zero/shared/race-with-timeout';
38
- import { Page } from 'puppeteer';
39
- import { log } from './debug.js';
40
- const SUB_PROCESS_PATH = path.resolve(import.meta.dirname, 'puppeteer-page-sub.js');
41
- let ExPage = (() => {
42
- let _classDecorators = [UnsafeDefineMethods(['screenshot', 'on'])];
43
- let _classDescriptor;
44
- let _classExtraInitializers = [];
45
- let _classThis;
46
- let _classSuper = Page;
47
- var ExPage = class extends _classSuper {
48
- static { _classThis = this; }
49
- static {
50
- const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
51
- __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
52
- ExPage = _classThis = _classDescriptor.value;
53
- if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
54
- __runInitializers(_classThis, _classExtraInitializers);
55
- }
56
- process;
57
- #url = 'about:blank';
58
- get mouse() {
59
- throw new Error('Not implemented');
60
- }
61
- get tracing() {
62
- throw new Error('Not implemented');
63
- }
64
- get coverage() {
65
- throw new Error('Not implemented');
66
- }
67
- get keyboard() {
68
- throw new Error('Not implemented');
69
- }
70
- get touchscreen() {
71
- throw new Error('Not implemented');
72
- }
73
- get pid() {
74
- return this.process.pid;
75
- }
76
- constructor(options) {
77
- super();
78
- this.process = new ProcTalk({
79
- type: 'main',
80
- subModulePath: SUB_PROCESS_PATH,
81
- options,
82
- });
83
- }
84
- async initialized() {
85
- return await this.process.initialized();
86
- }
87
- url() {
88
- return this.#url;
89
- }
90
- waitForDevicePrompt(options) {
91
- void options;
92
- throw new Error('Not implemented');
93
- }
94
- async setViewport(viewport) {
95
- return await this.process.call('setViewport', viewport);
96
- }
97
- viewport() {
98
- throw new Error('Not implemented');
99
- }
100
- pdf(options) {
101
- void options;
102
- throw new Error('Not implemented');
103
- }
104
- async title() {
105
- return await this.process.call('title');
106
- }
107
- async close(options) {
108
- const TIME_OUT = 30_000;
109
- log('Closing page(%d)', this.process.pid);
110
- const { timeout } = await raceWithTimeout(async () => {
111
- await this.process.call('close', options);
112
- }, TIME_OUT);
113
- if (timeout) {
114
- log('Timeout(%dms) closing page', TIME_OUT);
115
- }
116
- const closed = this.process.close();
117
- if (!closed) {
118
- log('Need force killing process(%d)', this.process.pid);
119
- }
120
- log('Closed page(%d)', this.process.pid);
121
- }
122
- isClosed() {
123
- throw new Error('Not implemented');
124
- }
125
- emulate(device) {
126
- void device;
127
- throw new Error('Not implemented');
128
- }
129
- emit(type, event) {
130
- void type;
131
- void event;
132
- throw new Error('Not implemented');
133
- }
134
- emulateCPUThrottling(factor) {
135
- void factor;
136
- throw new Error('Not implemented');
137
- }
138
- emulateIdleState(overrides) {
139
- void overrides;
140
- throw new Error('Not implemented');
141
- }
142
- emulateMediaFeatures(features) {
143
- void features;
144
- throw new Error('Not implemented');
145
- }
146
- emulateMediaType(type) {
147
- void type;
148
- throw new Error('Not implemented');
149
- }
150
- emulateTimezone(timezoneId) {
151
- void timezoneId;
152
- throw new Error('Not implemented');
153
- }
154
- emulateVisionDeficiency(type) {
155
- void type;
156
- throw new Error('Not implemented');
157
- }
158
- removeScriptToEvaluateOnNewDocument(identifier) {
159
- void identifier;
160
- throw new Error('Not implemented');
161
- }
162
- evaluate(pageFunction, ...args) {
163
- return this.process.call('evaluate',
164
- // @ts-ignore
165
- pageFunction, ...args);
166
- }
167
- evaluateHandle(pageFunction, ...args) {
168
- void pageFunction;
169
- void args;
170
- throw new Error('Not implemented');
171
- }
172
- evaluateOnNewDocument(pageFunction, ...args) {
173
- void pageFunction;
174
- void args;
175
- throw new Error('Not implemented');
176
- }
177
- $eval(selector, pageFunction, ...args) {
178
- void selector;
179
- void pageFunction;
180
- void args;
181
- throw new Error('Not implemented');
182
- }
183
- $$eval(selector, pageFunction, ...args) {
184
- void selector;
185
- void pageFunction;
186
- void args;
187
- throw new Error('Not implemented');
188
- }
189
- setCacheEnabled(enabled) {
190
- void enabled;
191
- throw new Error('Not implemented');
192
- }
193
- setBypassCSP(enabled) {
194
- void enabled;
195
- throw new Error('Not implemented');
196
- }
197
- setJavaScriptEnabled(enabled) {
198
- void enabled;
199
- throw new Error('Not implemented');
200
- }
201
- goBack(options) {
202
- void options;
203
- throw new Error('Not implemented');
204
- }
205
- goForward(options) {
206
- void options;
207
- throw new Error('Not implemented');
208
- }
209
- async goto(url, options) {
210
- this.#url = url;
211
- return await this.process.call('goto', url, options);
212
- }
213
- async reload(options) {
214
- return await this.process.call('reload', options);
215
- }
216
- metrics() {
217
- throw new Error('Not implemented');
218
- }
219
- setUserAgent(userAgent, userAgentMetadata) {
220
- void userAgent;
221
- void userAgentMetadata;
222
- throw new Error('Not implemented');
223
- }
224
- setExtraHTTPHeaders(headers) {
225
- void headers;
226
- throw new Error('Not implemented');
227
- }
228
- authenticate(credentials) {
229
- void credentials;
230
- throw new Error('Not implemented');
231
- }
232
- removeExposedFunction(name) {
233
- void name;
234
- throw new Error('Not implemented');
235
- }
236
- exposeFunction(name,
237
- // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
238
- pptrFunction) {
239
- void name;
240
- void pptrFunction; // cspell: disable-line
241
- throw new Error('Not implemented');
242
- }
243
- setCookie(...cookies) {
244
- void cookies;
245
- throw new Error('Not implemented');
246
- }
247
- deleteCookie(...cookies) {
248
- void cookies;
249
- throw new Error('Not implemented');
250
- }
251
- cookies(...urls) {
252
- void urls;
253
- throw new Error('Not implemented');
254
- }
255
- queryObjects(prototypeHandle) {
256
- void prototypeHandle;
257
- throw new Error('Not implemented');
258
- }
259
- setDefaultTimeout(timeout) {
260
- void timeout;
261
- throw new Error('Not implemented');
262
- }
263
- getDefaultTimeout() {
264
- throw new Error('Not implemented');
265
- }
266
- setDefaultNavigationTimeout(timeout) {
267
- // TODO: Async call
268
- return void this.process.call('setDefaultNavigationTimeout', timeout);
269
- }
270
- setOfflineMode(enabled) {
271
- void enabled;
272
- throw new Error('Not implemented');
273
- }
274
- emulateNetworkConditions(networkConditions) {
275
- void networkConditions;
276
- throw new Error('Not implemented');
277
- }
278
- setDragInterception(enabled) {
279
- void enabled;
280
- throw new Error('Not implemented');
281
- }
282
- setBypassServiceWorker(bypass) {
283
- void bypass;
284
- throw new Error('Not implemented');
285
- }
286
- setRequestInterception(value) {
287
- void value;
288
- throw new Error('Not implemented');
289
- }
290
- workers() {
291
- throw new Error('Not implemented');
292
- }
293
- frames() {
294
- throw new Error('Not implemented');
295
- }
296
- createPDFStream(options) {
297
- void options;
298
- throw new Error('Not implemented');
299
- }
300
- createCDPSession() {
301
- throw new Error('Not implemented');
302
- }
303
- mainFrame() {
304
- throw new Error('Not implemented');
305
- }
306
- browser() {
307
- throw new Error('Not implemented');
308
- }
309
- bringToFront() {
310
- throw new Error('Not implemented');
311
- }
312
- browserContext() {
313
- throw new Error('Not implemented');
314
- }
315
- target() {
316
- throw new Error('Not implemented');
317
- }
318
- setGeolocation() {
319
- throw new Error('Not implemented');
320
- }
321
- waitForFileChooser() {
322
- throw new Error('Not implemented');
323
- }
324
- isJavaScriptEnabled() {
325
- throw new Error('Not implemented');
326
- }
327
- isDragInterceptionEnabled() {
328
- throw new Error('Not implemented');
329
- }
330
- isServiceWorkerBypassed() {
331
- throw new Error('Not implemented');
332
- }
333
- };
334
- return ExPage = _classThis;
335
- })();
336
- export { ExPage };
337
- function UnsafeDefineMethods(methods) {
338
- return (Constructor) => {
339
- const addMethod = (name) => {
340
- Object.defineProperty(
341
- // @ts-ignore
342
- Constructor.prototype, name, {
343
- value: async function (...args) {
344
- if (this.process) {
345
- return await this.process.call(name, ...args);
346
- }
347
- // @ts-ignore
348
- return Page.prototype[name]?.call?.(this, ...args);
349
- },
350
- writable: false,
351
- enumerable: false,
352
- configurable: false,
353
- });
354
- };
355
- // eslint-disable-next-line unicorn/no-array-for-each
356
- methods.forEach(addMethod);
357
- };
358
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,29 +0,0 @@
1
- /* use as a sub-process */
2
- import { ProcTalk } from '@d-zero/proc-talk';
3
- import puppeteer from 'puppeteer';
4
- process.title = '@d-zero/puppeteer-dealer:sub-process';
5
- new ProcTalk({
6
- type: 'child',
7
- async process(options) {
8
- this.log('Starting puppeteer: %O', options);
9
- const browser = await puppeteer.launch(options);
10
- const page = await browser?.newPage();
11
- const cleanUp = async () => {
12
- this.log('Cleanup start');
13
- await page?.close();
14
- await browser?.close();
15
- this.log('Cleanup done');
16
- };
17
- this.bind('evaluate', page.evaluate.bind(page));
18
- this.bind('goto', page.goto.bind(page));
19
- this.bind('title', page.title.bind(page));
20
- this.bind('setDefaultNavigationTimeout', page.setDefaultNavigationTimeout.bind(page));
21
- this.bind('setViewport', page.setViewport.bind(page));
22
- this.bind('screenshot', page.screenshot.bind(page));
23
- this.bind('reload', page.reload.bind(page));
24
- this.bind('on', page.on.bind(page));
25
- this.bind('close', async () => {
26
- await cleanUp();
27
- });
28
- },
29
- });