@checkly/playwright-core 1.48.22 → 1.48.23
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/lib/checkly/secretsFilter.js +29 -6
- package/lib/client/clientStackTrace.js +65 -0
- package/lib/client/fileUtils.js +31 -0
- package/lib/client/platform.js +71 -0
- package/lib/client/timeoutSettings.js +65 -0
- package/lib/client/webSocket.js +106 -0
- package/lib/generated/clockSource.js +2 -1
- package/lib/generated/consoleApiSource.js +2 -1
- package/lib/generated/injectedScriptSource.js +2 -1
- package/lib/generated/pollingRecorderSource.js +2 -1
- package/lib/generated/utilityScriptSource.js +2 -1
- package/lib/generated/webSocketMockSource.js +2 -1
- package/lib/server/callLog.js +79 -0
- package/lib/server/harBackend.js +157 -0
- package/lib/server/localUtils.js +203 -0
- package/lib/server/recorder/chat.js +177 -0
- package/lib/server/storageScript.js +160 -0
- package/lib/server/timeoutSettings.js +74 -0
- package/lib/server/utils/ascii.js +31 -0
- package/lib/server/utils/comparators.js +159 -0
- package/lib/server/utils/crypto.js +171 -0
- package/lib/server/utils/debug.js +38 -0
- package/lib/server/utils/debugLogger.js +93 -0
- package/lib/server/utils/env.js +53 -0
- package/lib/server/utils/eventsHelper.js +38 -0
- package/lib/server/utils/expectUtils.js +33 -0
- package/lib/server/utils/fileUtils.js +204 -0
- package/lib/server/utils/happyEyeballs.js +209 -0
- package/lib/server/utils/hostPlatform.js +145 -0
- package/lib/server/utils/httpServer.js +233 -0
- package/lib/server/utils/image_tools/colorUtils.js +98 -0
- package/lib/server/utils/image_tools/compare.js +108 -0
- package/lib/server/utils/image_tools/imageChannel.js +70 -0
- package/lib/server/utils/image_tools/stats.js +102 -0
- package/lib/server/utils/linuxUtils.js +58 -0
- package/lib/server/utils/network.js +160 -0
- package/lib/server/utils/nodePlatform.js +140 -0
- package/lib/server/utils/pipeTransport.js +82 -0
- package/lib/server/utils/processLauncher.js +248 -0
- package/lib/server/utils/profiler.js +52 -0
- package/lib/server/utils/socksProxy.js +570 -0
- package/lib/server/utils/spawnAsync.js +45 -0
- package/lib/server/utils/task.js +58 -0
- package/lib/server/utils/userAgent.js +91 -0
- package/lib/server/utils/wsServer.js +128 -0
- package/lib/server/utils/zipFile.js +75 -0
- package/lib/server/utils/zones.js +54 -0
- package/lib/utils/isomorphic/ariaSnapshot.js +392 -0
- package/lib/utils/isomorphic/assert.js +25 -0
- package/lib/utils/isomorphic/colors.js +65 -0
- package/lib/utils/isomorphic/headers.js +52 -0
- package/lib/utils/isomorphic/manualPromise.js +107 -0
- package/lib/utils/isomorphic/multimap.js +73 -0
- package/lib/utils/isomorphic/rtti.js +41 -0
- package/lib/utils/isomorphic/semaphore.js +51 -0
- package/lib/utils/isomorphic/stackTrace.js +169 -0
- package/lib/utils/isomorphic/time.js +25 -0
- package/lib/utils/isomorphic/timeoutRunner.js +66 -0
- package/lib/utils/isomorphic/types.js +5 -0
- package/lib/utils.js +447 -0
- package/lib/vite/traceViewer/assets/{codeMirrorModule-pBPtArIT.js → codeMirrorModule-Bh1rfd2w.js} +14 -14
- package/lib/vite/traceViewer/assets/codeMirrorModule-DZoSgqUd.js +24 -0
- package/lib/vite/traceViewer/assets/codeMirrorModule-xvopPhZ4.js +24 -0
- package/lib/vite/traceViewer/assets/{inspectorTab-BuJ3wAX_.js → inspectorTab-7GHnKvSD.js} +2 -2
- package/lib/vite/traceViewer/assets/{inspectorTab-Soeeuvzv.js → inspectorTab-BHcfR9dD.js} +3 -3
- package/lib/vite/traceViewer/assets/inspectorTab-wfvwpMHs.js +64 -0
- package/lib/vite/traceViewer/assets/{workbench-DdmJ9AJV.js → workbench-C6nMfKVy.js} +1 -1
- package/lib/vite/traceViewer/assets/{workbench-lypYlf00.js → workbench-DZqNXdoV.js} +1 -1
- package/lib/vite/traceViewer/assets/workbench-LKskf2Iy.js +9 -0
- package/lib/vite/traceViewer/{embedded.BkvOrz5Z.js → embedded.BXYl5zRv.js} +1 -1
- package/lib/vite/traceViewer/{embedded.DInvAijy.js → embedded.CShPz96b.js} +1 -1
- package/lib/vite/traceViewer/embedded.Dxe2heQk.js +2 -0
- package/lib/vite/traceViewer/embedded.html +3 -3
- package/lib/vite/traceViewer/{index.Dha3cgqs.js → index.BZ9CE8t3.js} +1 -1
- package/lib/vite/traceViewer/{index._Iolt-uE.js → index.CB297BuW.js} +1 -1
- package/lib/vite/traceViewer/index.DZkJsFod.js +2 -0
- package/lib/vite/traceViewer/index.html +3 -3
- package/lib/vite/traceViewer/{recorder.DNMfnSiu.js → recorder.BVExlUUk.js} +1 -1
- package/lib/vite/traceViewer/{recorder.DTSaNaly.js → recorder.C4zxcvd2.js} +1 -1
- package/lib/vite/traceViewer/recorder.C88JDknq.js +2 -0
- package/lib/vite/traceViewer/recorder.html +2 -2
- package/lib/vite/traceViewer/{uiMode.BM7yhjzl.js → uiMode.2tr9k625.js} +1 -1
- package/lib/vite/traceViewer/{uiMode.Cr1tvTWS.js → uiMode.DXa41vt9.js} +1 -1
- package/lib/vite/traceViewer/uiMode.DjTS7tqC.js +5 -0
- package/lib/vite/traceViewer/uiMode.html +3 -3
- package/package.json +1 -1
- package/lib/vite/traceViewer/assets/codeMirrorModule-tzBrK1V4.js +0 -24
|
@@ -13,11 +13,34 @@ const IdentityFunction = s => s;
|
|
|
13
13
|
const secretsFilter = () => {
|
|
14
14
|
const disabled = process.env['CHECKLY_INTERNAL_ENABLE_PATCHED_TRACING'] !== 'true';
|
|
15
15
|
if (disabled) return IdentityFunction;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
|
|
17
|
+
// Cache for regex to avoid recompiling on every call
|
|
18
|
+
let cachedRegex = null;
|
|
19
|
+
let cachedKeys = '';
|
|
20
|
+
|
|
21
|
+
// Regex to filter out console markers
|
|
22
|
+
const consoleMarkerRegex = /\[CHECKLY_RUNTIME_SECRET\].*?\[\/CHECKLY_RUNTIME_SECRET\]/g;
|
|
23
|
+
return s => {
|
|
24
|
+
const keys = process.env['CHECKLY_INTERNAL_REPLACE_TRACE_KEYS'] || '[]';
|
|
25
|
+
|
|
26
|
+
// Only recompile regex if keys have changed (handles runtime CHECKLY_SECRET_ variables)
|
|
27
|
+
if (keys !== cachedKeys) {
|
|
28
|
+
const keylist = JSON.parse(keys);
|
|
29
|
+
if (keylist.length === 0) {
|
|
30
|
+
cachedRegex = null;
|
|
31
|
+
} else {
|
|
32
|
+
const escapedList = keylist.map(_escapeRegExp.default);
|
|
33
|
+
cachedRegex = new RegExp(escapedList.join('|'), 'g');
|
|
34
|
+
}
|
|
35
|
+
cachedKeys = keys;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// First filter out console markers entirely
|
|
39
|
+
let filtered = s.replace(consoleMarkerRegex, '');
|
|
40
|
+
|
|
41
|
+
// Scrub secrets
|
|
42
|
+
if (cachedRegex) filtered = filtered.replaceAll(cachedRegex, '*********');
|
|
43
|
+
return filtered;
|
|
44
|
+
};
|
|
22
45
|
};
|
|
23
46
|
exports.secretsFilter = secretsFilter;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.captureLibraryStackTrace = captureLibraryStackTrace;
|
|
7
|
+
var _stackTrace = require("../utils/isomorphic/stackTrace");
|
|
8
|
+
/**
|
|
9
|
+
* Copyright (c) Microsoft Corporation.
|
|
10
|
+
*
|
|
11
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
12
|
+
* you may not use this file except in compliance with the License.
|
|
13
|
+
* You may obtain a copy of the License at
|
|
14
|
+
*
|
|
15
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
+
*
|
|
17
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
18
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
19
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
+
* See the License for the specific language governing permissions and
|
|
21
|
+
* limitations under the License.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
function captureLibraryStackTrace(platform) {
|
|
25
|
+
const stack = (0, _stackTrace.captureRawStack)();
|
|
26
|
+
let parsedFrames = stack.map(line => {
|
|
27
|
+
const frame = (0, _stackTrace.parseStackFrame)(line, platform.pathSeparator, platform.showInternalStackFrames());
|
|
28
|
+
if (!frame || !frame.file) return null;
|
|
29
|
+
const isPlaywrightLibrary = !!platform.coreDir && frame.file.startsWith(platform.coreDir);
|
|
30
|
+
const parsed = {
|
|
31
|
+
frame,
|
|
32
|
+
frameText: line,
|
|
33
|
+
isPlaywrightLibrary
|
|
34
|
+
};
|
|
35
|
+
return parsed;
|
|
36
|
+
}).filter(Boolean);
|
|
37
|
+
let apiName = '';
|
|
38
|
+
|
|
39
|
+
// Deepest transition between non-client code calling into client
|
|
40
|
+
// code is the api entry.
|
|
41
|
+
for (let i = 0; i < parsedFrames.length - 1; i++) {
|
|
42
|
+
const parsedFrame = parsedFrames[i];
|
|
43
|
+
if (parsedFrame.isPlaywrightLibrary && !parsedFrames[i + 1].isPlaywrightLibrary) {
|
|
44
|
+
apiName = apiName || normalizeAPIName(parsedFrame.frame.function);
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function normalizeAPIName(name) {
|
|
49
|
+
if (!name) return '';
|
|
50
|
+
const match = name.match(/(API|JS|CDP|[A-Z])(.*)/);
|
|
51
|
+
if (!match) return name;
|
|
52
|
+
return match[1].toLowerCase() + match[2];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// This is for the inspector so that it did not include the test runner stack frames.
|
|
56
|
+
const filterPrefixes = platform.boxedStackPrefixes();
|
|
57
|
+
parsedFrames = parsedFrames.filter(f => {
|
|
58
|
+
if (filterPrefixes.some(prefix => f.frame.file.startsWith(prefix))) return false;
|
|
59
|
+
return true;
|
|
60
|
+
});
|
|
61
|
+
return {
|
|
62
|
+
frames: parsedFrames.map(p => p.frame),
|
|
63
|
+
apiName
|
|
64
|
+
};
|
|
65
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.fileUploadSizeLimit = void 0;
|
|
7
|
+
exports.mkdirIfNeeded = mkdirIfNeeded;
|
|
8
|
+
/**
|
|
9
|
+
* Copyright (c) Microsoft Corporation.
|
|
10
|
+
*
|
|
11
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
12
|
+
* you may not use this file except in compliance with the License.
|
|
13
|
+
* You may obtain a copy of the License at
|
|
14
|
+
*
|
|
15
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
+
*
|
|
17
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
18
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
19
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
+
* See the License for the specific language governing permissions and
|
|
21
|
+
* limitations under the License.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
// Keep in sync with the server.
|
|
25
|
+
const fileUploadSizeLimit = exports.fileUploadSizeLimit = 50 * 1024 * 1024;
|
|
26
|
+
async function mkdirIfNeeded(platform, filePath) {
|
|
27
|
+
// This will harmlessly throw on windows if the dirname is the root directory.
|
|
28
|
+
await platform.fs().promises.mkdir(platform.path().dirname(filePath), {
|
|
29
|
+
recursive: true
|
|
30
|
+
}).catch(() => {});
|
|
31
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.emptyPlatform = void 0;
|
|
7
|
+
var _colors = require("../utils/isomorphic/colors");
|
|
8
|
+
/**
|
|
9
|
+
* Copyright (c) Microsoft Corporation.
|
|
10
|
+
*
|
|
11
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
12
|
+
* you may not use this file except in compliance with the License.
|
|
13
|
+
* You may obtain a copy of the License at
|
|
14
|
+
*
|
|
15
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
+
*
|
|
17
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
18
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
19
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
+
* See the License for the specific language governing permissions and
|
|
21
|
+
* limitations under the License.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
const noopZone = {
|
|
25
|
+
push: () => noopZone,
|
|
26
|
+
pop: () => noopZone,
|
|
27
|
+
run: func => func(),
|
|
28
|
+
data: () => undefined
|
|
29
|
+
};
|
|
30
|
+
const emptyPlatform = exports.emptyPlatform = {
|
|
31
|
+
name: 'empty',
|
|
32
|
+
boxedStackPrefixes: () => [],
|
|
33
|
+
calculateSha1: async () => {
|
|
34
|
+
throw new Error('Not implemented');
|
|
35
|
+
},
|
|
36
|
+
colors: _colors.webColors,
|
|
37
|
+
createGuid: () => {
|
|
38
|
+
throw new Error('Not implemented');
|
|
39
|
+
},
|
|
40
|
+
defaultMaxListeners: () => 10,
|
|
41
|
+
env: {},
|
|
42
|
+
fs: () => {
|
|
43
|
+
throw new Error('Not implemented');
|
|
44
|
+
},
|
|
45
|
+
inspectCustom: undefined,
|
|
46
|
+
isDebugMode: () => false,
|
|
47
|
+
isJSDebuggerAttached: () => false,
|
|
48
|
+
isLogEnabled(name) {
|
|
49
|
+
return false;
|
|
50
|
+
},
|
|
51
|
+
isUnderTest: () => false,
|
|
52
|
+
log(name, message) {},
|
|
53
|
+
path: () => {
|
|
54
|
+
throw new Error('Function not implemented.');
|
|
55
|
+
},
|
|
56
|
+
pathSeparator: '/',
|
|
57
|
+
showInternalStackFrames: () => false,
|
|
58
|
+
streamFile(path, writable) {
|
|
59
|
+
throw new Error('Streams are not available');
|
|
60
|
+
},
|
|
61
|
+
streamReadable: channel => {
|
|
62
|
+
throw new Error('Streams are not available');
|
|
63
|
+
},
|
|
64
|
+
streamWritable: channel => {
|
|
65
|
+
throw new Error('Streams are not available');
|
|
66
|
+
},
|
|
67
|
+
zones: {
|
|
68
|
+
empty: noopZone,
|
|
69
|
+
current: () => noopZone
|
|
70
|
+
}
|
|
71
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.TimeoutSettings = exports.DEFAULT_TIMEOUT = exports.DEFAULT_LAUNCH_TIMEOUT = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Copyright 2019 Google Inc. All rights reserved.
|
|
9
|
+
* Modifications copyright (c) Microsoft Corporation.
|
|
10
|
+
*
|
|
11
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
12
|
+
* you may not use this file except in compliance with the License.
|
|
13
|
+
* You may obtain a copy of the License at
|
|
14
|
+
*
|
|
15
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
+
*
|
|
17
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
18
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
19
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
+
* See the License for the specific language governing permissions and
|
|
21
|
+
* limitations under the License.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
// Keep in sync with server.
|
|
25
|
+
const DEFAULT_TIMEOUT = exports.DEFAULT_TIMEOUT = 30000;
|
|
26
|
+
const DEFAULT_LAUNCH_TIMEOUT = exports.DEFAULT_LAUNCH_TIMEOUT = 3 * 60 * 1000; // 3 minutes
|
|
27
|
+
|
|
28
|
+
class TimeoutSettings {
|
|
29
|
+
constructor(platform, parent) {
|
|
30
|
+
this._parent = void 0;
|
|
31
|
+
this._defaultTimeout = void 0;
|
|
32
|
+
this._defaultNavigationTimeout = void 0;
|
|
33
|
+
this._platform = void 0;
|
|
34
|
+
this._parent = parent;
|
|
35
|
+
this._platform = platform;
|
|
36
|
+
}
|
|
37
|
+
setDefaultTimeout(timeout) {
|
|
38
|
+
this._defaultTimeout = timeout;
|
|
39
|
+
}
|
|
40
|
+
setDefaultNavigationTimeout(timeout) {
|
|
41
|
+
this._defaultNavigationTimeout = timeout;
|
|
42
|
+
}
|
|
43
|
+
defaultNavigationTimeout() {
|
|
44
|
+
return this._defaultNavigationTimeout;
|
|
45
|
+
}
|
|
46
|
+
defaultTimeout() {
|
|
47
|
+
return this._defaultTimeout;
|
|
48
|
+
}
|
|
49
|
+
navigationTimeout(options) {
|
|
50
|
+
if (typeof options.timeout === 'number') return options.timeout;
|
|
51
|
+
if (this._defaultNavigationTimeout !== undefined) return this._defaultNavigationTimeout;
|
|
52
|
+
if (this._platform.isDebugMode()) return 0;
|
|
53
|
+
if (this._defaultTimeout !== undefined) return this._defaultTimeout;
|
|
54
|
+
if (this._parent) return this._parent.navigationTimeout(options);
|
|
55
|
+
return DEFAULT_TIMEOUT;
|
|
56
|
+
}
|
|
57
|
+
timeout(options) {
|
|
58
|
+
if (typeof options.timeout === 'number') return options.timeout;
|
|
59
|
+
if (this._platform.isDebugMode()) return 0;
|
|
60
|
+
if (this._defaultTimeout !== undefined) return this._defaultTimeout;
|
|
61
|
+
if (this._parent) return this._parent.timeout(options);
|
|
62
|
+
return DEFAULT_TIMEOUT;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.TimeoutSettings = TimeoutSettings;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.connectOverWebSocket = connectOverWebSocket;
|
|
7
|
+
var _connection = require("./connection");
|
|
8
|
+
/**
|
|
9
|
+
* Copyright (c) Microsoft Corporation.
|
|
10
|
+
*
|
|
11
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
12
|
+
* you may not use this file except in compliance with the License.
|
|
13
|
+
* You may obtain a copy of the License at
|
|
14
|
+
*
|
|
15
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
+
*
|
|
17
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
18
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
19
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
+
* See the License for the specific language governing permissions and
|
|
21
|
+
* limitations under the License.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
async function connectOverWebSocket(parentConnection, params) {
|
|
25
|
+
const localUtils = parentConnection.localUtils();
|
|
26
|
+
const transport = localUtils ? new JsonPipeTransport(localUtils) : new WebSocketTransport();
|
|
27
|
+
const connectHeaders = await transport.connect(params);
|
|
28
|
+
const connection = new _connection.Connection(parentConnection._platform, localUtils, parentConnection._instrumentation, connectHeaders);
|
|
29
|
+
connection.markAsRemote();
|
|
30
|
+
connection.on('close', () => transport.close());
|
|
31
|
+
let closeError;
|
|
32
|
+
const onTransportClosed = reason => {
|
|
33
|
+
connection.close(reason || closeError);
|
|
34
|
+
};
|
|
35
|
+
transport.onClose(reason => onTransportClosed(reason));
|
|
36
|
+
connection.onmessage = message => transport.send(message).catch(() => onTransportClosed());
|
|
37
|
+
transport.onMessage(message => {
|
|
38
|
+
try {
|
|
39
|
+
connection.dispatch(message);
|
|
40
|
+
} catch (e) {
|
|
41
|
+
closeError = String(e);
|
|
42
|
+
transport.close().catch(() => {});
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
return connection;
|
|
46
|
+
}
|
|
47
|
+
class JsonPipeTransport {
|
|
48
|
+
constructor(owner) {
|
|
49
|
+
this._pipe = void 0;
|
|
50
|
+
this._owner = void 0;
|
|
51
|
+
this._owner = owner;
|
|
52
|
+
}
|
|
53
|
+
async connect(params) {
|
|
54
|
+
const {
|
|
55
|
+
pipe,
|
|
56
|
+
headers: connectHeaders
|
|
57
|
+
} = await this._owner._wrapApiCall(async () => {
|
|
58
|
+
return await this._owner._channel.connect(params);
|
|
59
|
+
}, /* isInternal */true);
|
|
60
|
+
this._pipe = pipe;
|
|
61
|
+
return connectHeaders;
|
|
62
|
+
}
|
|
63
|
+
async send(message) {
|
|
64
|
+
await this._owner._wrapApiCall(async () => {
|
|
65
|
+
await this._pipe.send({
|
|
66
|
+
message
|
|
67
|
+
});
|
|
68
|
+
}, /* isInternal */true);
|
|
69
|
+
}
|
|
70
|
+
onMessage(callback) {
|
|
71
|
+
this._pipe.on('message', ({
|
|
72
|
+
message
|
|
73
|
+
}) => callback(message));
|
|
74
|
+
}
|
|
75
|
+
onClose(callback) {
|
|
76
|
+
this._pipe.on('closed', ({
|
|
77
|
+
reason
|
|
78
|
+
}) => callback(reason));
|
|
79
|
+
}
|
|
80
|
+
async close() {
|
|
81
|
+
await this._owner._wrapApiCall(async () => {
|
|
82
|
+
await this._pipe.close().catch(() => {});
|
|
83
|
+
}, /* isInternal */true);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
class WebSocketTransport {
|
|
87
|
+
constructor() {
|
|
88
|
+
this._ws = void 0;
|
|
89
|
+
}
|
|
90
|
+
async connect(params) {
|
|
91
|
+
this._ws = new window.WebSocket(params.wsEndpoint);
|
|
92
|
+
return [];
|
|
93
|
+
}
|
|
94
|
+
async send(message) {
|
|
95
|
+
this._ws.send(JSON.stringify(message));
|
|
96
|
+
}
|
|
97
|
+
onMessage(callback) {
|
|
98
|
+
this._ws.addEventListener('message', event => callback(JSON.parse(event.data)));
|
|
99
|
+
}
|
|
100
|
+
onClose(callback) {
|
|
101
|
+
this._ws.addEventListener('close', () => callback());
|
|
102
|
+
}
|
|
103
|
+
async close() {
|
|
104
|
+
this._ws.close();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -4,4 +4,5 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.source = void 0;
|
|
7
|
-
const source = exports.source = "\nvar __commonJS = obj => {\n let required = false;\n let result;\n return function __require() {\n if (!required) {\n required = true;\n let fn;\n for (const name in obj) { fn = obj[name]; break; }\n const module = { exports: {} };\n fn(module.exports, module);\n result = module.exports;\n }\n return result;\n }\n};\nvar __export = (target, all) => {for (var name in all) target[name] = all[name];};\nvar __toESM = mod => ({ ...mod, 'default': mod });\nvar __toCommonJS = mod => ({ ...mod, __esModule: true });\n\n\n// packages/playwright-core/src/server/injected/clock.ts\nvar clock_exports = {};\n__export(clock_exports, {\n ClockController: () => ClockController,\n createClock: () => createClock,\n inject: () => inject,\n install: () => install\n});\nmodule.exports = __toCommonJS(clock_exports);\nvar ClockController = class {\n constructor(embedder) {\n this._duringTick = false;\n this._timers = /* @__PURE__ */ new Map();\n this._uniqueTimerId = idCounterStart;\n this.disposables = [];\n this._log = [];\n this._now = { time: asWallTime(0), isFixedTime: false, ticks: 0, origin: asWallTime(-1) };\n this._embedder = embedder;\n }\n uninstall() {\n this.disposables.forEach((dispose) => dispose());\n this.disposables.length = 0;\n }\n now() {\n this._replayLogOnce();\n return this._now.time;\n }\n install(time) {\n this._replayLogOnce();\n this._innerSetTime(asWallTime(time));\n }\n setSystemTime(time) {\n this._replayLogOnce();\n this._innerSetTime(asWallTime(time));\n }\n setFixedTime(time) {\n this._replayLogOnce();\n this._innerSetFixedTime(asWallTime(time));\n }\n performanceNow() {\n this._replayLogOnce();\n return this._now.ticks;\n }\n _innerSetTime(time) {\n this._now.time = time;\n this._now.isFixedTime = false;\n if (this._now.origin < 0)\n this._now.origin = this._now.time;\n }\n _innerSetFixedTime(time) {\n this._innerSetTime(time);\n this._now.isFixedTime = true;\n }\n _advanceNow(to) {\n if (!this._now.isFixedTime)\n this._now.time = asWallTime(this._now.time + to - this._now.ticks);\n this._now.ticks = to;\n }\n async log(type, time, param) {\n this._log.push({ type, time, param });\n }\n async runFor(ticks) {\n this._replayLogOnce();\n if (ticks < 0)\n throw new TypeError(\"Negative ticks are not supported\");\n await this._runTo(shiftTicks(this._now.ticks, ticks));\n }\n async _runTo(to) {\n to = Math.ceil(to);\n if (this._now.ticks > to)\n return;\n let firstException;\n while (true) {\n const result = await this._callFirstTimer(to);\n if (!result.timerFound)\n break;\n firstException = firstException || result.error;\n }\n this._advanceNow(to);\n if (firstException)\n throw firstException;\n }\n async pauseAt(time) {\n this._replayLogOnce();\n this._innerPause();\n const toConsume = time - this._now.time;\n await this._innerFastForwardTo(shiftTicks(this._now.ticks, toConsume));\n return toConsume;\n }\n _innerPause() {\n this._realTime = void 0;\n this._updateRealTimeTimer();\n }\n resume() {\n this._replayLogOnce();\n this._innerResume();\n }\n _innerResume() {\n const now = this._embedder.performanceNow();\n this._realTime = { startTicks: now, lastSyncTicks: now };\n this._updateRealTimeTimer();\n }\n _updateRealTimeTimer() {\n var _a;\n if (!this._realTime) {\n (_a = this._currentRealTimeTimer) == null ? void 0 : _a.dispose();\n this._currentRealTimeTimer = void 0;\n return;\n }\n const firstTimer = this._firstTimer();\n const callAt = Math.min(firstTimer ? firstTimer.callAt : this._now.ticks + maxTimeout, this._now.ticks + 100);\n if (this._currentRealTimeTimer && this._currentRealTimeTimer.callAt < callAt)\n return;\n if (this._currentRealTimeTimer) {\n this._currentRealTimeTimer.dispose();\n this._currentRealTimeTimer = void 0;\n }\n this._currentRealTimeTimer = {\n callAt,\n dispose: this._embedder.setTimeout(() => {\n const now = this._embedder.performanceNow();\n this._currentRealTimeTimer = void 0;\n const sinceLastSync = now - this._realTime.lastSyncTicks;\n this._realTime.lastSyncTicks = now;\n void this._runTo(shiftTicks(this._now.ticks, sinceLastSync)).catch((e) => console.error(e)).then(() => this._updateRealTimeTimer());\n }, callAt - this._now.ticks)\n };\n }\n async fastForward(ticks) {\n this._replayLogOnce();\n await this._innerFastForwardTo(shiftTicks(this._now.ticks, ticks | 0));\n }\n async _innerFastForwardTo(to) {\n if (to < this._now.ticks)\n throw new Error(\"Cannot fast-forward to the past\");\n for (const timer of this._timers.values()) {\n if (to > timer.callAt)\n timer.callAt = to;\n }\n await this._runTo(to);\n }\n addTimer(options) {\n this._replayLogOnce();\n if (options.type === \"AnimationFrame\" /* AnimationFrame */ && !options.func)\n throw new Error(\"Callback must be provided to requestAnimationFrame calls\");\n if (options.type === \"IdleCallback\" /* IdleCallback */ && !options.func)\n throw new Error(\"Callback must be provided to requestIdleCallback calls\");\n if ([\"Timeout\" /* Timeout */, \"Interval\" /* Interval */].includes(options.type) && !options.func && options.delay === void 0)\n throw new Error(\"Callback must be provided to timer calls\");\n let delay = options.delay ? +options.delay : 0;\n if (!Number.isFinite(delay))\n delay = 0;\n delay = delay > maxTimeout ? 1 : delay;\n delay = Math.max(0, delay);\n const timer = {\n type: options.type,\n func: options.func,\n args: options.args || [],\n delay,\n callAt: shiftTicks(this._now.ticks, delay || (this._duringTick ? 1 : 0)),\n createdAt: this._now.ticks,\n id: this._uniqueTimerId++,\n error: new Error()\n };\n this._timers.set(timer.id, timer);\n if (this._realTime)\n this._updateRealTimeTimer();\n return timer.id;\n }\n countTimers() {\n return this._timers.size;\n }\n _firstTimer(beforeTick) {\n let firstTimer = null;\n for (const timer of this._timers.values()) {\n const isInRange = beforeTick === void 0 || timer.callAt <= beforeTick;\n if (isInRange && (!firstTimer || compareTimers(firstTimer, timer) === 1))\n firstTimer = timer;\n }\n return firstTimer;\n }\n _takeFirstTimer(beforeTick) {\n const timer = this._firstTimer(beforeTick);\n if (!timer)\n return null;\n this._advanceNow(timer.callAt);\n if (timer.type === \"Interval\" /* Interval */)\n timer.callAt = shiftTicks(timer.callAt, timer.delay);\n else\n this._timers.delete(timer.id);\n return timer;\n }\n async _callFirstTimer(beforeTick) {\n const timer = this._takeFirstTimer(beforeTick);\n if (!timer)\n return { timerFound: false };\n this._duringTick = true;\n try {\n if (typeof timer.func !== \"function\") {\n let error2;\n try {\n (() => {\n globalThis.eval(timer.func);\n })();\n } catch (e) {\n error2 = e;\n }\n await new Promise((f) => this._embedder.setTimeout(f));\n return { timerFound: true, error: error2 };\n }\n let args = timer.args;\n if (timer.type === \"AnimationFrame\" /* AnimationFrame */)\n args = [this._now.ticks];\n else if (timer.type === \"IdleCallback\" /* IdleCallback */)\n args = [{ didTimeout: false, timeRemaining: () => 0 }];\n let error;\n try {\n timer.func.apply(null, args);\n } catch (e) {\n error = e;\n }\n await new Promise((f) => this._embedder.setTimeout(f));\n return { timerFound: true, error };\n } finally {\n this._duringTick = false;\n }\n }\n getTimeToNextFrame() {\n return 16 - this._now.ticks % 16;\n }\n clearTimer(timerId, type) {\n this._replayLogOnce();\n if (!timerId) {\n return;\n }\n const id = Number(timerId);\n if (Number.isNaN(id) || id < idCounterStart) {\n const handlerName = getClearHandler(type);\n new Error(`Clock: ${handlerName} was invoked to clear a native timer instead of one created by the clock library.`);\n }\n const timer = this._timers.get(id);\n if (timer) {\n if (timer.type === type || timer.type === \"Timeout\" && type === \"Interval\" || timer.type === \"Interval\" && type === \"Timeout\") {\n this._timers.delete(id);\n } else {\n const clear = getClearHandler(type);\n const schedule = getScheduleHandler(timer.type);\n throw new Error(\n `Cannot clear timer: timer created with ${schedule}() but cleared with ${clear}()`\n );\n }\n }\n }\n _replayLogOnce() {\n if (!this._log.length)\n return;\n let lastLogTime = -1;\n let isPaused = false;\n for (const { type, time, param } of this._log) {\n if (!isPaused && lastLogTime !== -1)\n this._advanceNow(shiftTicks(this._now.ticks, time - lastLogTime));\n lastLogTime = time;\n if (type === \"install\") {\n this._innerSetTime(asWallTime(param));\n } else if (type === \"fastForward\" || type === \"runFor\") {\n this._advanceNow(shiftTicks(this._now.ticks, param));\n } else if (type === \"pauseAt\") {\n isPaused = true;\n this._innerPause();\n this._innerSetTime(asWallTime(param));\n } else if (type === \"resume\") {\n this._innerResume();\n isPaused = false;\n } else if (type === \"setFixedTime\") {\n this._innerSetFixedTime(asWallTime(param));\n } else if (type === \"setSystemTime\") {\n this._innerSetTime(asWallTime(param));\n }\n }\n if (!isPaused && lastLogTime > 0)\n this._advanceNow(shiftTicks(this._now.ticks, this._embedder.dateNow() - lastLogTime));\n this._log.length = 0;\n }\n};\nfunction mirrorDateProperties(target, source) {\n for (const prop in source) {\n if (source.hasOwnProperty(prop))\n target[prop] = source[prop];\n }\n target.toString = () => source.toString();\n target.prototype = source.prototype;\n target.parse = source.parse;\n target.UTC = source.UTC;\n target.prototype.toUTCString = source.prototype.toUTCString;\n target.isFake = true;\n return target;\n}\nfunction createDate(clock, NativeDate) {\n function ClockDate(year, month, date, hour, minute, second, ms) {\n if (!(this instanceof ClockDate))\n return new NativeDate(clock.now()).toString();\n switch (arguments.length) {\n case 0:\n return new NativeDate(clock.now());\n case 1:\n return new NativeDate(year);\n case 2:\n return new NativeDate(year, month);\n case 3:\n return new NativeDate(year, month, date);\n case 4:\n return new NativeDate(year, month, date, hour);\n case 5:\n return new NativeDate(year, month, date, hour, minute);\n case 6:\n return new NativeDate(\n year,\n month,\n date,\n hour,\n minute,\n second\n );\n default:\n return new NativeDate(\n year,\n month,\n date,\n hour,\n minute,\n second,\n ms\n );\n }\n }\n ClockDate.now = () => clock.now();\n return mirrorDateProperties(ClockDate, NativeDate);\n}\nfunction createIntl(clock, NativeIntl) {\n const ClockIntl = {};\n for (const key of Object.getOwnPropertyNames(NativeIntl))\n ClockIntl[key] = NativeIntl[key];\n ClockIntl.DateTimeFormat = function(...args) {\n const realFormatter = new NativeIntl.DateTimeFormat(...args);\n const formatter = {\n formatRange: realFormatter.formatRange.bind(realFormatter),\n formatRangeToParts: realFormatter.formatRangeToParts.bind(realFormatter),\n resolvedOptions: realFormatter.resolvedOptions.bind(realFormatter),\n format: (date) => realFormatter.format(date || clock.now()),\n formatToParts: (date) => realFormatter.formatToParts(date || clock.now())\n };\n return formatter;\n };\n ClockIntl.DateTimeFormat.prototype = Object.create(\n NativeIntl.DateTimeFormat.prototype\n );\n ClockIntl.DateTimeFormat.supportedLocalesOf = NativeIntl.DateTimeFormat.supportedLocalesOf;\n return ClockIntl;\n}\nfunction compareTimers(a, b) {\n if (a.callAt < b.callAt)\n return -1;\n if (a.callAt > b.callAt)\n return 1;\n if (a.type === \"Immediate\" /* Immediate */ && b.type !== \"Immediate\" /* Immediate */)\n return -1;\n if (a.type !== \"Immediate\" /* Immediate */ && b.type === \"Immediate\" /* Immediate */)\n return 1;\n if (a.createdAt < b.createdAt)\n return -1;\n if (a.createdAt > b.createdAt)\n return 1;\n if (a.id < b.id)\n return -1;\n if (a.id > b.id)\n return 1;\n}\nvar maxTimeout = Math.pow(2, 31) - 1;\nvar idCounterStart = 1e12;\nfunction platformOriginals(globalObject) {\n const raw = {\n setTimeout: globalObject.setTimeout,\n clearTimeout: globalObject.clearTimeout,\n setInterval: globalObject.setInterval,\n clearInterval: globalObject.clearInterval,\n requestAnimationFrame: globalObject.requestAnimationFrame ? globalObject.requestAnimationFrame : void 0,\n cancelAnimationFrame: globalObject.cancelAnimationFrame ? globalObject.cancelAnimationFrame : void 0,\n requestIdleCallback: globalObject.requestIdleCallback ? globalObject.requestIdleCallback : void 0,\n cancelIdleCallback: globalObject.cancelIdleCallback ? globalObject.cancelIdleCallback : void 0,\n Date: globalObject.Date,\n performance: globalObject.performance,\n Intl: globalObject.Intl\n };\n const bound = { ...raw };\n for (const key of Object.keys(bound)) {\n if (key !== \"Date\" && typeof bound[key] === \"function\")\n bound[key] = bound[key].bind(globalObject);\n }\n return { raw, bound };\n}\nfunction getScheduleHandler(type) {\n if (type === \"IdleCallback\" || type === \"AnimationFrame\")\n return `request${type}`;\n return `set${type}`;\n}\nfunction createApi(clock, originals) {\n return {\n setTimeout: (func, timeout, ...args) => {\n const delay = timeout ? +timeout : timeout;\n return clock.addTimer({\n type: \"Timeout\" /* Timeout */,\n func,\n args,\n delay\n });\n },\n clearTimeout: (timerId) => {\n if (timerId)\n clock.clearTimer(timerId, \"Timeout\" /* Timeout */);\n },\n setInterval: (func, timeout, ...args) => {\n const delay = timeout ? +timeout : timeout;\n return clock.addTimer({\n type: \"Interval\" /* Interval */,\n func,\n args,\n delay\n });\n },\n clearInterval: (timerId) => {\n if (timerId)\n return clock.clearTimer(timerId, \"Interval\" /* Interval */);\n },\n requestAnimationFrame: (callback) => {\n return clock.addTimer({\n type: \"AnimationFrame\" /* AnimationFrame */,\n func: callback,\n delay: clock.getTimeToNextFrame()\n });\n },\n cancelAnimationFrame: (timerId) => {\n if (timerId)\n return clock.clearTimer(timerId, \"AnimationFrame\" /* AnimationFrame */);\n },\n requestIdleCallback: (callback, options) => {\n let timeToNextIdlePeriod = 0;\n if (clock.countTimers() > 0)\n timeToNextIdlePeriod = 50;\n return clock.addTimer({\n type: \"IdleCallback\" /* IdleCallback */,\n func: callback,\n delay: (options == null ? void 0 : options.timeout) ? Math.min(options == null ? void 0 : options.timeout, timeToNextIdlePeriod) : timeToNextIdlePeriod\n });\n },\n cancelIdleCallback: (timerId) => {\n if (timerId)\n return clock.clearTimer(timerId, \"IdleCallback\" /* IdleCallback */);\n },\n Intl: originals.Intl ? createIntl(clock, originals.Intl) : void 0,\n Date: createDate(clock, originals.Date),\n performance: originals.performance ? fakePerformance(clock, originals.performance) : void 0\n };\n}\nfunction getClearHandler(type) {\n if (type === \"IdleCallback\" || type === \"AnimationFrame\")\n return `cancel${type}`;\n return `clear${type}`;\n}\nfunction fakePerformance(clock, performance) {\n const result = {\n now: () => clock.performanceNow()\n };\n result.__defineGetter__(\"timeOrigin\", () => clock._now.origin || 0);\n for (const key of Object.keys(performance.__proto__)) {\n if (key === \"now\" || key === \"timeOrigin\")\n continue;\n if (key === \"getEntries\" || key === \"getEntriesByName\" || key === \"getEntriesByType\")\n result[key] = () => [];\n else\n result[key] = () => {\n };\n }\n return result;\n}\nfunction createClock(globalObject) {\n const originals = platformOriginals(globalObject);\n const embedder = {\n dateNow: () => originals.raw.Date.now(),\n performanceNow: () => Math.ceil(originals.raw.performance.now()),\n setTimeout: (task, timeout) => {\n const timerId = originals.bound.setTimeout(task, timeout);\n return () => originals.bound.clearTimeout(timerId);\n },\n setInterval: (task, delay) => {\n const intervalId = originals.bound.setInterval(task, delay);\n return () => originals.bound.clearInterval(intervalId);\n }\n };\n const clock = new ClockController(embedder);\n const api = createApi(clock, originals.bound);\n return { clock, api, originals: originals.raw };\n}\nfunction install(globalObject, config = {}) {\n var _a, _b;\n if ((_a = globalObject.Date) == null ? void 0 : _a.isFake) {\n throw new TypeError(`Can't install fake timers twice on the same global object.`);\n }\n const { clock, api, originals } = createClock(globalObject);\n const toFake = ((_b = config.toFake) == null ? void 0 : _b.length) ? config.toFake : Object.keys(originals);\n for (const method of toFake) {\n if (method === \"Date\") {\n globalObject.Date = mirrorDateProperties(api.Date, globalObject.Date);\n } else if (method === \"Intl\") {\n globalObject.Intl = api[method];\n } else if (method === \"performance\") {\n globalObject.performance = api[method];\n const kEventTimeStamp = Symbol(\"playwrightEventTimeStamp\");\n Object.defineProperty(Event.prototype, \"timeStamp\", {\n get() {\n var _a2;\n if (!this[kEventTimeStamp])\n this[kEventTimeStamp] = (_a2 = api.performance) == null ? void 0 : _a2.now();\n return this[kEventTimeStamp];\n }\n });\n } else {\n globalObject[method] = (...args) => {\n return api[method].apply(api, args);\n };\n }\n clock.disposables.push(() => {\n globalObject[method] = originals[method];\n });\n }\n return { clock, api, originals };\n}\nfunction inject(globalObject) {\n const builtin = platformOriginals(globalObject).bound;\n const { clock: controller } = install(globalObject);\n controller.resume();\n return {\n controller,\n builtin\n };\n}\nfunction asWallTime(n) {\n return n;\n}\nfunction shiftTicks(ticks, ms) {\n return ticks + ms;\n}\n";
|
|
7
|
+
const source = exports.source = "\nvar __commonJS = obj => {\n let required = false;\n let result;\n return function __require() {\n if (!required) {\n required = true;\n let fn;\n for (const name in obj) { fn = obj[name]; break; }\n const module = { exports: {} };\n fn(module.exports, module);\n result = module.exports;\n }\n return result;\n }\n};\nvar __export = (target, all) => {for (var name in all) target[name] = all[name];};\nvar __toESM = mod => ({ ...mod, 'default': mod });\nvar __toCommonJS = mod => ({ ...mod, __esModule: true });\n\n\n// packages/playwright-core/src/server/injected/clock.ts\nvar clock_exports = {};\n__export(clock_exports, {\n ClockController: () => ClockController,\n createClock: () => createClock,\n inject: () => inject,\n install: () => install\n});\nmodule.exports = __toCommonJS(clock_exports);\nvar ClockController = class {\n constructor(embedder) {\n this._duringTick = false;\n this._timers = /* @__PURE__ */ new Map();\n this._uniqueTimerId = idCounterStart;\n this.disposables = [];\n this._log = [];\n this._now = { time: asWallTime(0), isFixedTime: false, ticks: 0, origin: asWallTime(-1) };\n this._embedder = embedder;\n }\n uninstall() {\n this.disposables.forEach((dispose) => dispose());\n this.disposables.length = 0;\n }\n now() {\n this._replayLogOnce();\n return this._now.time;\n }\n install(time) {\n this._replayLogOnce();\n this._innerSetTime(asWallTime(time));\n }\n setSystemTime(time) {\n this._replayLogOnce();\n this._innerSetTime(asWallTime(time));\n }\n setFixedTime(time) {\n this._replayLogOnce();\n this._innerSetFixedTime(asWallTime(time));\n }\n performanceNow() {\n this._replayLogOnce();\n return this._now.ticks;\n }\n _innerSetTime(time) {\n this._now.time = time;\n this._now.isFixedTime = false;\n if (this._now.origin < 0)\n this._now.origin = this._now.time;\n }\n _innerSetFixedTime(time) {\n this._innerSetTime(time);\n this._now.isFixedTime = true;\n }\n _advanceNow(to) {\n if (!this._now.isFixedTime)\n this._now.time = asWallTime(this._now.time + to - this._now.ticks);\n this._now.ticks = to;\n }\n async log(type, time, param) {\n this._log.push({ type, time, param });\n }\n async runFor(ticks) {\n this._replayLogOnce();\n if (ticks < 0)\n throw new TypeError(\"Negative ticks are not supported\");\n await this._runTo(shiftTicks(this._now.ticks, ticks));\n }\n async _runTo(to) {\n to = Math.ceil(to);\n if (this._now.ticks > to)\n return;\n let firstException;\n while (true) {\n const result = await this._callFirstTimer(to);\n if (!result.timerFound)\n break;\n firstException = firstException || result.error;\n }\n this._advanceNow(to);\n if (firstException)\n throw firstException;\n }\n async pauseAt(time) {\n this._replayLogOnce();\n this._innerPause();\n const toConsume = time - this._now.time;\n await this._innerFastForwardTo(shiftTicks(this._now.ticks, toConsume));\n return toConsume;\n }\n _innerPause() {\n this._realTime = void 0;\n this._updateRealTimeTimer();\n }\n resume() {\n this._replayLogOnce();\n this._innerResume();\n }\n _innerResume() {\n const now = this._embedder.performanceNow();\n this._realTime = { startTicks: now, lastSyncTicks: now };\n this._updateRealTimeTimer();\n }\n _updateRealTimeTimer() {\n var _a;\n if (!this._realTime) {\n (_a = this._currentRealTimeTimer) == null ? void 0 : _a.dispose();\n this._currentRealTimeTimer = void 0;\n return;\n }\n const firstTimer = this._firstTimer();\n const callAt = Math.min(firstTimer ? firstTimer.callAt : this._now.ticks + maxTimeout, this._now.ticks + 100);\n if (this._currentRealTimeTimer && this._currentRealTimeTimer.callAt < callAt)\n return;\n if (this._currentRealTimeTimer) {\n this._currentRealTimeTimer.dispose();\n this._currentRealTimeTimer = void 0;\n }\n this._currentRealTimeTimer = {\n callAt,\n dispose: this._embedder.setTimeout(() => {\n const now = this._embedder.performanceNow();\n this._currentRealTimeTimer = void 0;\n const sinceLastSync = now - this._realTime.lastSyncTicks;\n this._realTime.lastSyncTicks = now;\n void this._runTo(shiftTicks(this._now.ticks, sinceLastSync)).catch((e) => console.error(e)).then(() => this._updateRealTimeTimer());\n }, callAt - this._now.ticks)\n };\n }\n async fastForward(ticks) {\n this._replayLogOnce();\n await this._innerFastForwardTo(shiftTicks(this._now.ticks, ticks | 0));\n }\n async _innerFastForwardTo(to) {\n if (to < this._now.ticks)\n throw new Error(\"Cannot fast-forward to the past\");\n for (const timer of this._timers.values()) {\n if (to > timer.callAt)\n timer.callAt = to;\n }\n await this._runTo(to);\n }\n addTimer(options) {\n this._replayLogOnce();\n if (options.type === \"AnimationFrame\" /* AnimationFrame */ && !options.func)\n throw new Error(\"Callback must be provided to requestAnimationFrame calls\");\n if (options.type === \"IdleCallback\" /* IdleCallback */ && !options.func)\n throw new Error(\"Callback must be provided to requestIdleCallback calls\");\n if ([\"Timeout\" /* Timeout */, \"Interval\" /* Interval */].includes(options.type) && !options.func && options.delay === void 0)\n throw new Error(\"Callback must be provided to timer calls\");\n let delay = options.delay ? +options.delay : 0;\n if (!Number.isFinite(delay))\n delay = 0;\n delay = delay > maxTimeout ? 1 : delay;\n delay = Math.max(0, delay);\n const timer = {\n type: options.type,\n func: options.func,\n args: options.args || [],\n delay,\n callAt: shiftTicks(this._now.ticks, delay || (this._duringTick ? 1 : 0)),\n createdAt: this._now.ticks,\n id: this._uniqueTimerId++,\n error: new Error()\n };\n this._timers.set(timer.id, timer);\n if (this._realTime)\n this._updateRealTimeTimer();\n return timer.id;\n }\n countTimers() {\n return this._timers.size;\n }\n _firstTimer(beforeTick) {\n let firstTimer = null;\n for (const timer of this._timers.values()) {\n const isInRange = beforeTick === void 0 || timer.callAt <= beforeTick;\n if (isInRange && (!firstTimer || compareTimers(firstTimer, timer) === 1))\n firstTimer = timer;\n }\n return firstTimer;\n }\n _takeFirstTimer(beforeTick) {\n const timer = this._firstTimer(beforeTick);\n if (!timer)\n return null;\n this._advanceNow(timer.callAt);\n if (timer.type === \"Interval\" /* Interval */)\n timer.callAt = shiftTicks(timer.callAt, timer.delay);\n else\n this._timers.delete(timer.id);\n return timer;\n }\n async _callFirstTimer(beforeTick) {\n const timer = this._takeFirstTimer(beforeTick);\n if (!timer)\n return { timerFound: false };\n this._duringTick = true;\n try {\n if (typeof timer.func !== \"function\") {\n let error2;\n try {\n (() => {\n globalThis.eval(timer.func);\n })();\n } catch (e) {\n error2 = e;\n }\n await new Promise((f) => this._embedder.setTimeout(f));\n return { timerFound: true, error: error2 };\n }\n let args = timer.args;\n if (timer.type === \"AnimationFrame\" /* AnimationFrame */)\n args = [this._now.ticks];\n else if (timer.type === \"IdleCallback\" /* IdleCallback */)\n args = [{ didTimeout: false, timeRemaining: () => 0 }];\n let error;\n try {\n timer.func.apply(null, args);\n } catch (e) {\n error = e;\n }\n await new Promise((f) => this._embedder.setTimeout(f));\n return { timerFound: true, error };\n } finally {\n this._duringTick = false;\n }\n }\n getTimeToNextFrame() {\n return 16 - this._now.ticks % 16;\n }\n clearTimer(timerId, type) {\n this._replayLogOnce();\n if (!timerId) {\n return;\n }\n const id = Number(timerId);\n if (Number.isNaN(id) || id < idCounterStart) {\n const handlerName = getClearHandler(type);\n new Error(`Clock: ${handlerName} was invoked to clear a native timer instead of one created by the clock library.`);\n }\n const timer = this._timers.get(id);\n if (timer) {\n if (timer.type === type || timer.type === \"Timeout\" && type === \"Interval\" || timer.type === \"Interval\" && type === \"Timeout\") {\n this._timers.delete(id);\n } else {\n const clear = getClearHandler(type);\n const schedule = getScheduleHandler(timer.type);\n throw new Error(\n `Cannot clear timer: timer created with ${schedule}() but cleared with ${clear}()`\n );\n }\n }\n }\n _replayLogOnce() {\n if (!this._log.length)\n return;\n let lastLogTime = -1;\n let isPaused = false;\n for (const { type, time, param } of this._log) {\n if (!isPaused && lastLogTime !== -1)\n this._advanceNow(shiftTicks(this._now.ticks, time - lastLogTime));\n lastLogTime = time;\n if (type === \"install\") {\n this._innerSetTime(asWallTime(param));\n } else if (type === \"fastForward\" || type === \"runFor\") {\n this._advanceNow(shiftTicks(this._now.ticks, param));\n } else if (type === \"pauseAt\") {\n isPaused = true;\n this._innerPause();\n this._innerSetTime(asWallTime(param));\n } else if (type === \"resume\") {\n this._innerResume();\n isPaused = false;\n } else if (type === \"setFixedTime\") {\n this._innerSetFixedTime(asWallTime(param));\n } else if (type === \"setSystemTime\") {\n this._innerSetTime(asWallTime(param));\n }\n }\n if (!isPaused && lastLogTime > 0)\n this._advanceNow(shiftTicks(this._now.ticks, this._embedder.dateNow() - lastLogTime));\n this._log.length = 0;\n }\n};\nfunction mirrorDateProperties(target, source) {\n for (const prop in source) {\n if (source.hasOwnProperty(prop))\n target[prop] = source[prop];\n }\n target.toString = () => source.toString();\n target.prototype = source.prototype;\n target.parse = source.parse;\n target.UTC = source.UTC;\n target.prototype.toUTCString = source.prototype.toUTCString;\n target.isFake = true;\n return target;\n}\nfunction createDate(clock, NativeDate) {\n function ClockDate(year, month, date, hour, minute, second, ms) {\n if (!(this instanceof ClockDate))\n return new NativeDate(clock.now()).toString();\n switch (arguments.length) {\n case 0:\n return new NativeDate(clock.now());\n case 1:\n return new NativeDate(year);\n case 2:\n return new NativeDate(year, month);\n case 3:\n return new NativeDate(year, month, date);\n case 4:\n return new NativeDate(year, month, date, hour);\n case 5:\n return new NativeDate(year, month, date, hour, minute);\n case 6:\n return new NativeDate(\n year,\n month,\n date,\n hour,\n minute,\n second\n );\n default:\n return new NativeDate(\n year,\n month,\n date,\n hour,\n minute,\n second,\n ms\n );\n }\n }\n ClockDate.now = () => clock.now();\n return mirrorDateProperties(ClockDate, NativeDate);\n}\nfunction createIntl(clock, NativeIntl) {\n const ClockIntl = {};\n for (const key of Object.getOwnPropertyNames(NativeIntl))\n ClockIntl[key] = NativeIntl[key];\n ClockIntl.DateTimeFormat = function(...args) {\n const realFormatter = new NativeIntl.DateTimeFormat(...args);\n const formatter = {\n formatRange: realFormatter.formatRange.bind(realFormatter),\n formatRangeToParts: realFormatter.formatRangeToParts.bind(realFormatter),\n resolvedOptions: realFormatter.resolvedOptions.bind(realFormatter),\n format: (date) => realFormatter.format(date || clock.now()),\n formatToParts: (date) => realFormatter.formatToParts(date || clock.now())\n };\n return formatter;\n };\n ClockIntl.DateTimeFormat.prototype = Object.create(\n NativeIntl.DateTimeFormat.prototype\n );\n ClockIntl.DateTimeFormat.supportedLocalesOf = NativeIntl.DateTimeFormat.supportedLocalesOf;\n return ClockIntl;\n}\nfunction compareTimers(a, b) {\n if (a.callAt < b.callAt)\n return -1;\n if (a.callAt > b.callAt)\n return 1;\n if (a.type === \"Immediate\" /* Immediate */ && b.type !== \"Immediate\" /* Immediate */)\n return -1;\n if (a.type !== \"Immediate\" /* Immediate */ && b.type === \"Immediate\" /* Immediate */)\n return 1;\n if (a.createdAt < b.createdAt)\n return -1;\n if (a.createdAt > b.createdAt)\n return 1;\n if (a.id < b.id)\n return -1;\n if (a.id > b.id)\n return 1;\n}\nvar maxTimeout = Math.pow(2, 31) - 1;\nvar idCounterStart = 1e12;\nfunction platformOriginals(globalObject) {\n const raw = {\n setTimeout: globalObject.setTimeout,\n clearTimeout: globalObject.clearTimeout,\n setInterval: globalObject.setInterval,\n clearInterval: globalObject.clearInterval,\n requestAnimationFrame: globalObject.requestAnimationFrame ? globalObject.requestAnimationFrame : void 0,\n cancelAnimationFrame: globalObject.cancelAnimationFrame ? globalObject.cancelAnimationFrame : void 0,\n requestIdleCallback: globalObject.requestIdleCallback ? globalObject.requestIdleCallback : void 0,\n cancelIdleCallback: globalObject.cancelIdleCallback ? globalObject.cancelIdleCallback : void 0,\n Date: globalObject.Date,\n performance: globalObject.performance,\n Intl: globalObject.Intl\n };\n const bound = { ...raw };\n for (const key of Object.keys(bound)) {\n if (key !== \"Date\" && typeof bound[key] === \"function\")\n bound[key] = bound[key].bind(globalObject);\n }\n return { raw, bound };\n}\nfunction getScheduleHandler(type) {\n if (type === \"IdleCallback\" || type === \"AnimationFrame\")\n return `request${type}`;\n return `set${type}`;\n}\nfunction createApi(clock, originals) {\n return {\n setTimeout: (func, timeout, ...args) => {\n const delay = timeout ? +timeout : timeout;\n return clock.addTimer({\n type: \"Timeout\" /* Timeout */,\n func,\n args,\n delay\n });\n },\n clearTimeout: (timerId) => {\n if (timerId)\n clock.clearTimer(timerId, \"Timeout\" /* Timeout */);\n },\n setInterval: (func, timeout, ...args) => {\n const delay = timeout ? +timeout : timeout;\n return clock.addTimer({\n type: \"Interval\" /* Interval */,\n func,\n args,\n delay\n });\n },\n clearInterval: (timerId) => {\n if (timerId)\n return clock.clearTimer(timerId, \"Interval\" /* Interval */);\n },\n requestAnimationFrame: (callback) => {\n return clock.addTimer({\n type: \"AnimationFrame\" /* AnimationFrame */,\n func: callback,\n delay: clock.getTimeToNextFrame()\n });\n },\n cancelAnimationFrame: (timerId) => {\n if (timerId)\n return clock.clearTimer(timerId, \"AnimationFrame\" /* AnimationFrame */);\n },\n requestIdleCallback: (callback, options) => {\n let timeToNextIdlePeriod = 0;\n if (clock.countTimers() > 0)\n timeToNextIdlePeriod = 50;\n return clock.addTimer({\n type: \"IdleCallback\" /* IdleCallback */,\n func: callback,\n delay: (options == null ? void 0 : options.timeout) ? Math.min(options == null ? void 0 : options.timeout, timeToNextIdlePeriod) : timeToNextIdlePeriod\n });\n },\n cancelIdleCallback: (timerId) => {\n if (timerId)\n return clock.clearTimer(timerId, \"IdleCallback\" /* IdleCallback */);\n },\n Intl: originals.Intl ? createIntl(clock, originals.Intl) : void 0,\n Date: createDate(clock, originals.Date),\n performance: originals.performance ? fakePerformance(clock, originals.performance) : void 0\n };\n}\nfunction getClearHandler(type) {\n if (type === \"IdleCallback\" || type === \"AnimationFrame\")\n return `cancel${type}`;\n return `clear${type}`;\n}\nfunction fakePerformance(clock, performance) {\n const result = {\n now: () => clock.performanceNow()\n };\n result.__defineGetter__(\"timeOrigin\", () => clock._now.origin || 0);\n for (const key of Object.keys(performance.__proto__)) {\n if (key === \"now\" || key === \"timeOrigin\")\n continue;\n if (key === \"getEntries\" || key === \"getEntriesByName\" || key === \"getEntriesByType\")\n result[key] = () => [];\n else\n result[key] = () => {\n };\n }\n return result;\n}\nfunction createClock(globalObject) {\n const originals = platformOriginals(globalObject);\n const embedder = {\n dateNow: () => originals.raw.Date.now(),\n performanceNow: () => Math.ceil(originals.raw.performance.now()),\n setTimeout: (task, timeout) => {\n const timerId = originals.bound.setTimeout(task, timeout);\n return () => originals.bound.clearTimeout(timerId);\n },\n setInterval: (task, delay) => {\n const intervalId = originals.bound.setInterval(task, delay);\n return () => originals.bound.clearInterval(intervalId);\n }\n };\n const clock = new ClockController(embedder);\n const api = createApi(clock, originals.bound);\n return { clock, api, originals: originals.raw };\n}\nfunction install(globalObject, config = {}) {\n var _a, _b;\n if ((_a = globalObject.Date) == null ? void 0 : _a.isFake) {\n throw new TypeError(`Can't install fake timers twice on the same global object.`);\n }\n const { clock, api, originals } = createClock(globalObject);\n const toFake = ((_b = config.toFake) == null ? void 0 : _b.length) ? config.toFake : Object.keys(originals);\n for (const method of toFake) {\n if (method === \"Date\") {\n globalObject.Date = mirrorDateProperties(api.Date, globalObject.Date);\n } else if (method === \"Intl\") {\n globalObject.Intl = api[method];\n } else if (method === \"performance\") {\n globalObject.performance = api[method];\n const kEventTimeStamp = Symbol(\"playwrightEventTimeStamp\");\n Object.defineProperty(Event.prototype, \"timeStamp\", {\n get() {\n var _a2;\n if (!this[kEventTimeStamp])\n this[kEventTimeStamp] = (_a2 = api.performance) == null ? void 0 : _a2.now();\n return this[kEventTimeStamp];\n }\n });\n } else {\n globalObject[method] = (...args) => {\n return api[method].apply(api, args);\n };\n }\n clock.disposables.push(() => {\n globalObject[method] = originals[method];\n });\n }\n return { clock, api, originals };\n}\nfunction inject(globalObject) {\n const builtin = platformOriginals(globalObject).bound;\n const { clock: controller } = install(globalObject);\n controller.resume();\n return {\n controller,\n builtin\n };\n}\nfunction asWallTime(n) {\n return n;\n}\nfunction shiftTicks(ticks, ms) {\n return ticks + ms;\n}\n";
|
|
8
|
+
//# sourceMappingURL=clockSource.js.map
|