@checkly/playwright-core 1.48.23 → 1.48.24-beta.1

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.
Files changed (71) hide show
  1. package/lib/generated/clockSource.js +1 -2
  2. package/lib/generated/consoleApiSource.js +1 -2
  3. package/lib/generated/injectedScriptSource.js +1 -2
  4. package/lib/generated/pollingRecorderSource.js +1 -2
  5. package/lib/generated/utilityScriptSource.js +1 -2
  6. package/lib/generated/webSocketMockSource.js +1 -2
  7. package/lib/vite/traceViewer/assets/codeMirrorModule-lDjkI8Ax.js +24 -0
  8. package/lib/vite/traceViewer/assets/inspectorTab-BPzhNk9r.js +64 -0
  9. package/lib/vite/traceViewer/assets/workbench-DLv_q9ji.js +9 -0
  10. package/lib/vite/traceViewer/embedded.BIubxTi3.js +2 -0
  11. package/lib/vite/traceViewer/embedded.html +3 -3
  12. package/lib/vite/traceViewer/index.DPD22sZn.js +2 -0
  13. package/lib/vite/traceViewer/index.html +3 -3
  14. package/lib/vite/traceViewer/recorder.BaRuS6Pc.js +2 -0
  15. package/lib/vite/traceViewer/recorder.html +2 -2
  16. package/lib/vite/traceViewer/uiMode.B11wexdJ.js +5 -0
  17. package/lib/vite/traceViewer/uiMode.html +3 -3
  18. package/package.json +1 -1
  19. package/lib/client/clientStackTrace.js +0 -65
  20. package/lib/client/fileUtils.js +0 -31
  21. package/lib/client/platform.js +0 -71
  22. package/lib/client/timeoutSettings.js +0 -65
  23. package/lib/client/webSocket.js +0 -106
  24. package/lib/server/callLog.js +0 -79
  25. package/lib/server/harBackend.js +0 -157
  26. package/lib/server/localUtils.js +0 -203
  27. package/lib/server/recorder/chat.js +0 -177
  28. package/lib/server/storageScript.js +0 -160
  29. package/lib/server/timeoutSettings.js +0 -74
  30. package/lib/server/utils/ascii.js +0 -31
  31. package/lib/server/utils/comparators.js +0 -159
  32. package/lib/server/utils/crypto.js +0 -171
  33. package/lib/server/utils/debug.js +0 -38
  34. package/lib/server/utils/debugLogger.js +0 -93
  35. package/lib/server/utils/env.js +0 -53
  36. package/lib/server/utils/eventsHelper.js +0 -38
  37. package/lib/server/utils/expectUtils.js +0 -33
  38. package/lib/server/utils/fileUtils.js +0 -204
  39. package/lib/server/utils/happyEyeballs.js +0 -209
  40. package/lib/server/utils/hostPlatform.js +0 -145
  41. package/lib/server/utils/httpServer.js +0 -233
  42. package/lib/server/utils/image_tools/colorUtils.js +0 -98
  43. package/lib/server/utils/image_tools/compare.js +0 -108
  44. package/lib/server/utils/image_tools/imageChannel.js +0 -70
  45. package/lib/server/utils/image_tools/stats.js +0 -102
  46. package/lib/server/utils/linuxUtils.js +0 -58
  47. package/lib/server/utils/network.js +0 -160
  48. package/lib/server/utils/nodePlatform.js +0 -140
  49. package/lib/server/utils/pipeTransport.js +0 -82
  50. package/lib/server/utils/processLauncher.js +0 -248
  51. package/lib/server/utils/profiler.js +0 -52
  52. package/lib/server/utils/socksProxy.js +0 -570
  53. package/lib/server/utils/spawnAsync.js +0 -45
  54. package/lib/server/utils/task.js +0 -58
  55. package/lib/server/utils/userAgent.js +0 -91
  56. package/lib/server/utils/wsServer.js +0 -128
  57. package/lib/server/utils/zipFile.js +0 -75
  58. package/lib/server/utils/zones.js +0 -54
  59. package/lib/utils/isomorphic/ariaSnapshot.js +0 -392
  60. package/lib/utils/isomorphic/assert.js +0 -25
  61. package/lib/utils/isomorphic/colors.js +0 -65
  62. package/lib/utils/isomorphic/headers.js +0 -52
  63. package/lib/utils/isomorphic/manualPromise.js +0 -107
  64. package/lib/utils/isomorphic/multimap.js +0 -73
  65. package/lib/utils/isomorphic/rtti.js +0 -41
  66. package/lib/utils/isomorphic/semaphore.js +0 -51
  67. package/lib/utils/isomorphic/stackTrace.js +0 -169
  68. package/lib/utils/isomorphic/time.js +0 -25
  69. package/lib/utils/isomorphic/timeoutRunner.js +0 -66
  70. package/lib/utils/isomorphic/types.js +0 -5
  71. package/lib/utils.js +0 -447
@@ -1,106 +0,0 @@
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
- }
@@ -1,79 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.compressCallLog = compressCallLog;
7
- exports.findRepeatedSubsequencesForTest = void 0;
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 compressCallLog(log) {
25
- const lines = [];
26
- for (const block of findRepeatedSubsequences(log)) {
27
- for (let i = 0; i < block.sequence.length; i++) {
28
- const line = block.sequence[i];
29
- const leadingWhitespace = line.match(/^\s*/);
30
- const whitespacePrefix = ' ' + (leadingWhitespace === null || leadingWhitespace === void 0 ? void 0 : leadingWhitespace[0]) || '';
31
- const countPrefix = `${block.count} × `;
32
- if (block.count > 1 && i === 0) lines.push(whitespacePrefix + countPrefix + line.trim());else if (block.count > 1) lines.push(whitespacePrefix + ' '.repeat(countPrefix.length - 2) + '- ' + line.trim());else lines.push(whitespacePrefix + '- ' + line.trim());
33
- }
34
- }
35
- return lines;
36
- }
37
- function findRepeatedSubsequences(s) {
38
- const n = s.length;
39
- const result = [];
40
- let i = 0;
41
- const arraysEqual = (a1, a2) => {
42
- if (a1.length !== a2.length) return false;
43
- for (let j = 0; j < a1.length; j++) {
44
- if (a1[j] !== a2[j]) return false;
45
- }
46
- return true;
47
- };
48
- while (i < n) {
49
- let maxRepeatCount = 1;
50
- let maxRepeatSubstr = [s[i]]; // Initialize with the element at index i
51
- let maxRepeatLength = 1;
52
-
53
- // Try substrings of length from 1 to the remaining length of the array
54
- for (let p = 1; p <= n - i; p++) {
55
- const substr = s.slice(i, i + p); // Extract substring as array
56
- let k = 1;
57
-
58
- // Count how many times the substring repeats consecutively
59
- while (i + p * k <= n && arraysEqual(s.slice(i + p * (k - 1), i + p * k), substr)) k += 1;
60
- k -= 1; // Adjust k since it increments one extra time in the loop
61
-
62
- // Update the maximal repeating substring if necessary
63
- if (k > 1 && k * p > maxRepeatCount * maxRepeatLength) {
64
- maxRepeatCount = k;
65
- maxRepeatSubstr = substr;
66
- maxRepeatLength = p;
67
- }
68
- }
69
-
70
- // Record the substring and its count
71
- result.push({
72
- sequence: maxRepeatSubstr,
73
- count: maxRepeatCount
74
- });
75
- i += maxRepeatLength * maxRepeatCount; // Move index forward
76
- }
77
- return result;
78
- }
79
- const findRepeatedSubsequencesForTest = exports.findRepeatedSubsequencesForTest = findRepeatedSubsequences;
@@ -1,157 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.HarBackend = void 0;
7
- var _fs = _interopRequireDefault(require("fs"));
8
- var _path = _interopRequireDefault(require("path"));
9
- var _crypto = require("./utils/crypto");
10
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
- /**
12
- * Copyright (c) Microsoft Corporation.
13
- *
14
- * Licensed under the Apache License, Version 2.0 (the 'License");
15
- * you may not use this file except in compliance with the License.
16
- * You may obtain a copy of the License at
17
- *
18
- * http://www.apache.org/licenses/LICENSE-2.0
19
- *
20
- * Unless required by applicable law or agreed to in writing, software
21
- * distributed under the License is distributed on an "AS IS" BASIS,
22
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23
- * See the License for the specific language governing permissions and
24
- * limitations under the License.
25
- */
26
-
27
- const redirectStatus = [301, 302, 303, 307, 308];
28
- class HarBackend {
29
- constructor(harFile, baseDir, zipFile) {
30
- this.id = void 0;
31
- this._harFile = void 0;
32
- this._zipFile = void 0;
33
- this._baseDir = void 0;
34
- this.id = (0, _crypto.createGuid)();
35
- this._harFile = harFile;
36
- this._baseDir = baseDir;
37
- this._zipFile = zipFile;
38
- }
39
- async lookup(url, method, headers, postData, isNavigationRequest) {
40
- let entry;
41
- try {
42
- entry = await this._harFindResponse(url, method, headers, postData);
43
- } catch (e) {
44
- return {
45
- action: 'error',
46
- message: 'HAR error: ' + e.message
47
- };
48
- }
49
- if (!entry) return {
50
- action: 'noentry'
51
- };
52
-
53
- // If navigation is being redirected, restart it with the final url to ensure the document's url changes.
54
- if (entry.request.url !== url && isNavigationRequest) return {
55
- action: 'redirect',
56
- redirectURL: entry.request.url
57
- };
58
- const response = entry.response;
59
- try {
60
- const buffer = await this._loadContent(response.content);
61
- return {
62
- action: 'fulfill',
63
- status: response.status,
64
- headers: response.headers,
65
- body: buffer
66
- };
67
- } catch (e) {
68
- return {
69
- action: 'error',
70
- message: e.message
71
- };
72
- }
73
- }
74
- async _loadContent(content) {
75
- const file = content._file;
76
- let buffer;
77
- if (file) {
78
- if (this._zipFile) buffer = await this._zipFile.read(file);else buffer = await _fs.default.promises.readFile(_path.default.resolve(this._baseDir, file));
79
- } else {
80
- buffer = Buffer.from(content.text || '', content.encoding === 'base64' ? 'base64' : 'utf-8');
81
- }
82
- return buffer;
83
- }
84
- async _harFindResponse(url, method, headers, postData) {
85
- const harLog = this._harFile.log;
86
- const visited = new Set();
87
- while (true) {
88
- const entries = [];
89
- for (const candidate of harLog.entries) {
90
- if (candidate.request.url !== url || candidate.request.method !== method) continue;
91
- if (method === 'POST' && postData && candidate.request.postData) {
92
- const buffer = await this._loadContent(candidate.request.postData);
93
- if (!buffer.equals(postData)) {
94
- const boundary = multipartBoundary(headers);
95
- if (!boundary) continue;
96
- const candidataBoundary = multipartBoundary(candidate.request.headers);
97
- if (!candidataBoundary) continue;
98
- // Try to match multipart/form-data ignroing boundary as it changes between requests.
99
- if (postData.toString().replaceAll(boundary, '') !== buffer.toString().replaceAll(candidataBoundary, '')) continue;
100
- }
101
- }
102
- entries.push(candidate);
103
- }
104
- if (!entries.length) return;
105
- let entry = entries[0];
106
-
107
- // Disambiguate using headers - then one with most matching headers wins.
108
- if (entries.length > 1) {
109
- const list = [];
110
- for (const candidate of entries) {
111
- const matchingHeaders = countMatchingHeaders(candidate.request.headers, headers);
112
- list.push({
113
- candidate,
114
- matchingHeaders
115
- });
116
- }
117
- list.sort((a, b) => b.matchingHeaders - a.matchingHeaders);
118
- entry = list[0].candidate;
119
- }
120
- if (visited.has(entry)) throw new Error(`Found redirect cycle for ${url}`);
121
- visited.add(entry);
122
-
123
- // Follow redirects.
124
- const locationHeader = entry.response.headers.find(h => h.name.toLowerCase() === 'location');
125
- if (redirectStatus.includes(entry.response.status) && locationHeader) {
126
- const locationURL = new URL(locationHeader.value, url);
127
- url = locationURL.toString();
128
- if ((entry.response.status === 301 || entry.response.status === 302) && method === 'POST' || entry.response.status === 303 && !['GET', 'HEAD'].includes(method)) {
129
- // HTTP-redirect fetch step 13 (https://fetch.spec.whatwg.org/#http-redirect-fetch)
130
- method = 'GET';
131
- }
132
- continue;
133
- }
134
- return entry;
135
- }
136
- }
137
- dispose() {
138
- var _this$_zipFile;
139
- (_this$_zipFile = this._zipFile) === null || _this$_zipFile === void 0 || _this$_zipFile.close();
140
- }
141
- }
142
- exports.HarBackend = HarBackend;
143
- function countMatchingHeaders(harHeaders, headers) {
144
- const set = new Set(headers.map(h => h.name.toLowerCase() + ':' + h.value));
145
- let matches = 0;
146
- for (const h of harHeaders) {
147
- if (set.has(h.name.toLowerCase() + ':' + h.value)) ++matches;
148
- }
149
- return matches;
150
- }
151
- function multipartBoundary(headers) {
152
- const contentType = headers.find(h => h.name.toLowerCase() === 'content-type');
153
- if (!(contentType !== null && contentType !== void 0 && contentType.value.includes('multipart/form-data'))) return undefined;
154
- const boundary = contentType.value.match(/boundary=(\S+)/);
155
- if (boundary) return boundary[1];
156
- return undefined;
157
- }
@@ -1,203 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.addStackToTracingNoReply = addStackToTracingNoReply;
7
- exports.harClose = harClose;
8
- exports.harLookup = harLookup;
9
- exports.harOpen = harOpen;
10
- exports.harUnzip = harUnzip;
11
- exports.traceDiscarded = traceDiscarded;
12
- exports.tracingStarted = tracingStarted;
13
- exports.zip = zip;
14
- var _fs = _interopRequireDefault(require("fs"));
15
- var _os = _interopRequireDefault(require("os"));
16
- var _path = _interopRequireDefault(require("path"));
17
- var _crypto = require("./utils/crypto");
18
- var _harBackend = require("./harBackend");
19
- var _manualPromise = require("../utils/isomorphic/manualPromise");
20
- var _zipFile = require("./utils/zipFile");
21
- var _zipBundle = require("../zipBundle");
22
- var _traceUtils = require("../utils/isomorphic/traceUtils");
23
- var _assert = require("../utils/isomorphic/assert");
24
- var _fileUtils = require("./utils/fileUtils");
25
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
26
- /**
27
- * Copyright (c) Microsoft Corporation.
28
- *
29
- * Licensed under the Apache License, Version 2.0 (the 'License");
30
- * you may not use this file except in compliance with the License.
31
- * You may obtain a copy of the License at
32
- *
33
- * http://www.apache.org/licenses/LICENSE-2.0
34
- *
35
- * Unless required by applicable law or agreed to in writing, software
36
- * distributed under the License is distributed on an "AS IS" BASIS,
37
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
38
- * See the License for the specific language governing permissions and
39
- * limitations under the License.
40
- */
41
-
42
- async function zip(stackSessions, params) {
43
- const promise = new _manualPromise.ManualPromise();
44
- const zipFile = new _zipBundle.yazl.ZipFile();
45
- zipFile.on('error', error => promise.reject(error));
46
- const addFile = (file, name) => {
47
- try {
48
- if (_fs.default.statSync(file).isFile()) zipFile.addFile(file, name);
49
- } catch (e) {}
50
- };
51
- for (const entry of params.entries) addFile(entry.value, entry.name);
52
-
53
- // Add stacks and the sources.
54
- const stackSession = params.stacksId ? stackSessions.get(params.stacksId) : undefined;
55
- if (stackSession !== null && stackSession !== void 0 && stackSession.callStacks.length) {
56
- await stackSession.writer;
57
- if (process.env.PW_LIVE_TRACE_STACKS) {
58
- zipFile.addFile(stackSession.file, 'trace.stacks');
59
- } else {
60
- const buffer = Buffer.from(JSON.stringify((0, _traceUtils.serializeClientSideCallMetadata)(stackSession.callStacks)));
61
- zipFile.addBuffer(buffer, 'trace.stacks');
62
- }
63
- }
64
-
65
- // Collect sources from stacks.
66
- if (params.includeSources) {
67
- const sourceFiles = new Set();
68
- for (const {
69
- stack
70
- } of (stackSession === null || stackSession === void 0 ? void 0 : stackSession.callStacks) || []) {
71
- if (!stack) continue;
72
- for (const {
73
- file
74
- } of stack) sourceFiles.add(file);
75
- }
76
- for (const sourceFile of sourceFiles) addFile(sourceFile, 'resources/src@' + (await (0, _crypto.calculateSha1)(sourceFile)) + '.txt');
77
- }
78
- if (params.mode === 'write') {
79
- // New file, just compress the entries.
80
- await _fs.default.promises.mkdir(_path.default.dirname(params.zipFile), {
81
- recursive: true
82
- });
83
- zipFile.end(undefined, () => {
84
- zipFile.outputStream.pipe(_fs.default.createWriteStream(params.zipFile)).on('close', () => promise.resolve()).on('error', error => promise.reject(error));
85
- });
86
- await promise;
87
- await deleteStackSession(stackSessions, params.stacksId);
88
- return;
89
- }
90
-
91
- // File already exists. Repack and add new entries.
92
- const tempFile = params.zipFile + '.tmp';
93
- await _fs.default.promises.rename(params.zipFile, tempFile);
94
- _zipBundle.yauzl.open(tempFile, (err, inZipFile) => {
95
- if (err) {
96
- promise.reject(err);
97
- return;
98
- }
99
- (0, _assert.assert)(inZipFile);
100
- let pendingEntries = inZipFile.entryCount;
101
- inZipFile.on('entry', entry => {
102
- inZipFile.openReadStream(entry, (err, readStream) => {
103
- if (err) {
104
- promise.reject(err);
105
- return;
106
- }
107
- zipFile.addReadStream(readStream, entry.fileName);
108
- if (--pendingEntries === 0) {
109
- zipFile.end(undefined, () => {
110
- zipFile.outputStream.pipe(_fs.default.createWriteStream(params.zipFile)).on('close', () => {
111
- _fs.default.promises.unlink(tempFile).then(() => {
112
- promise.resolve();
113
- }).catch(error => promise.reject(error));
114
- });
115
- });
116
- }
117
- });
118
- });
119
- });
120
- await promise;
121
- await deleteStackSession(stackSessions, params.stacksId);
122
- }
123
- async function deleteStackSession(stackSessions, stacksId) {
124
- const session = stacksId ? stackSessions.get(stacksId) : undefined;
125
- if (!session) return;
126
- await session.writer;
127
- if (session.tmpDir) await (0, _fileUtils.removeFolders)([session.tmpDir]);
128
- stackSessions.delete(stacksId);
129
- }
130
- async function harOpen(harBackends, params) {
131
- let harBackend;
132
- if (params.file.endsWith('.zip')) {
133
- const zipFile = new _zipFile.ZipFile(params.file);
134
- const entryNames = await zipFile.entries();
135
- const harEntryName = entryNames.find(e => e.endsWith('.har'));
136
- if (!harEntryName) return {
137
- error: 'Specified archive does not have a .har file'
138
- };
139
- const har = await zipFile.read(harEntryName);
140
- const harFile = JSON.parse(har.toString());
141
- harBackend = new _harBackend.HarBackend(harFile, null, zipFile);
142
- } else {
143
- const harFile = JSON.parse(await _fs.default.promises.readFile(params.file, 'utf-8'));
144
- harBackend = new _harBackend.HarBackend(harFile, _path.default.dirname(params.file), null);
145
- }
146
- harBackends.set(harBackend.id, harBackend);
147
- return {
148
- harId: harBackend.id
149
- };
150
- }
151
- async function harLookup(harBackends, params) {
152
- const harBackend = harBackends.get(params.harId);
153
- if (!harBackend) return {
154
- action: 'error',
155
- message: `Internal error: har was not opened`
156
- };
157
- return await harBackend.lookup(params.url, params.method, params.headers, params.postData, params.isNavigationRequest);
158
- }
159
- async function harClose(harBackends, params) {
160
- const harBackend = harBackends.get(params.harId);
161
- if (harBackend) {
162
- harBackends.delete(harBackend.id);
163
- harBackend.dispose();
164
- }
165
- }
166
- async function harUnzip(params) {
167
- const dir = _path.default.dirname(params.zipFile);
168
- const zipFile = new _zipFile.ZipFile(params.zipFile);
169
- for (const entry of await zipFile.entries()) {
170
- const buffer = await zipFile.read(entry);
171
- if (entry === 'har.har') await _fs.default.promises.writeFile(params.harFile, buffer);else await _fs.default.promises.writeFile(_path.default.join(dir, entry), buffer);
172
- }
173
- zipFile.close();
174
- await _fs.default.promises.unlink(params.zipFile);
175
- }
176
- async function tracingStarted(stackSessions, params) {
177
- let tmpDir = undefined;
178
- if (!params.tracesDir) tmpDir = await _fs.default.promises.mkdtemp(_path.default.join(_os.default.tmpdir(), 'playwright-tracing-'));
179
- const traceStacksFile = _path.default.join(params.tracesDir || tmpDir, params.traceName + '.stacks');
180
- stackSessions.set(traceStacksFile, {
181
- callStacks: [],
182
- file: traceStacksFile,
183
- writer: Promise.resolve(),
184
- tmpDir
185
- });
186
- return {
187
- stacksId: traceStacksFile
188
- };
189
- }
190
- async function traceDiscarded(stackSessions, params) {
191
- await deleteStackSession(stackSessions, params.stacksId);
192
- }
193
- async function addStackToTracingNoReply(stackSessions, params) {
194
- for (const session of stackSessions.values()) {
195
- session.callStacks.push(params.callData);
196
- if (process.env.PW_LIVE_TRACE_STACKS) {
197
- session.writer = session.writer.then(() => {
198
- const buffer = Buffer.from(JSON.stringify((0, _traceUtils.serializeClientSideCallMetadata)(session.callStacks)));
199
- return _fs.default.promises.writeFile(session.file, buffer);
200
- });
201
- }
202
- }
203
- }