@d-zero/puppeteer-dealer 0.2.0 → 0.3.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/dist/deal.d.ts CHANGED
@@ -1,4 +1,11 @@
1
1
  import type { PuppeteerDealerOptions, PuppeteerDealHandler, URLInfo } from './types.js';
2
2
  import type { DealHeader } from '@d-zero/dealer';
3
3
  import type { PuppeteerLaunchOptions } from 'puppeteer';
4
+ /**
5
+ *
6
+ * @param list
7
+ * @param header
8
+ * @param handler
9
+ * @param options
10
+ */
4
11
  export declare function deal(list: readonly URLInfo[], header: DealHeader, handler: PuppeteerDealHandler, options?: PuppeteerDealerOptions & PuppeteerLaunchOptions): Promise<void>;
package/dist/deal.js CHANGED
@@ -3,6 +3,13 @@ import { createPage } from '@d-zero/puppeteer-page';
3
3
  import { delay } from '@d-zero/shared/delay';
4
4
  import c from 'ansi-colors';
5
5
  import { log } from './debug.js';
6
+ /**
7
+ *
8
+ * @param list
9
+ * @param header
10
+ * @param handler
11
+ * @param options
12
+ */
6
13
  export async function deal(list, header, handler, options) {
7
14
  const config = {
8
15
  locale: 'ja-JP',
@@ -71,6 +78,13 @@ export async function deal(list, header, handler, options) {
71
78
  });
72
79
  log('PuppeteerDealer.deal() completed');
73
80
  }
81
+ /**
82
+ *
83
+ * @param page
84
+ * @param url
85
+ * @param fileId
86
+ * @param index
87
+ */
74
88
  function evaluationError(page, url, fileId, index) {
75
89
  return (error) => {
76
90
  if (error instanceof Error &&
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.3.0",
4
4
  "description": "Puppeteer handles each page",
5
5
  "author": "D-ZERO",
6
6
  "license": "MIT",
@@ -24,14 +24,14 @@
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.0",
28
+ "@d-zero/puppeteer-page": "0.3.0",
29
+ "@d-zero/shared": "0.7.0",
30
30
  "ansi-colors": "4.1.3",
31
- "debug": "4.3.7"
31
+ "debug": "4.4.0"
32
32
  },
33
33
  "devDependencies": {
34
- "puppeteer": "23.6.1"
34
+ "puppeteer": "23.7.1"
35
35
  },
36
- "gitHead": "1eb1c03400580040119121e11ffb33acd876fe1b"
36
+ "gitHead": "e4fd17857e31022d121527b00fd7f009dbdb2142"
37
37
  }
@@ -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
- });