@d-zero/puppeteer-dealer 0.2.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.
- package/LICENSE +21 -0
- package/README.md +54 -0
- package/dist/create-page.d.ts +5 -0
- package/dist/create-page.js +7 -0
- package/dist/deal.d.ts +4 -0
- package/dist/deal.js +93 -0
- package/dist/debug.d.ts +2 -0
- package/dist/debug.js +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/puppeteer-page-child-process.d.ts +1 -0
- package/dist/puppeteer-page-child-process.js +29 -0
- package/dist/puppeteer-page-main-process.d.ts +84 -0
- package/dist/puppeteer-page-main-process.js +358 -0
- package/dist/puppeteer-page-main.d.ts +84 -0
- package/dist/puppeteer-page-main.js +358 -0
- package/dist/puppeteer-page-sub.d.ts +1 -0
- package/dist/puppeteer-page-sub.js +29 -0
- package/dist/types.d.ts +14 -0
- package/dist/types.js +1 -0
- package/package.json +37 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 D-ZERO Co., Ltd.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# `@d-zero/puppeteer-dealer`
|
|
2
|
+
|
|
3
|
+
```ts
|
|
4
|
+
import { deal } from '@d-zero/puppeteer-dealer';
|
|
5
|
+
|
|
6
|
+
await deal(
|
|
7
|
+
// Input list data
|
|
8
|
+
[
|
|
9
|
+
{
|
|
10
|
+
id: '1',
|
|
11
|
+
url: 'https://example.com',
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
id: '2',
|
|
15
|
+
url: 'https://example.com',
|
|
16
|
+
},
|
|
17
|
+
],
|
|
18
|
+
|
|
19
|
+
// Header log
|
|
20
|
+
(progress, done, total) => {
|
|
21
|
+
return `Header ${Math.ceil(progress * 100)}% ${done}/${total}`;
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
// Handlers
|
|
25
|
+
{
|
|
26
|
+
async beforeOpenPage(id, url, logger) {
|
|
27
|
+
if (condition) {
|
|
28
|
+
// continue (like Event preventDefault)
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return true;
|
|
33
|
+
},
|
|
34
|
+
async deal(page, id, url, logger) {
|
|
35
|
+
// Do something
|
|
36
|
+
await page.goto(url);
|
|
37
|
+
await page.evaluate(() => {
|
|
38
|
+
// Do something
|
|
39
|
+
});
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
// Options
|
|
44
|
+
{
|
|
45
|
+
locale: 'ja-JP',
|
|
46
|
+
debug: false,
|
|
47
|
+
limit: 10,
|
|
48
|
+
verbose: false,
|
|
49
|
+
|
|
50
|
+
// Puppeteer launch options
|
|
51
|
+
headless: true,
|
|
52
|
+
},
|
|
53
|
+
);
|
|
54
|
+
```
|
|
@@ -0,0 +1,7 @@
|
|
|
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
|
+
}
|
package/dist/deal.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { PuppeteerDealerOptions, PuppeteerDealHandler, URLInfo } from './types.js';
|
|
2
|
+
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>;
|
package/dist/deal.js
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
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
|
+
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) => {
|
|
34
|
+
const fileId = id || index.toString().padStart(3, '0');
|
|
35
|
+
const lineHeader = `%braille% ${c.bgWhite(` ${fileId} `)} ${c.gray(url.toString())}: `;
|
|
36
|
+
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,
|
|
50
|
+
});
|
|
51
|
+
if (page.pid !== null) {
|
|
52
|
+
childPrecessIds.add(page.pid);
|
|
53
|
+
}
|
|
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);
|
|
67
|
+
};
|
|
68
|
+
}, {
|
|
69
|
+
...config,
|
|
70
|
+
header,
|
|
71
|
+
});
|
|
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
|
+
}
|
package/dist/debug.d.ts
ADDED
package/dist/debug.js
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,84 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,358 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,358 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
});
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { DealOptions } from '@d-zero/dealer';
|
|
2
|
+
import type { Page } from '@d-zero/puppeteer-page';
|
|
3
|
+
export type PuppeteerDealerOptions = {
|
|
4
|
+
readonly locale?: string;
|
|
5
|
+
} & DealOptions;
|
|
6
|
+
export type PuppeteerDealHandler = {
|
|
7
|
+
beforeOpenPage?: (id: string, url: string, log: Logger, index: number) => Promise<boolean>;
|
|
8
|
+
deal: (page: Page, id: string, url: string, log: Logger, index: number) => Promise<void>;
|
|
9
|
+
};
|
|
10
|
+
export type URLInfo = {
|
|
11
|
+
readonly id: string | null;
|
|
12
|
+
readonly url: string | URL;
|
|
13
|
+
};
|
|
14
|
+
export type Logger = (log: string) => void;
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@d-zero/puppeteer-dealer",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Puppeteer handles each page",
|
|
5
|
+
"author": "D-ZERO",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"private": false,
|
|
8
|
+
"publishConfig": {
|
|
9
|
+
"access": "public"
|
|
10
|
+
},
|
|
11
|
+
"type": "module",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"import": "./dist/index.js",
|
|
15
|
+
"types": "./dist/index.d.ts"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsc",
|
|
23
|
+
"watch": "tsc --watch",
|
|
24
|
+
"clean": "tsc --build --clean"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@d-zero/dealer": "1.2.0",
|
|
28
|
+
"@d-zero/puppeteer-page": "0.2.0",
|
|
29
|
+
"@d-zero/shared": "0.6.0",
|
|
30
|
+
"ansi-colors": "4.1.3",
|
|
31
|
+
"debug": "4.3.7"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"puppeteer": "23.6.1"
|
|
35
|
+
},
|
|
36
|
+
"gitHead": "1eb1c03400580040119121e11ffb33acd876fe1b"
|
|
37
|
+
}
|