brave-real-puppeteer-core 24.22.0 → 24.23.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/README.md +5 -5
- package/advanced-stealth.js +1 -1
- package/lib/cjs/puppeteer/api/Dialog.d.ts +8 -10
- package/lib/cjs/puppeteer/api/Dialog.d.ts.map +1 -1
- package/lib/cjs/puppeteer/api/Dialog.js +8 -10
- package/lib/cjs/puppeteer/api/Dialog.js.map +1 -1
- package/lib/cjs/puppeteer/api/ElementHandle.d.ts +28 -30
- package/lib/cjs/puppeteer/api/ElementHandle.d.ts.map +1 -1
- package/lib/cjs/puppeteer/api/ElementHandle.js +27 -29
- package/lib/cjs/puppeteer/api/ElementHandle.js.map +1 -1
- package/lib/cjs/puppeteer/api/Frame.d.ts +34 -38
- package/lib/cjs/puppeteer/api/Frame.d.ts.map +1 -1
- package/lib/cjs/puppeteer/api/Frame.js +34 -38
- package/lib/cjs/puppeteer/api/Frame.js.map +1 -1
- package/lib/cjs/puppeteer/api/HTTPRequest.d.ts +8 -1
- package/lib/cjs/puppeteer/api/HTTPRequest.d.ts.map +1 -1
- package/lib/cjs/puppeteer/api/HTTPRequest.js +12 -14
- package/lib/cjs/puppeteer/api/HTTPRequest.js.map +1 -1
- package/lib/cjs/puppeteer/api/Page.d.ts +92 -108
- package/lib/cjs/puppeteer/api/Page.d.ts.map +1 -1
- package/lib/cjs/puppeteer/api/Page.js +33 -39
- package/lib/cjs/puppeteer/api/Page.js.map +1 -1
- package/lib/cjs/puppeteer/bidi/Browser.d.ts.map +1 -1
- package/lib/cjs/puppeteer/bidi/Browser.js +5 -3
- package/lib/cjs/puppeteer/bidi/Browser.js.map +1 -1
- package/lib/cjs/puppeteer/bidi/Frame.d.ts.map +1 -1
- package/lib/cjs/puppeteer/bidi/Frame.js +1 -1
- package/lib/cjs/puppeteer/bidi/Frame.js.map +1 -1
- package/lib/cjs/puppeteer/bidi/HTTPRequest.d.ts +4 -2
- package/lib/cjs/puppeteer/bidi/HTTPRequest.d.ts.map +1 -1
- package/lib/cjs/puppeteer/bidi/HTTPRequest.js +14 -5
- package/lib/cjs/puppeteer/bidi/HTTPRequest.js.map +1 -1
- package/lib/cjs/puppeteer/bidi/Page.d.ts +1 -0
- package/lib/cjs/puppeteer/bidi/Page.d.ts.map +1 -1
- package/lib/cjs/puppeteer/bidi/Page.js +12 -6
- package/lib/cjs/puppeteer/bidi/Page.js.map +1 -1
- package/lib/cjs/puppeteer/bidi/core/Browser.d.ts.map +1 -1
- package/lib/cjs/puppeteer/bidi/core/Browser.js +24 -2
- package/lib/cjs/puppeteer/bidi/core/Browser.js.map +1 -1
- package/lib/cjs/puppeteer/bidi/core/Realm.d.ts +2 -2
- package/lib/cjs/puppeteer/cdp/HTTPRequest.d.ts +1 -0
- package/lib/cjs/puppeteer/cdp/HTTPRequest.d.ts.map +1 -1
- package/lib/cjs/puppeteer/cdp/HTTPRequest.js +3 -0
- package/lib/cjs/puppeteer/cdp/HTTPRequest.js.map +1 -1
- package/lib/cjs/puppeteer/cdp/PredefinedNetworkConditions.d.ts +13 -22
- package/lib/cjs/puppeteer/cdp/PredefinedNetworkConditions.d.ts.map +1 -1
- package/lib/cjs/puppeteer/cdp/PredefinedNetworkConditions.js +13 -22
- package/lib/cjs/puppeteer/cdp/PredefinedNetworkConditions.js.map +1 -1
- package/lib/cjs/puppeteer/common/Device.d.ts +6 -8
- package/lib/cjs/puppeteer/common/Device.d.ts.map +1 -1
- package/lib/cjs/puppeteer/common/Device.js +6 -8
- package/lib/cjs/puppeteer/common/Device.js.map +1 -1
- package/lib/cjs/puppeteer/generated/injected.d.ts +1 -1
- package/lib/cjs/puppeteer/generated/injected.js +1 -1
- package/lib/cjs/puppeteer/generated/version.d.ts +1 -1
- package/lib/cjs/puppeteer/generated/version.js +1 -1
- package/lib/cjs/puppeteer/injected/injected.d.ts +1 -1
- package/lib/cjs/puppeteer/node/BrowserLauncher.d.ts +1 -1
- package/lib/cjs/puppeteer/node/BrowserLauncher.d.ts.map +1 -1
- package/lib/cjs/puppeteer/node/BrowserLauncher.js +7 -4
- package/lib/cjs/puppeteer/node/BrowserLauncher.js.map +1 -1
- package/lib/cjs/puppeteer/node/ChromeLauncher.d.ts.map +1 -1
- package/lib/cjs/puppeteer/node/ChromeLauncher.js +1 -0
- package/lib/cjs/puppeteer/node/ChromeLauncher.js.map +1 -1
- package/lib/cjs/puppeteer/node/PipeTransport.d.ts.map +1 -1
- package/lib/cjs/puppeteer/node/PipeTransport.js +15 -16
- package/lib/cjs/puppeteer/node/PipeTransport.js.map +1 -1
- package/lib/cjs/puppeteer/node/PuppeteerNode.d.ts +5 -7
- package/lib/cjs/puppeteer/node/PuppeteerNode.d.ts.map +1 -1
- package/lib/cjs/puppeteer/node/PuppeteerNode.js +5 -7
- package/lib/cjs/puppeteer/node/PuppeteerNode.js.map +1 -1
- package/lib/cjs/puppeteer/revisions.d.ts +3 -3
- package/lib/cjs/puppeteer/revisions.js +3 -3
- package/lib/cjs/puppeteer/revisions.js.map +1 -1
- package/lib/cjs/puppeteer/util/Function.d.ts.map +1 -1
- package/lib/cjs/puppeteer/util/Function.js +16 -25
- package/lib/cjs/puppeteer/util/Function.js.map +1 -1
- package/lib/cjs/puppeteer/util/Mutex.d.ts +2 -2
- package/lib/es5-iife/puppeteer-core-browser.d.ts +189 -225
- package/lib/es5-iife/puppeteer-core-browser.js +155 -190
- package/lib/esm/puppeteer/api/Dialog.d.ts +8 -10
- package/lib/esm/puppeteer/api/Dialog.d.ts.map +1 -1
- package/lib/esm/puppeteer/api/Dialog.js +8 -10
- package/lib/esm/puppeteer/api/Dialog.js.map +1 -1
- package/lib/esm/puppeteer/api/ElementHandle.d.ts +28 -30
- package/lib/esm/puppeteer/api/ElementHandle.d.ts.map +1 -1
- package/lib/esm/puppeteer/api/ElementHandle.js +27 -29
- package/lib/esm/puppeteer/api/ElementHandle.js.map +1 -1
- package/lib/esm/puppeteer/api/Frame.d.ts +34 -38
- package/lib/esm/puppeteer/api/Frame.d.ts.map +1 -1
- package/lib/esm/puppeteer/api/Frame.js +34 -38
- package/lib/esm/puppeteer/api/Frame.js.map +1 -1
- package/lib/esm/puppeteer/api/HTTPRequest.d.ts +8 -1
- package/lib/esm/puppeteer/api/HTTPRequest.d.ts.map +1 -1
- package/lib/esm/puppeteer/api/HTTPRequest.js +12 -14
- package/lib/esm/puppeteer/api/HTTPRequest.js.map +1 -1
- package/lib/esm/puppeteer/api/Page.d.ts +92 -108
- package/lib/esm/puppeteer/api/Page.d.ts.map +1 -1
- package/lib/esm/puppeteer/api/Page.js +33 -39
- package/lib/esm/puppeteer/api/Page.js.map +1 -1
- package/lib/esm/puppeteer/bidi/Browser.d.ts.map +1 -1
- package/lib/esm/puppeteer/bidi/Browser.js +5 -3
- package/lib/esm/puppeteer/bidi/Browser.js.map +1 -1
- package/lib/esm/puppeteer/bidi/Frame.d.ts.map +1 -1
- package/lib/esm/puppeteer/bidi/Frame.js +1 -1
- package/lib/esm/puppeteer/bidi/Frame.js.map +1 -1
- package/lib/esm/puppeteer/bidi/HTTPRequest.d.ts +4 -2
- package/lib/esm/puppeteer/bidi/HTTPRequest.d.ts.map +1 -1
- package/lib/esm/puppeteer/bidi/HTTPRequest.js +15 -6
- package/lib/esm/puppeteer/bidi/HTTPRequest.js.map +1 -1
- package/lib/esm/puppeteer/bidi/Page.d.ts +1 -0
- package/lib/esm/puppeteer/bidi/Page.d.ts.map +1 -1
- package/lib/esm/puppeteer/bidi/Page.js +12 -6
- package/lib/esm/puppeteer/bidi/Page.js.map +1 -1
- package/lib/esm/puppeteer/bidi/core/Browser.d.ts.map +1 -1
- package/lib/esm/puppeteer/bidi/core/Browser.js +24 -2
- package/lib/esm/puppeteer/bidi/core/Browser.js.map +1 -1
- package/lib/esm/puppeteer/cdp/HTTPRequest.d.ts +1 -0
- package/lib/esm/puppeteer/cdp/HTTPRequest.d.ts.map +1 -1
- package/lib/esm/puppeteer/cdp/HTTPRequest.js +3 -0
- package/lib/esm/puppeteer/cdp/HTTPRequest.js.map +1 -1
- package/lib/esm/puppeteer/cdp/PredefinedNetworkConditions.d.ts +13 -22
- package/lib/esm/puppeteer/cdp/PredefinedNetworkConditions.d.ts.map +1 -1
- package/lib/esm/puppeteer/cdp/PredefinedNetworkConditions.js +13 -22
- package/lib/esm/puppeteer/cdp/PredefinedNetworkConditions.js.map +1 -1
- package/lib/esm/puppeteer/common/Device.d.ts +6 -8
- package/lib/esm/puppeteer/common/Device.d.ts.map +1 -1
- package/lib/esm/puppeteer/common/Device.js +6 -8
- package/lib/esm/puppeteer/common/Device.js.map +1 -1
- package/lib/esm/puppeteer/generated/injected.d.ts +1 -1
- package/lib/esm/puppeteer/generated/injected.js +1 -1
- package/lib/esm/puppeteer/generated/version.d.ts +1 -1
- package/lib/esm/puppeteer/generated/version.js +1 -1
- package/lib/esm/puppeteer/node/BrowserLauncher.d.ts +1 -1
- package/lib/esm/puppeteer/node/BrowserLauncher.d.ts.map +1 -1
- package/lib/esm/puppeteer/node/BrowserLauncher.js +7 -4
- package/lib/esm/puppeteer/node/BrowserLauncher.js.map +1 -1
- package/lib/esm/puppeteer/node/ChromeLauncher.d.ts.map +1 -1
- package/lib/esm/puppeteer/node/ChromeLauncher.js +1 -0
- package/lib/esm/puppeteer/node/ChromeLauncher.js.map +1 -1
- package/lib/esm/puppeteer/node/PipeTransport.d.ts.map +1 -1
- package/lib/esm/puppeteer/node/PipeTransport.js +15 -16
- package/lib/esm/puppeteer/node/PipeTransport.js.map +1 -1
- package/lib/esm/puppeteer/node/PuppeteerNode.d.ts +5 -7
- package/lib/esm/puppeteer/node/PuppeteerNode.d.ts.map +1 -1
- package/lib/esm/puppeteer/node/PuppeteerNode.js +5 -7
- package/lib/esm/puppeteer/node/PuppeteerNode.js.map +1 -1
- package/lib/esm/puppeteer/revisions.d.ts +3 -3
- package/lib/esm/puppeteer/revisions.js +3 -3
- package/lib/esm/puppeteer/revisions.js.map +1 -1
- package/lib/esm/puppeteer/util/Function.d.ts.map +1 -1
- package/lib/esm/puppeteer/util/Function.js +16 -25
- package/lib/esm/puppeteer/util/Function.js.map +1 -1
- package/lib/types.d.ts +189 -225
- package/package.json +14 -14
- package/src/api/Dialog.ts +8 -10
- package/src/api/ElementHandle.ts +27 -29
- package/src/api/Frame.ts +34 -38
- package/src/api/HTTPRequest.ts +17 -14
- package/src/api/Page.ts +92 -108
- package/src/bidi/Browser.ts +5 -3
- package/src/bidi/Frame.ts +5 -1
- package/src/bidi/HTTPRequest.ts +28 -3
- package/src/bidi/Page.ts +16 -7
- package/src/bidi/core/Browser.ts +28 -2
- package/src/cdp/HTTPRequest.ts +4 -0
- package/src/cdp/PredefinedNetworkConditions.ts +13 -22
- package/src/common/Device.ts +6 -8
- package/src/generated/injected.ts +1 -1
- package/src/generated/version.ts +1 -1
- package/src/node/BrowserLauncher.ts +7 -4
- package/src/node/ChromeLauncher.ts +1 -0
- package/src/node/PipeTransport.ts +15 -17
- package/src/node/PuppeteerNode.ts +5 -7
- package/src/revisions.ts +3 -3
- package/src/util/Function.ts +22 -30
package/src/bidi/HTTPRequest.ts
CHANGED
|
@@ -9,6 +9,7 @@ import type * as Bidi from 'webdriver-bidi-protocol';
|
|
|
9
9
|
import type {CDPSession} from '../api/CDPSession.js';
|
|
10
10
|
import type {
|
|
11
11
|
ContinueRequestOverrides,
|
|
12
|
+
InterceptResolutionState,
|
|
12
13
|
ResponseForRequest,
|
|
13
14
|
} from '../api/HTTPRequest.js';
|
|
14
15
|
import {
|
|
@@ -16,6 +17,7 @@ import {
|
|
|
16
17
|
STATUS_TEXTS,
|
|
17
18
|
type ResourceType,
|
|
18
19
|
handleError,
|
|
20
|
+
InterceptResolutionAction,
|
|
19
21
|
} from '../api/HTTPRequest.js';
|
|
20
22
|
import {PageEvent} from '../api/Page.js';
|
|
21
23
|
import {UnsupportedOperation} from '../common/Errors.js';
|
|
@@ -34,9 +36,15 @@ export class BidiHTTPRequest extends HTTPRequest {
|
|
|
34
36
|
static from(
|
|
35
37
|
bidiRequest: Request,
|
|
36
38
|
frame: BidiFrame,
|
|
39
|
+
isNetworkInterceptionEnabled: boolean,
|
|
37
40
|
redirect?: BidiHTTPRequest,
|
|
38
41
|
): BidiHTTPRequest {
|
|
39
|
-
const request = new BidiHTTPRequest(
|
|
42
|
+
const request = new BidiHTTPRequest(
|
|
43
|
+
bidiRequest,
|
|
44
|
+
frame,
|
|
45
|
+
isNetworkInterceptionEnabled,
|
|
46
|
+
redirect,
|
|
47
|
+
);
|
|
40
48
|
request.#initialize();
|
|
41
49
|
return request;
|
|
42
50
|
}
|
|
@@ -50,12 +58,13 @@ export class BidiHTTPRequest extends HTTPRequest {
|
|
|
50
58
|
private constructor(
|
|
51
59
|
request: Request,
|
|
52
60
|
frame: BidiFrame,
|
|
61
|
+
isNetworkInterceptionEnabled: boolean,
|
|
53
62
|
redirect?: BidiHTTPRequest,
|
|
54
63
|
) {
|
|
55
64
|
super();
|
|
56
65
|
requests.set(request, this);
|
|
57
66
|
|
|
58
|
-
this.interception.enabled =
|
|
67
|
+
this.interception.enabled = isNetworkInterceptionEnabled;
|
|
59
68
|
|
|
60
69
|
this.#request = request;
|
|
61
70
|
this.#frame = frame;
|
|
@@ -69,7 +78,12 @@ export class BidiHTTPRequest extends HTTPRequest {
|
|
|
69
78
|
|
|
70
79
|
#initialize() {
|
|
71
80
|
this.#request.on('redirect', request => {
|
|
72
|
-
const httpRequest = BidiHTTPRequest.from(
|
|
81
|
+
const httpRequest = BidiHTTPRequest.from(
|
|
82
|
+
request,
|
|
83
|
+
this.#frame,
|
|
84
|
+
this.interception.enabled,
|
|
85
|
+
this,
|
|
86
|
+
);
|
|
73
87
|
this.#redirectChain.push(this);
|
|
74
88
|
|
|
75
89
|
request.once('success', () => {
|
|
@@ -108,6 +122,17 @@ export class BidiHTTPRequest extends HTTPRequest {
|
|
|
108
122
|
}
|
|
109
123
|
}
|
|
110
124
|
|
|
125
|
+
protected canBeIntercepted(): boolean {
|
|
126
|
+
return this.#request.isBlocked;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
override interceptResolutionState(): InterceptResolutionState {
|
|
130
|
+
if (!this.#request.isBlocked) {
|
|
131
|
+
return {action: InterceptResolutionAction.Disabled};
|
|
132
|
+
}
|
|
133
|
+
return super.interceptResolutionState();
|
|
134
|
+
}
|
|
135
|
+
|
|
111
136
|
override url(): string {
|
|
112
137
|
return this.#request.url;
|
|
113
138
|
}
|
package/src/bidi/Page.ts
CHANGED
|
@@ -245,7 +245,7 @@ export class BidiPage extends Page {
|
|
|
245
245
|
}
|
|
246
246
|
|
|
247
247
|
override async setBypassCSP(enabled: boolean): Promise<void> {
|
|
248
|
-
// TODO: handle CDP-specific cases such as
|
|
248
|
+
// TODO: handle CDP-specific cases such as MPArch.
|
|
249
249
|
await this._client().send('Page.setBypassCSP', {enabled});
|
|
250
250
|
}
|
|
251
251
|
|
|
@@ -626,7 +626,7 @@ export class BidiPage extends Page {
|
|
|
626
626
|
);
|
|
627
627
|
return;
|
|
628
628
|
}
|
|
629
|
-
// TODO: handle CDP-specific cases such as
|
|
629
|
+
// TODO: handle CDP-specific cases such as MPArch.
|
|
630
630
|
await this._client().send('Network.setCacheDisabled', {
|
|
631
631
|
cacheDisabled: !enabled,
|
|
632
632
|
});
|
|
@@ -711,11 +711,20 @@ export class BidiPage extends Page {
|
|
|
711
711
|
return [...this.#workers];
|
|
712
712
|
}
|
|
713
713
|
|
|
714
|
-
|
|
714
|
+
get isNetworkInterceptionEnabled(): boolean {
|
|
715
|
+
return (
|
|
716
|
+
Boolean(this.#requestInterception) ||
|
|
717
|
+
Boolean(this.#extraHeadersInterception) ||
|
|
718
|
+
Boolean(this.#authInterception) ||
|
|
719
|
+
Boolean(this.#userAgentInterception)
|
|
720
|
+
);
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
#requestInterception?: string;
|
|
715
724
|
override async setRequestInterception(enable: boolean): Promise<void> {
|
|
716
|
-
this.#
|
|
725
|
+
this.#requestInterception = await this.#toggleInterception(
|
|
717
726
|
[Bidi.Network.InterceptPhase.BeforeRequestSent],
|
|
718
|
-
this.#
|
|
727
|
+
this.#requestInterception,
|
|
719
728
|
enable,
|
|
720
729
|
);
|
|
721
730
|
}
|
|
@@ -1054,7 +1063,7 @@ export function bidiToPuppeteerCookie(
|
|
|
1054
1063
|
): Cookie {
|
|
1055
1064
|
const partitionKey = bidiCookie[CDP_SPECIFIC_PREFIX + 'partitionKey'];
|
|
1056
1065
|
|
|
1057
|
-
function
|
|
1066
|
+
function getPartitionKey(): {partitionKey?: Cookie['partitionKey']} {
|
|
1058
1067
|
if (typeof partitionKey === 'string') {
|
|
1059
1068
|
return {partitionKey};
|
|
1060
1069
|
}
|
|
@@ -1096,7 +1105,7 @@ export function bidiToPuppeteerCookie(
|
|
|
1096
1105
|
'partitionKeyOpaque',
|
|
1097
1106
|
'priority',
|
|
1098
1107
|
),
|
|
1099
|
-
...
|
|
1108
|
+
...getPartitionKey(),
|
|
1100
1109
|
};
|
|
1101
1110
|
}
|
|
1102
1111
|
|
package/src/bidi/core/Browser.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import type * as Bidi from 'webdriver-bidi-protocol';
|
|
8
8
|
|
|
9
9
|
import type {BrowserContextOptions} from '../../api/Browser.js';
|
|
10
|
+
import {UnsupportedOperation} from '../../common/Errors.js';
|
|
10
11
|
import {EventEmitter} from '../../common/EventEmitter.js';
|
|
11
12
|
import {inertIfDisposed, throwIfDisposed} from '../../util/decorators.js';
|
|
12
13
|
import {DisposableStack, disposeSymbol} from '../../util/disposable.js';
|
|
@@ -232,11 +233,36 @@ export class Browser extends EventEmitter<{
|
|
|
232
233
|
noProxy: options.proxyBypassList,
|
|
233
234
|
};
|
|
234
235
|
const {
|
|
235
|
-
result: {userContext
|
|
236
|
+
result: {userContext},
|
|
236
237
|
} = await this.session.send('browser.createUserContext', {
|
|
237
238
|
proxy: proxyConfig,
|
|
238
239
|
});
|
|
239
|
-
|
|
240
|
+
if (options.downloadBehavior?.policy === 'allowAndName') {
|
|
241
|
+
throw new UnsupportedOperation(
|
|
242
|
+
'`allowAndName` is not supported in WebDriver BiDi',
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
if (options.downloadBehavior?.policy === 'allow') {
|
|
246
|
+
if (options.downloadBehavior.downloadPath === undefined) {
|
|
247
|
+
throw new UnsupportedOperation(
|
|
248
|
+
'`downloadPath` is required in `allow` download behavior',
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
await this.session.send('browser.setDownloadBehavior', {
|
|
252
|
+
downloadBehavior: {
|
|
253
|
+
type: 'allowed',
|
|
254
|
+
destinationFolder: options.downloadBehavior.downloadPath,
|
|
255
|
+
},
|
|
256
|
+
userContexts: [userContext],
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
if (options.downloadBehavior?.policy === 'deny') {
|
|
260
|
+
await this.session.send('browser.setDownloadBehavior', {
|
|
261
|
+
downloadBehavior: {type: 'denied'},
|
|
262
|
+
userContexts: [userContext],
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
return this.#createUserContext(userContext);
|
|
240
266
|
}
|
|
241
267
|
|
|
242
268
|
@throwIfDisposed<Browser>(browser => {
|
package/src/cdp/HTTPRequest.ts
CHANGED
|
@@ -14,28 +14,19 @@ import type {NetworkConditions} from './NetworkManager.js';
|
|
|
14
14
|
*
|
|
15
15
|
* ```ts
|
|
16
16
|
* import {PredefinedNetworkConditions} from 'puppeteer';
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* ); // alias to Fast 3G.
|
|
31
|
-
* await page.goto('https://www.google.com');
|
|
32
|
-
* await page.emulateNetworkConditions(
|
|
33
|
-
* PredefinedNetworkConditions['Fast 4G'],
|
|
34
|
-
* );
|
|
35
|
-
* await page.goto('https://www.google.com');
|
|
36
|
-
* // other actions...
|
|
37
|
-
* await browser.close();
|
|
38
|
-
* })();
|
|
17
|
+
* const browser = await puppeteer.launch();
|
|
18
|
+
* const page = await browser.newPage();
|
|
19
|
+
* await page.emulateNetworkConditions(PredefinedNetworkConditions['Slow 3G']);
|
|
20
|
+
* await page.goto('https://www.google.com');
|
|
21
|
+
* await page.emulateNetworkConditions(PredefinedNetworkConditions['Fast 3G']);
|
|
22
|
+
* await page.goto('https://www.google.com');
|
|
23
|
+
* // alias to Fast 3G.
|
|
24
|
+
* await page.emulateNetworkConditions(PredefinedNetworkConditions['Slow 4G']);
|
|
25
|
+
* await page.goto('https://www.google.com');
|
|
26
|
+
* await page.emulateNetworkConditions(PredefinedNetworkConditions['Fast 4G']);
|
|
27
|
+
* await page.goto('https://www.google.com');
|
|
28
|
+
* // other actions...
|
|
29
|
+
* await browser.close();
|
|
39
30
|
* ```
|
|
40
31
|
*
|
|
41
32
|
* @public
|
package/src/common/Device.ts
CHANGED
|
@@ -1738,14 +1738,12 @@ for (const device of knownDevices) {
|
|
|
1738
1738
|
* import {KnownDevices} from 'puppeteer';
|
|
1739
1739
|
* const iPhone = KnownDevices['iPhone 15 Pro'];
|
|
1740
1740
|
*
|
|
1741
|
-
*
|
|
1742
|
-
*
|
|
1743
|
-
*
|
|
1744
|
-
*
|
|
1745
|
-
*
|
|
1746
|
-
*
|
|
1747
|
-
* await browser.close();
|
|
1748
|
-
* })();
|
|
1741
|
+
* const browser = await puppeteer.launch();
|
|
1742
|
+
* const page = await browser.newPage();
|
|
1743
|
+
* await page.emulate(iPhone);
|
|
1744
|
+
* await page.goto('https://www.google.com');
|
|
1745
|
+
* // other actions...
|
|
1746
|
+
* await browser.close();
|
|
1749
1747
|
* ```
|
|
1750
1748
|
*
|
|
1751
1749
|
* @public
|
|
@@ -5,4 +5,4 @@
|
|
|
5
5
|
*
|
|
6
6
|
* @internal
|
|
7
7
|
*/
|
|
8
|
-
export const source = "\"use strict\";var g=Object.defineProperty;var X=Object.getOwnPropertyDescriptor;var B=Object.getOwnPropertyNames;var
|
|
8
|
+
export const source = "\"use strict\";var g=Object.defineProperty;var X=Object.getOwnPropertyDescriptor;var B=Object.getOwnPropertyNames;var Y=Object.prototype.hasOwnProperty;var l=(t,e)=>{for(var r in e)g(t,r,{get:e[r],enumerable:!0})},G=(t,e,r,o)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let s of B(e))!Y.call(t,s)&&s!==r&&g(t,s,{get:()=>e[s],enumerable:!(o=X(e,s))||o.enumerable});return t};var J=t=>G(g({},\"__esModule\",{value:!0}),t);var pe={};l(pe,{default:()=>he});module.exports=J(pe);var N=class extends Error{constructor(e,r){super(e,r),this.name=this.constructor.name}get[Symbol.toStringTag](){return this.constructor.name}},p=class extends N{};var c=class t{static create(e){return new t(e)}static async race(e){let r=new Set;try{let o=e.map(s=>s instanceof t?(s.#s&&r.add(s),s.valueOrThrow()):s);return await Promise.race(o)}finally{for(let o of r)o.reject(new Error(\"Timeout cleared\"))}}#e=!1;#r=!1;#o;#t;#a=new Promise(e=>{this.#t=e});#s;#i;constructor(e){e&&e.timeout>0&&(this.#i=new p(e.message),this.#s=setTimeout(()=>{this.reject(this.#i)},e.timeout))}#l(e){clearTimeout(this.#s),this.#o=e,this.#t()}resolve(e){this.#r||this.#e||(this.#e=!0,this.#l(e))}reject(e){this.#r||this.#e||(this.#r=!0,this.#l(e))}resolved(){return this.#e}finished(){return this.#e||this.#r}value(){return this.#o}#n;valueOrThrow(){return this.#n||(this.#n=(async()=>{if(await this.#a,this.#r)throw this.#o;return this.#o})()),this.#n}};var L=new Map,W=t=>{let e=L.get(t);return e||(e=new Function(`return ${t}`)(),L.set(t,e),e)};var b={};l(b,{ariaQuerySelector:()=>z,ariaQuerySelectorAll:()=>x});var z=(t,e)=>globalThis.__ariaQuerySelector(t,e),x=async function*(t,e){yield*await globalThis.__ariaQuerySelectorAll(t,e)};var E={};l(E,{cssQuerySelector:()=>K,cssQuerySelectorAll:()=>Z});var K=(t,e)=>t.querySelector(e),Z=function(t,e){return t.querySelectorAll(e)};var A={};l(A,{customQuerySelectors:()=>P});var v=class{#e=new Map;register(e,r){if(!r.queryOne&&r.queryAll){let o=r.queryAll;r.queryOne=(s,i)=>{for(let n of o(s,i))return n;return null}}else if(r.queryOne&&!r.queryAll){let o=r.queryOne;r.queryAll=(s,i)=>{let n=o(s,i);return n?[n]:[]}}else if(!r.queryOne||!r.queryAll)throw new Error(\"At least one query method must be defined.\");this.#e.set(e,{querySelector:r.queryOne,querySelectorAll:r.queryAll})}unregister(e){this.#e.delete(e)}get(e){return this.#e.get(e)}clear(){this.#e.clear()}},P=new v;var R={};l(R,{pierceQuerySelector:()=>ee,pierceQuerySelectorAll:()=>te});var ee=(t,e)=>{let r=null,o=s=>{let i=document.createTreeWalker(s,NodeFilter.SHOW_ELEMENT);do{let n=i.currentNode;n.shadowRoot&&o(n.shadowRoot),!(n instanceof ShadowRoot)&&n!==s&&!r&&n.matches(e)&&(r=n)}while(!r&&i.nextNode())};return t instanceof Document&&(t=t.documentElement),o(t),r},te=(t,e)=>{let r=[],o=s=>{let i=document.createTreeWalker(s,NodeFilter.SHOW_ELEMENT);do{let n=i.currentNode;n.shadowRoot&&o(n.shadowRoot),!(n instanceof ShadowRoot)&&n!==s&&n.matches(e)&&r.push(n)}while(i.nextNode())};return t instanceof Document&&(t=t.documentElement),o(t),r};var u=(t,e)=>{if(!t)throw new Error(e)};var y=class{#e;#r;#o;#t;constructor(e,r){this.#e=e,this.#r=r}async start(){let e=this.#t=c.create(),r=await this.#e();if(r){e.resolve(r);return}this.#o=new MutationObserver(async()=>{let o=await this.#e();o&&(e.resolve(o),await this.stop())}),this.#o.observe(this.#r,{childList:!0,subtree:!0,attributes:!0})}async stop(){u(this.#t,\"Polling never started.\"),this.#t.finished()||this.#t.reject(new Error(\"Polling stopped\")),this.#o&&(this.#o.disconnect(),this.#o=void 0)}result(){return u(this.#t,\"Polling never started.\"),this.#t.valueOrThrow()}},w=class{#e;#r;constructor(e){this.#e=e}async start(){let e=this.#r=c.create(),r=await this.#e();if(r){e.resolve(r);return}let o=async()=>{if(e.finished())return;let s=await this.#e();if(!s){window.requestAnimationFrame(o);return}e.resolve(s),await this.stop()};window.requestAnimationFrame(o)}async stop(){u(this.#r,\"Polling never started.\"),this.#r.finished()||this.#r.reject(new Error(\"Polling stopped\"))}result(){return u(this.#r,\"Polling never started.\"),this.#r.valueOrThrow()}},T=class{#e;#r;#o;#t;constructor(e,r){this.#e=e,this.#r=r}async start(){let e=this.#t=c.create(),r=await this.#e();if(r){e.resolve(r);return}this.#o=setInterval(async()=>{let o=await this.#e();o&&(e.resolve(o),await this.stop())},this.#r)}async stop(){u(this.#t,\"Polling never started.\"),this.#t.finished()||this.#t.reject(new Error(\"Polling stopped\")),this.#o&&(clearInterval(this.#o),this.#o=void 0)}result(){return u(this.#t,\"Polling never started.\"),this.#t.valueOrThrow()}};var _={};l(_,{PCombinator:()=>H,pQuerySelector:()=>fe,pQuerySelectorAll:()=>$});var a=class{static async*map(e,r){for await(let o of e)yield await r(o)}static async*flatMap(e,r){for await(let o of e)yield*r(o)}static async collect(e){let r=[];for await(let o of e)r.push(o);return r}static async first(e){for await(let r of e)return r}};var C={};l(C,{textQuerySelectorAll:()=>m});var re=new Set([\"checkbox\",\"image\",\"radio\"]),oe=t=>t instanceof HTMLSelectElement||t instanceof HTMLTextAreaElement||t instanceof HTMLInputElement&&!re.has(t.type),se=new Set([\"SCRIPT\",\"STYLE\"]),f=t=>!se.has(t.nodeName)&&!document.head?.contains(t),I=new WeakMap,F=t=>{for(;t;)I.delete(t),t instanceof ShadowRoot?t=t.host:t=t.parentNode},j=new WeakSet,ne=new MutationObserver(t=>{for(let e of t)F(e.target)}),d=t=>{let e=I.get(t);if(e||(e={full:\"\",immediate:[]},!f(t)))return e;let r=\"\";if(oe(t))e.full=t.value,e.immediate.push(t.value),t.addEventListener(\"input\",o=>{F(o.target)},{once:!0,capture:!0});else{for(let o=t.firstChild;o;o=o.nextSibling){if(o.nodeType===Node.TEXT_NODE){e.full+=o.nodeValue??\"\",r+=o.nodeValue??\"\";continue}r&&e.immediate.push(r),r=\"\",o.nodeType===Node.ELEMENT_NODE&&(e.full+=d(o).full)}r&&e.immediate.push(r),t instanceof Element&&t.shadowRoot&&(e.full+=d(t.shadowRoot).full),j.has(t)||(ne.observe(t,{childList:!0,characterData:!0,subtree:!0}),j.add(t))}return I.set(t,e),e};var m=function*(t,e){let r=!1;for(let o of t.childNodes)if(o instanceof Element&&f(o)){let s;o.shadowRoot?s=m(o.shadowRoot,e):s=m(o,e);for(let i of s)yield i,r=!0}r||t instanceof Element&&f(t)&&d(t).full.includes(e)&&(yield t)};var k={};l(k,{checkVisibility:()=>le,pierce:()=>S,pierceAll:()=>O});var ie=[\"hidden\",\"collapse\"],le=(t,e)=>{if(!t)return e===!1;if(e===void 0)return t;let r=t.nodeType===Node.TEXT_NODE?t.parentElement:t,o=window.getComputedStyle(r),s=o&&!ie.includes(o.visibility)&&!ae(r);return e===s?t:!1};function ae(t){let e=t.getBoundingClientRect();return e.width===0||e.height===0}var ce=t=>\"shadowRoot\"in t&&t.shadowRoot instanceof ShadowRoot;function*S(t){ce(t)?yield t.shadowRoot:yield t}function*O(t){t=S(t).next().value,yield t;let e=[document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT)];for(let r of e){let o;for(;o=r.nextNode();)o.shadowRoot&&(yield o.shadowRoot,e.push(document.createTreeWalker(o.shadowRoot,NodeFilter.SHOW_ELEMENT)))}}var D={};l(D,{xpathQuerySelectorAll:()=>q});var q=function*(t,e,r=-1){let s=(t.ownerDocument||document).evaluate(e,t,null,XPathResult.ORDERED_NODE_ITERATOR_TYPE),i=[],n;for(;(n=s.iterateNext())&&(i.push(n),!(r&&i.length===r)););for(let h=0;h<i.length;h++)n=i[h],yield n,delete i[h]};var ue=/[-\\w\\P{ASCII}*]/u,H=(r=>(r.Descendent=\">>>\",r.Child=\">>>>\",r))(H||{}),V=t=>\"querySelectorAll\"in t,Q=class{#e;#r=[];#o=void 0;elements;constructor(e,r){this.elements=[e],this.#e=r,this.#t()}async run(){if(typeof this.#o==\"string\")switch(this.#o.trimStart()){case\":scope\":this.#t();break}for(;this.#o!==void 0;this.#t()){let e=this.#o;typeof e==\"string\"?e[0]&&ue.test(e[0])?this.elements=a.flatMap(this.elements,async function*(r){V(r)&&(yield*r.querySelectorAll(e))}):this.elements=a.flatMap(this.elements,async function*(r){if(!r.parentElement){if(!V(r))return;yield*r.querySelectorAll(e);return}let o=0;for(let s of r.parentElement.children)if(++o,s===r)break;yield*r.parentElement.querySelectorAll(`:scope>:nth-child(${o})${e}`)}):this.elements=a.flatMap(this.elements,async function*(r){switch(e.name){case\"text\":yield*m(r,e.value);break;case\"xpath\":yield*q(r,e.value);break;case\"aria\":yield*x(r,e.value);break;default:let o=P.get(e.name);if(!o)throw new Error(`Unknown selector type: ${e.name}`);yield*o.querySelectorAll(r,e.value)}})}}#t(){if(this.#r.length!==0){this.#o=this.#r.shift();return}if(this.#e.length===0){this.#o=void 0;return}let e=this.#e.shift();switch(e){case\">>>>\":{this.elements=a.flatMap(this.elements,S),this.#t();break}case\">>>\":{this.elements=a.flatMap(this.elements,O),this.#t();break}default:this.#r=e,this.#t();break}}},M=class{#e=new WeakMap;calculate(e,r=[]){if(e===null)return r;e instanceof ShadowRoot&&(e=e.host);let o=this.#e.get(e);if(o)return[...o,...r];let s=0;for(let n=e.previousSibling;n;n=n.previousSibling)++s;let i=this.calculate(e.parentNode,[s]);return this.#e.set(e,i),[...i,...r]}},U=(t,e)=>{if(t.length+e.length===0)return 0;let[r=-1,...o]=t,[s=-1,...i]=e;return r===s?U(o,i):r<s?-1:1},de=async function*(t){let e=new Set;for await(let o of t)e.add(o);let r=new M;yield*[...e.values()].map(o=>[o,r.calculate(o)]).sort(([,o],[,s])=>U(o,s)).map(([o])=>o)},$=function(t,e){let r=JSON.parse(e);if(r.some(o=>{let s=0;return o.some(i=>(typeof i==\"string\"?++s:s=0,s>1))}))throw new Error(\"Multiple deep combinators found in sequence.\");return de(a.flatMap(r,o=>{let s=new Q(t,o);return s.run(),s.elements}))},fe=async function(t,e){for await(let r of $(t,e))return r;return null};var me=Object.freeze({...b,...A,...R,..._,...C,...k,...D,...E,Deferred:c,createFunction:W,createTextContent:d,IntervalPoller:T,isSuitableNodeForTextMatching:f,MutationPoller:y,RAFPoller:w}),he=me;\n";
|
package/src/generated/version.ts
CHANGED
|
@@ -154,7 +154,7 @@ export abstract class BrowserLauncher {
|
|
|
154
154
|
};
|
|
155
155
|
|
|
156
156
|
try {
|
|
157
|
-
if (this.#browser === 'firefox'
|
|
157
|
+
if (this.#browser === 'firefox') {
|
|
158
158
|
browser = await this.createBiDiBrowser(
|
|
159
159
|
browserProcess,
|
|
160
160
|
browserCloseCallback,
|
|
@@ -372,7 +372,7 @@ export abstract class BrowserLauncher {
|
|
|
372
372
|
*/
|
|
373
373
|
protected async createBiDiOverCdpBrowser(
|
|
374
374
|
browserProcess: ReturnType<typeof launch>,
|
|
375
|
-
|
|
375
|
+
cdpConnection: Connection,
|
|
376
376
|
closeCallback: BrowserCloseCallback,
|
|
377
377
|
opts: {
|
|
378
378
|
defaultViewport: Viewport | null;
|
|
@@ -380,11 +380,14 @@ export abstract class BrowserLauncher {
|
|
|
380
380
|
networkEnabled: boolean;
|
|
381
381
|
},
|
|
382
382
|
): Promise<Browser> {
|
|
383
|
+
const bidiOnly = process.env['PUPPETEER_WEBDRIVER_BIDI_ONLY'] === 'true';
|
|
383
384
|
const BiDi = await import(/* webpackIgnore: true */ '../bidi/bidi.js');
|
|
384
|
-
const bidiConnection = await BiDi.connectBidiOverCdp(
|
|
385
|
+
const bidiConnection = await BiDi.connectBidiOverCdp(cdpConnection);
|
|
385
386
|
return await BiDi.BidiBrowser.create({
|
|
386
387
|
connection: bidiConnection,
|
|
387
|
-
|
|
388
|
+
// Do not provide CDP connection to Browser, if BiDi-only mode is enabled. This
|
|
389
|
+
// would restrict Browser to use only BiDi endpoint.
|
|
390
|
+
cdpConnection: bidiOnly ? undefined : cdpConnection,
|
|
388
391
|
closeCallback,
|
|
389
392
|
process: browserProcess.nodeProcess,
|
|
390
393
|
defaultViewport: opts.defaultViewport,
|
|
@@ -17,7 +17,7 @@ export class PipeTransport implements ConnectionTransport {
|
|
|
17
17
|
#subscriptions = new DisposableStack();
|
|
18
18
|
|
|
19
19
|
#isClosed = false;
|
|
20
|
-
#pendingMessage =
|
|
20
|
+
#pendingMessage: Buffer[] = [];
|
|
21
21
|
|
|
22
22
|
onclose?: () => void;
|
|
23
23
|
onmessage?: (value: string) => void;
|
|
@@ -34,7 +34,7 @@ export class PipeTransport implements ConnectionTransport {
|
|
|
34
34
|
pipeRead as unknown as EventEmitter<Record<string, any>>,
|
|
35
35
|
),
|
|
36
36
|
);
|
|
37
|
-
pipeReadEmitter.on('data',
|
|
37
|
+
pipeReadEmitter.on('data', buffer => {
|
|
38
38
|
return this.#dispatch(buffer);
|
|
39
39
|
});
|
|
40
40
|
pipeReadEmitter.on('close', () => {
|
|
@@ -60,34 +60,32 @@ export class PipeTransport implements ConnectionTransport {
|
|
|
60
60
|
this.#pipeWrite.write('\0');
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
#dispatch(buffer: Buffer): void {
|
|
63
|
+
#dispatch(buffer: Buffer<ArrayBuffer>): void {
|
|
64
64
|
assert(!this.#isClosed, '`PipeTransport` is closed.');
|
|
65
65
|
|
|
66
|
-
|
|
67
|
-
if (
|
|
68
|
-
this.#pendingMessage += buffer.toString();
|
|
66
|
+
this.#pendingMessage.push(buffer);
|
|
67
|
+
if (buffer.indexOf('\0') === -1) {
|
|
69
68
|
return;
|
|
70
69
|
}
|
|
71
|
-
const
|
|
72
|
-
setImmediate(() => {
|
|
73
|
-
if (this.onmessage) {
|
|
74
|
-
this.onmessage.call(null, message);
|
|
75
|
-
}
|
|
76
|
-
});
|
|
70
|
+
const concatBuffer = Buffer.concat(this.#pendingMessage);
|
|
77
71
|
|
|
78
|
-
let start =
|
|
79
|
-
end =
|
|
72
|
+
let start = 0;
|
|
73
|
+
let end = concatBuffer.indexOf('\0');
|
|
80
74
|
while (end !== -1) {
|
|
81
|
-
const message =
|
|
75
|
+
const message = concatBuffer.toString(undefined, start, end);
|
|
82
76
|
setImmediate(() => {
|
|
83
77
|
if (this.onmessage) {
|
|
84
78
|
this.onmessage.call(null, message);
|
|
85
79
|
}
|
|
86
80
|
});
|
|
87
81
|
start = end + 1;
|
|
88
|
-
end =
|
|
82
|
+
end = concatBuffer.indexOf('\0', start);
|
|
83
|
+
}
|
|
84
|
+
if (start >= concatBuffer.length) {
|
|
85
|
+
this.#pendingMessage = [];
|
|
86
|
+
} else {
|
|
87
|
+
this.#pendingMessage = [concatBuffer.subarray(start)];
|
|
89
88
|
}
|
|
90
|
-
this.#pendingMessage = buffer.toString(undefined, start);
|
|
91
89
|
}
|
|
92
90
|
|
|
93
91
|
close(): void {
|
|
@@ -44,13 +44,11 @@ import type {ChromeReleaseChannel, LaunchOptions} from './LaunchOptions.js';
|
|
|
44
44
|
* ```ts
|
|
45
45
|
* import puppeteer from 'puppeteer';
|
|
46
46
|
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
* await browser.close();
|
|
53
|
-
* })();
|
|
47
|
+
* const browser = await puppeteer.launch();
|
|
48
|
+
* const page = await browser.newPage();
|
|
49
|
+
* await page.goto('https://www.google.com');
|
|
50
|
+
* // other actions...
|
|
51
|
+
* await browser.close();
|
|
54
52
|
* ```
|
|
55
53
|
*
|
|
56
54
|
* Once you have created a `page` you have access to a large API to interact
|
package/src/revisions.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* @internal
|
|
9
9
|
*/
|
|
10
10
|
export const PUPPETEER_REVISIONS = Object.freeze({
|
|
11
|
-
chrome: '
|
|
12
|
-
'chrome-headless-shell': '
|
|
13
|
-
firefox: 'stable_143.0',
|
|
11
|
+
chrome: '141.0.7390.54',
|
|
12
|
+
'chrome-headless-shell': '141.0.7390.54',
|
|
13
|
+
firefox: 'stable_143.0.3',
|
|
14
14
|
});
|
package/src/util/Function.ts
CHANGED
|
@@ -29,37 +29,29 @@ export const createFunction = (
|
|
|
29
29
|
*/
|
|
30
30
|
export function stringifyFunction(fn: (...args: never) => unknown): string {
|
|
31
31
|
let value = fn.toString();
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
`Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive`,
|
|
38
|
-
) ||
|
|
39
|
-
(err as Error).message.includes(
|
|
40
|
-
'Evaluating a string as JavaScript violates the following Content Security Policy',
|
|
41
|
-
)
|
|
42
|
-
) {
|
|
43
|
-
// The content security policy does not allow Function eval. Let's
|
|
44
|
-
// assume the value might be valid as is.
|
|
45
|
-
return value;
|
|
46
|
-
}
|
|
47
|
-
// This means we might have a function shorthand (e.g. `test(){}`). Let's
|
|
48
|
-
// try prefixing.
|
|
49
|
-
let prefix = 'function ';
|
|
50
|
-
if (value.startsWith('async ')) {
|
|
51
|
-
prefix = `async ${prefix}`;
|
|
52
|
-
value = value.substring('async '.length);
|
|
53
|
-
}
|
|
54
|
-
value = `${prefix}${value}`;
|
|
55
|
-
try {
|
|
56
|
-
new Function(`(${value})`);
|
|
57
|
-
} catch {
|
|
58
|
-
// We tried hard to serialize, but there's a weird beast here.
|
|
59
|
-
throw new Error('Passed function cannot be serialized!');
|
|
60
|
-
}
|
|
32
|
+
if (
|
|
33
|
+
value.match(/^(async )*function(\(|\s)/) ||
|
|
34
|
+
value.match(/^(async )*function\s*\*\s*/)
|
|
35
|
+
) {
|
|
36
|
+
return value;
|
|
61
37
|
}
|
|
62
|
-
|
|
38
|
+
const isArrow =
|
|
39
|
+
value.startsWith('(') ||
|
|
40
|
+
value.match(/^async\s*\(/) ||
|
|
41
|
+
value.match(
|
|
42
|
+
/^(async)*\s*(?:[$_\p{ID_Start}])(?:[$\u200C\u200D\p{ID_Continue}])*\s*=>/u,
|
|
43
|
+
);
|
|
44
|
+
if (isArrow) {
|
|
45
|
+
return value;
|
|
46
|
+
}
|
|
47
|
+
// This means we might have a function shorthand (e.g. `test(){}`). Let's
|
|
48
|
+
// try prefixing.
|
|
49
|
+
let prefix = 'function ';
|
|
50
|
+
if (value.startsWith('async ')) {
|
|
51
|
+
prefix = `async ${prefix}`;
|
|
52
|
+
value = value.substring('async '.length);
|
|
53
|
+
}
|
|
54
|
+
return `${prefix}${value}`;
|
|
63
55
|
}
|
|
64
56
|
|
|
65
57
|
/**
|