@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
|
@@ -0,0 +1,157 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,203 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Chat = void 0;
|
|
7
|
+
exports.asString = asString;
|
|
8
|
+
var _transport = require("../transport");
|
|
9
|
+
/**
|
|
10
|
+
* Copyright (c) Microsoft Corporation.
|
|
11
|
+
*
|
|
12
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
13
|
+
* you may not use this file except in compliance with the License.
|
|
14
|
+
* You may obtain a copy of the License at
|
|
15
|
+
*
|
|
16
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
17
|
+
*
|
|
18
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
19
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
20
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
21
|
+
* See the License for the specific language governing permissions and
|
|
22
|
+
* limitations under the License.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
class Chat {
|
|
26
|
+
constructor(wsEndpoint) {
|
|
27
|
+
this._history = [];
|
|
28
|
+
this._connectionPromise = void 0;
|
|
29
|
+
this._chatSinks = new Map();
|
|
30
|
+
this._wsEndpoint = void 0;
|
|
31
|
+
this._wsEndpoint = wsEndpoint;
|
|
32
|
+
}
|
|
33
|
+
clearHistory() {
|
|
34
|
+
this._history = [];
|
|
35
|
+
}
|
|
36
|
+
async post(prompt) {
|
|
37
|
+
await this._append('user', prompt);
|
|
38
|
+
let text = await asString(await this._post());
|
|
39
|
+
if (text.startsWith('```json') && text.endsWith('```')) text = text.substring('```json'.length, text.length - '```'.length);
|
|
40
|
+
for (let i = 0; i < 3; ++i) {
|
|
41
|
+
try {
|
|
42
|
+
return JSON.parse(text);
|
|
43
|
+
} catch (e) {
|
|
44
|
+
await this._append('user', String(e));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
throw new Error('Failed to parse response: ' + text);
|
|
48
|
+
}
|
|
49
|
+
async _append(user, content) {
|
|
50
|
+
this._history.push({
|
|
51
|
+
user,
|
|
52
|
+
content
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
async _connection() {
|
|
56
|
+
if (!this._connectionPromise) {
|
|
57
|
+
this._connectionPromise = _transport.WebSocketTransport.connect(undefined, this._wsEndpoint).then(transport => {
|
|
58
|
+
return new Connection(transport, (method, params) => this._dispatchEvent(method, params), () => {});
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
return this._connectionPromise;
|
|
62
|
+
}
|
|
63
|
+
_dispatchEvent(method, params) {
|
|
64
|
+
if (method === 'chatChunk') {
|
|
65
|
+
const {
|
|
66
|
+
chatId,
|
|
67
|
+
chunk
|
|
68
|
+
} = params;
|
|
69
|
+
const chunkSink = this._chatSinks.get(chatId);
|
|
70
|
+
chunkSink(chunk);
|
|
71
|
+
if (!chunk) this._chatSinks.delete(chatId);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
async _post() {
|
|
75
|
+
const connection = await this._connection();
|
|
76
|
+
const result = await connection.send('chat', {
|
|
77
|
+
history: this._history
|
|
78
|
+
});
|
|
79
|
+
const {
|
|
80
|
+
chatId
|
|
81
|
+
} = result;
|
|
82
|
+
const {
|
|
83
|
+
iterable,
|
|
84
|
+
addChunk
|
|
85
|
+
} = iterablePump();
|
|
86
|
+
this._chatSinks.set(chatId, addChunk);
|
|
87
|
+
return iterable;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
exports.Chat = Chat;
|
|
91
|
+
async function asString(stream) {
|
|
92
|
+
let result = '';
|
|
93
|
+
for await (const chunk of stream) result += chunk;
|
|
94
|
+
return result;
|
|
95
|
+
}
|
|
96
|
+
function iterablePump() {
|
|
97
|
+
let controller;
|
|
98
|
+
const stream = new ReadableStream({
|
|
99
|
+
start: c => controller = c
|
|
100
|
+
});
|
|
101
|
+
const iterable = async function* () {
|
|
102
|
+
const reader = stream.getReader();
|
|
103
|
+
while (true) {
|
|
104
|
+
const {
|
|
105
|
+
done,
|
|
106
|
+
value
|
|
107
|
+
} = await reader.read();
|
|
108
|
+
if (done) break;
|
|
109
|
+
yield value;
|
|
110
|
+
}
|
|
111
|
+
}();
|
|
112
|
+
return {
|
|
113
|
+
iterable,
|
|
114
|
+
addChunk: chunk => {
|
|
115
|
+
if (chunk) controller.enqueue(chunk);else controller.close();
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
class Connection {
|
|
120
|
+
constructor(transport, onEvent, onClose) {
|
|
121
|
+
this._transport = void 0;
|
|
122
|
+
this._lastId = 0;
|
|
123
|
+
this._closed = false;
|
|
124
|
+
this._pending = new Map();
|
|
125
|
+
this._onEvent = void 0;
|
|
126
|
+
this._onClose = void 0;
|
|
127
|
+
this._transport = transport;
|
|
128
|
+
this._onEvent = onEvent;
|
|
129
|
+
this._onClose = onClose;
|
|
130
|
+
this._transport.onmessage = this._dispatchMessage.bind(this);
|
|
131
|
+
this._transport.onclose = this._close.bind(this);
|
|
132
|
+
}
|
|
133
|
+
send(method, params) {
|
|
134
|
+
const id = this._lastId++;
|
|
135
|
+
const message = {
|
|
136
|
+
id,
|
|
137
|
+
method,
|
|
138
|
+
params
|
|
139
|
+
};
|
|
140
|
+
this._transport.send(message);
|
|
141
|
+
return new Promise((resolve, reject) => {
|
|
142
|
+
this._pending.set(id, {
|
|
143
|
+
resolve,
|
|
144
|
+
reject
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
_dispatchMessage(message) {
|
|
149
|
+
if (message.id === undefined) {
|
|
150
|
+
this._onEvent(message.method, message.params);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const callback = this._pending.get(message.id);
|
|
154
|
+
this._pending.delete(message.id);
|
|
155
|
+
if (!callback) return;
|
|
156
|
+
if (message.error) {
|
|
157
|
+
callback.reject(new Error(message.error.message));
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
callback.resolve(message.result);
|
|
161
|
+
}
|
|
162
|
+
_close() {
|
|
163
|
+
this._closed = true;
|
|
164
|
+
this._transport.onmessage = undefined;
|
|
165
|
+
this._transport.onclose = undefined;
|
|
166
|
+
for (const {
|
|
167
|
+
reject
|
|
168
|
+
} of this._pending.values()) reject(new Error('Connection closed'));
|
|
169
|
+
this._onClose();
|
|
170
|
+
}
|
|
171
|
+
isClosed() {
|
|
172
|
+
return this._closed;
|
|
173
|
+
}
|
|
174
|
+
close() {
|
|
175
|
+
if (!this._closed) this._transport.close();
|
|
176
|
+
}
|
|
177
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.collect = collect;
|
|
7
|
+
exports.restore = restore;
|
|
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 collect(serializers, isFirefox, recordIndexedDB) {
|
|
25
|
+
async function collectDB(dbInfo) {
|
|
26
|
+
if (!dbInfo.name) throw new Error('Database name is empty');
|
|
27
|
+
if (!dbInfo.version) throw new Error('Database version is unset');
|
|
28
|
+
function idbRequestToPromise(request) {
|
|
29
|
+
return new Promise((resolve, reject) => {
|
|
30
|
+
request.addEventListener('success', () => resolve(request.result));
|
|
31
|
+
request.addEventListener('error', () => reject(request.error));
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
function isPlainObject(v) {
|
|
35
|
+
const ctor = v === null || v === void 0 ? void 0 : v.constructor;
|
|
36
|
+
if (isFirefox) {
|
|
37
|
+
const constructorImpl = ctor === null || ctor === void 0 ? void 0 : ctor.toString();
|
|
38
|
+
if (constructorImpl.startsWith('function Object() {') && constructorImpl.includes('[native code]')) return true;
|
|
39
|
+
}
|
|
40
|
+
return ctor === Object;
|
|
41
|
+
}
|
|
42
|
+
function trySerialize(value) {
|
|
43
|
+
let trivial = true;
|
|
44
|
+
const encoded = serializers.serializeAsCallArgument(value, v => {
|
|
45
|
+
const isTrivial = isPlainObject(v) || Array.isArray(v) || typeof v === 'string' || typeof v === 'number' || typeof v === 'boolean' || Object.is(v, null);
|
|
46
|
+
if (!isTrivial) trivial = false;
|
|
47
|
+
return {
|
|
48
|
+
fallThrough: v
|
|
49
|
+
};
|
|
50
|
+
});
|
|
51
|
+
if (trivial) return {
|
|
52
|
+
trivial: value
|
|
53
|
+
};
|
|
54
|
+
return {
|
|
55
|
+
encoded
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
const db = await idbRequestToPromise(indexedDB.open(dbInfo.name));
|
|
59
|
+
const transaction = db.transaction(db.objectStoreNames, 'readonly');
|
|
60
|
+
const stores = await Promise.all([...db.objectStoreNames].map(async storeName => {
|
|
61
|
+
const objectStore = transaction.objectStore(storeName);
|
|
62
|
+
const keys = await idbRequestToPromise(objectStore.getAllKeys());
|
|
63
|
+
const records = await Promise.all(keys.map(async key => {
|
|
64
|
+
const record = {};
|
|
65
|
+
if (objectStore.keyPath === null) {
|
|
66
|
+
const {
|
|
67
|
+
encoded,
|
|
68
|
+
trivial
|
|
69
|
+
} = trySerialize(key);
|
|
70
|
+
if (trivial) record.key = trivial;else record.keyEncoded = encoded;
|
|
71
|
+
}
|
|
72
|
+
const value = await idbRequestToPromise(objectStore.get(key));
|
|
73
|
+
const {
|
|
74
|
+
encoded,
|
|
75
|
+
trivial
|
|
76
|
+
} = trySerialize(value);
|
|
77
|
+
if (trivial) record.value = trivial;else record.valueEncoded = encoded;
|
|
78
|
+
return record;
|
|
79
|
+
}));
|
|
80
|
+
const indexes = [...objectStore.indexNames].map(indexName => {
|
|
81
|
+
const index = objectStore.index(indexName);
|
|
82
|
+
return {
|
|
83
|
+
name: index.name,
|
|
84
|
+
keyPath: typeof index.keyPath === 'string' ? index.keyPath : undefined,
|
|
85
|
+
keyPathArray: Array.isArray(index.keyPath) ? index.keyPath : undefined,
|
|
86
|
+
multiEntry: index.multiEntry,
|
|
87
|
+
unique: index.unique
|
|
88
|
+
};
|
|
89
|
+
});
|
|
90
|
+
return {
|
|
91
|
+
name: storeName,
|
|
92
|
+
records: records,
|
|
93
|
+
indexes,
|
|
94
|
+
autoIncrement: objectStore.autoIncrement,
|
|
95
|
+
keyPath: typeof objectStore.keyPath === 'string' ? objectStore.keyPath : undefined,
|
|
96
|
+
keyPathArray: Array.isArray(objectStore.keyPath) ? objectStore.keyPath : undefined
|
|
97
|
+
};
|
|
98
|
+
}));
|
|
99
|
+
return {
|
|
100
|
+
name: dbInfo.name,
|
|
101
|
+
version: dbInfo.version,
|
|
102
|
+
stores
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
return {
|
|
106
|
+
localStorage: Object.keys(localStorage).map(name => ({
|
|
107
|
+
name,
|
|
108
|
+
value: localStorage.getItem(name)
|
|
109
|
+
})),
|
|
110
|
+
indexedDB: recordIndexedDB ? await Promise.all((await indexedDB.databases()).map(collectDB)).catch(e => {
|
|
111
|
+
throw new Error('Unable to serialize IndexedDB: ' + e.message);
|
|
112
|
+
}) : undefined
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
async function restore(originState, serializers) {
|
|
116
|
+
var _originState$indexedD;
|
|
117
|
+
for (const {
|
|
118
|
+
name,
|
|
119
|
+
value
|
|
120
|
+
} of originState.localStorage || []) localStorage.setItem(name, value);
|
|
121
|
+
await Promise.all(((_originState$indexedD = originState.indexedDB) !== null && _originState$indexedD !== void 0 ? _originState$indexedD : []).map(async dbInfo => {
|
|
122
|
+
const openRequest = indexedDB.open(dbInfo.name, dbInfo.version);
|
|
123
|
+
openRequest.addEventListener('upgradeneeded', () => {
|
|
124
|
+
const db = openRequest.result;
|
|
125
|
+
for (const store of dbInfo.stores) {
|
|
126
|
+
var _store$keyPathArray;
|
|
127
|
+
const objectStore = db.createObjectStore(store.name, {
|
|
128
|
+
autoIncrement: store.autoIncrement,
|
|
129
|
+
keyPath: (_store$keyPathArray = store.keyPathArray) !== null && _store$keyPathArray !== void 0 ? _store$keyPathArray : store.keyPath
|
|
130
|
+
});
|
|
131
|
+
for (const index of store.indexes) {
|
|
132
|
+
var _index$keyPathArray;
|
|
133
|
+
objectStore.createIndex(index.name, (_index$keyPathArray = index.keyPathArray) !== null && _index$keyPathArray !== void 0 ? _index$keyPathArray : index.keyPath, {
|
|
134
|
+
unique: index.unique,
|
|
135
|
+
multiEntry: index.multiEntry
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
function idbRequestToPromise(request) {
|
|
141
|
+
return new Promise((resolve, reject) => {
|
|
142
|
+
request.addEventListener('success', () => resolve(request.result));
|
|
143
|
+
request.addEventListener('error', () => reject(request.error));
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// after `upgradeneeded` finishes, `success` event is fired.
|
|
148
|
+
const db = await idbRequestToPromise(openRequest);
|
|
149
|
+
const transaction = db.transaction(db.objectStoreNames, 'readwrite');
|
|
150
|
+
await Promise.all(dbInfo.stores.map(async store => {
|
|
151
|
+
const objectStore = transaction.objectStore(store.name);
|
|
152
|
+
await Promise.all(store.records.map(async record => {
|
|
153
|
+
var _record$value, _record$key;
|
|
154
|
+
await idbRequestToPromise(objectStore.add((_record$value = record.value) !== null && _record$value !== void 0 ? _record$value : serializers.parseEvaluationResultValue(record.valueEncoded), (_record$key = record.key) !== null && _record$key !== void 0 ? _record$key : serializers.parseEvaluationResultValue(record.keyEncoded)));
|
|
155
|
+
}));
|
|
156
|
+
}));
|
|
157
|
+
})).catch(e => {
|
|
158
|
+
throw new Error('Unable to restore IndexedDB: ' + e.message);
|
|
159
|
+
});
|
|
160
|
+
}
|