@pedropaulovc/playwright-core 1.59.0-next → 1.59.0-next.3
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/bin/reinstall_chrome_beta_linux.sh +0 -0
- package/bin/reinstall_chrome_beta_mac.sh +0 -0
- package/bin/reinstall_chrome_stable_linux.sh +0 -0
- package/bin/reinstall_chrome_stable_mac.sh +0 -0
- package/bin/reinstall_msedge_beta_linux.sh +0 -0
- package/bin/reinstall_msedge_beta_mac.sh +0 -0
- package/bin/reinstall_msedge_dev_linux.sh +0 -0
- package/bin/reinstall_msedge_dev_mac.sh +0 -0
- package/bin/reinstall_msedge_stable_linux.sh +0 -0
- package/bin/reinstall_msedge_stable_mac.sh +0 -0
- package/lib/cli/program.js +5 -7
- package/lib/client/page.js +0 -2
- package/lib/utilsBundle.js +3 -0
- package/lib/utilsBundleImpl/xdg-open +0 -0
- package/package.json +2 -2
- package/types/types.d.ts +327 -0
- package/lib/server/trace/viewer/traceExporter.js +0 -679
- package/lib/vite/traceViewer/assets/codeMirrorModule-DwzBH9eL.js +0 -32
- package/lib/vite/traceViewer/assets/defaultSettingsView-CdCX8877.js +0 -266
- package/lib/vite/traceViewer/index.f4OcrOqs.js +0 -2
- package/lib/vite/traceViewer/uiMode.qcahlSup.js +0 -5
|
@@ -1,679 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var traceExporter_exports = {};
|
|
30
|
-
__export(traceExporter_exports, {
|
|
31
|
-
exportTraceToMarkdown: () => exportTraceToMarkdown
|
|
32
|
-
});
|
|
33
|
-
module.exports = __toCommonJS(traceExporter_exports);
|
|
34
|
-
var import_fs = __toESM(require("fs"));
|
|
35
|
-
var import_path = __toESM(require("path"));
|
|
36
|
-
var import_zipFile = require("../../utils/zipFile");
|
|
37
|
-
async function exportTraceToMarkdown(traceFile, options) {
|
|
38
|
-
const context = await parseTrace(traceFile);
|
|
39
|
-
const outputDir = options.outputDir;
|
|
40
|
-
const assetsDir = import_path.default.join(outputDir, "assets");
|
|
41
|
-
const screenshotsDir = import_path.default.join(assetsDir, "screenshots");
|
|
42
|
-
const snapshotsDir = import_path.default.join(assetsDir, "snapshots");
|
|
43
|
-
await import_fs.default.promises.mkdir(outputDir, { recursive: true });
|
|
44
|
-
let assetMap = /* @__PURE__ */ new Map();
|
|
45
|
-
if (options.includeAssets) {
|
|
46
|
-
await import_fs.default.promises.mkdir(screenshotsDir, { recursive: true });
|
|
47
|
-
await import_fs.default.promises.mkdir(snapshotsDir, { recursive: true });
|
|
48
|
-
assetMap = await extractAssets(traceFile, context, outputDir);
|
|
49
|
-
}
|
|
50
|
-
const files = [
|
|
51
|
-
{ name: "index.md", content: generateIndexMarkdown(context, traceFile) },
|
|
52
|
-
{ name: "metadata.md", content: generateMetadataMarkdown(context) },
|
|
53
|
-
{ name: "timeline.md", content: generateTimelineMarkdown(context.actions, assetMap) },
|
|
54
|
-
{ name: "errors.md", content: generateErrorsMarkdown(context.errors, context.actions) },
|
|
55
|
-
{ name: "console.md", content: generateConsoleMarkdown(context.events) },
|
|
56
|
-
{ name: "network.md", content: generateNetworkMarkdown(context.resources) }
|
|
57
|
-
];
|
|
58
|
-
for (const file of files)
|
|
59
|
-
await import_fs.default.promises.writeFile(import_path.default.join(outputDir, file.name), file.content);
|
|
60
|
-
}
|
|
61
|
-
async function parseTrace(traceFile) {
|
|
62
|
-
const zipFile = new import_zipFile.ZipFile(traceFile);
|
|
63
|
-
const entries = await zipFile.entries();
|
|
64
|
-
const context = {
|
|
65
|
-
browserName: "Unknown",
|
|
66
|
-
wallTime: 0,
|
|
67
|
-
startTime: Number.MAX_SAFE_INTEGER,
|
|
68
|
-
endTime: 0,
|
|
69
|
-
options: {},
|
|
70
|
-
actions: [],
|
|
71
|
-
events: [],
|
|
72
|
-
errors: [],
|
|
73
|
-
resources: [],
|
|
74
|
-
pages: [],
|
|
75
|
-
snapshots: []
|
|
76
|
-
};
|
|
77
|
-
const actionMap = /* @__PURE__ */ new Map();
|
|
78
|
-
const pageMap = /* @__PURE__ */ new Map();
|
|
79
|
-
const traceEntries = entries.filter((name) => name.endsWith(".trace"));
|
|
80
|
-
const networkEntries = entries.filter((name) => name.endsWith(".network"));
|
|
81
|
-
for (const entryName of [...traceEntries, ...networkEntries]) {
|
|
82
|
-
const content = await zipFile.read(entryName);
|
|
83
|
-
const lines = content.toString("utf-8").split("\n");
|
|
84
|
-
for (const line of lines) {
|
|
85
|
-
if (!line.trim())
|
|
86
|
-
continue;
|
|
87
|
-
try {
|
|
88
|
-
const event = JSON.parse(line);
|
|
89
|
-
processTraceEvent(event, context, actionMap, pageMap);
|
|
90
|
-
} catch {
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
context.actions = [...actionMap.values()].sort((a, b) => a.startTime - b.startTime);
|
|
95
|
-
context.pages = [...pageMap.values()];
|
|
96
|
-
for (const action of context.actions) {
|
|
97
|
-
if (action.endTime > context.endTime)
|
|
98
|
-
context.endTime = action.endTime;
|
|
99
|
-
}
|
|
100
|
-
zipFile.close();
|
|
101
|
-
return context;
|
|
102
|
-
}
|
|
103
|
-
function processTraceEvent(event, context, actionMap, pageMap) {
|
|
104
|
-
switch (event.type) {
|
|
105
|
-
case "context-options":
|
|
106
|
-
context.browserName = event.browserName || "Unknown";
|
|
107
|
-
context.channel = event.channel;
|
|
108
|
-
context.title = event.title;
|
|
109
|
-
context.platform = event.platform;
|
|
110
|
-
context.playwrightVersion = event.playwrightVersion;
|
|
111
|
-
context.wallTime = event.wallTime || 0;
|
|
112
|
-
context.startTime = event.monotonicTime || 0;
|
|
113
|
-
context.sdkLanguage = event.sdkLanguage;
|
|
114
|
-
context.options = event.options || {};
|
|
115
|
-
break;
|
|
116
|
-
case "before":
|
|
117
|
-
actionMap.set(event.callId, {
|
|
118
|
-
callId: event.callId,
|
|
119
|
-
class: event.class,
|
|
120
|
-
method: event.method,
|
|
121
|
-
params: event.params || {},
|
|
122
|
-
startTime: event.startTime || 0,
|
|
123
|
-
endTime: 0,
|
|
124
|
-
log: [],
|
|
125
|
-
stack: event.stack,
|
|
126
|
-
beforeSnapshot: event.beforeSnapshot,
|
|
127
|
-
pageId: event.pageId
|
|
128
|
-
});
|
|
129
|
-
break;
|
|
130
|
-
case "after":
|
|
131
|
-
const action = actionMap.get(event.callId);
|
|
132
|
-
if (action) {
|
|
133
|
-
action.endTime = event.endTime || action.startTime;
|
|
134
|
-
action.error = event.error;
|
|
135
|
-
action.result = event.result;
|
|
136
|
-
action.afterSnapshot = event.afterSnapshot;
|
|
137
|
-
}
|
|
138
|
-
break;
|
|
139
|
-
case "log":
|
|
140
|
-
const logAction = actionMap.get(event.callId);
|
|
141
|
-
if (logAction) {
|
|
142
|
-
logAction.log.push({
|
|
143
|
-
time: event.time || 0,
|
|
144
|
-
message: event.message || ""
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
break;
|
|
148
|
-
case "console":
|
|
149
|
-
context.events.push({
|
|
150
|
-
type: "console",
|
|
151
|
-
time: event.time || 0,
|
|
152
|
-
messageType: event.messageType,
|
|
153
|
-
text: event.text,
|
|
154
|
-
location: event.location
|
|
155
|
-
});
|
|
156
|
-
break;
|
|
157
|
-
case "error":
|
|
158
|
-
context.errors.push({
|
|
159
|
-
message: event.message || "Unknown error",
|
|
160
|
-
stack: event.stack
|
|
161
|
-
});
|
|
162
|
-
break;
|
|
163
|
-
case "resource-snapshot":
|
|
164
|
-
if (event.snapshot) {
|
|
165
|
-
context.resources.push({
|
|
166
|
-
request: {
|
|
167
|
-
method: event.snapshot.request?.method || "GET",
|
|
168
|
-
url: event.snapshot.request?.url || ""
|
|
169
|
-
},
|
|
170
|
-
response: {
|
|
171
|
-
status: event.snapshot.response?.status || 0,
|
|
172
|
-
content: event.snapshot.response?.content,
|
|
173
|
-
_failureText: event.snapshot.response?._failureText
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
break;
|
|
178
|
-
case "screencast-frame":
|
|
179
|
-
let page = pageMap.get(event.pageId);
|
|
180
|
-
if (!page) {
|
|
181
|
-
page = { pageId: event.pageId, screencastFrames: [] };
|
|
182
|
-
pageMap.set(event.pageId, page);
|
|
183
|
-
}
|
|
184
|
-
page.screencastFrames.push({
|
|
185
|
-
sha1: event.sha1,
|
|
186
|
-
timestamp: event.timestamp || 0
|
|
187
|
-
});
|
|
188
|
-
break;
|
|
189
|
-
case "frame-snapshot":
|
|
190
|
-
if (event.snapshot) {
|
|
191
|
-
context.snapshots.push({
|
|
192
|
-
snapshotName: event.snapshot.snapshotName || "",
|
|
193
|
-
callId: event.snapshot.callId || "",
|
|
194
|
-
pageId: event.snapshot.pageId || "",
|
|
195
|
-
frameId: event.snapshot.frameId || "",
|
|
196
|
-
frameUrl: event.snapshot.frameUrl || "",
|
|
197
|
-
html: event.snapshot.html,
|
|
198
|
-
timestamp: event.snapshot.timestamp || 0
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
break;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
async function extractAssets(traceFile, context, outputDir) {
|
|
205
|
-
const assetMap = /* @__PURE__ */ new Map();
|
|
206
|
-
const zipFile = new import_zipFile.ZipFile(traceFile);
|
|
207
|
-
const entries = await zipFile.entries();
|
|
208
|
-
const screenshotSha1s = /* @__PURE__ */ new Set();
|
|
209
|
-
for (const page of context.pages) {
|
|
210
|
-
for (const frame of page.screencastFrames)
|
|
211
|
-
screenshotSha1s.add(frame.sha1);
|
|
212
|
-
}
|
|
213
|
-
for (const sha1 of screenshotSha1s) {
|
|
214
|
-
const resourcePath = `resources/${sha1}`;
|
|
215
|
-
if (entries.includes(resourcePath)) {
|
|
216
|
-
try {
|
|
217
|
-
const buffer = await zipFile.read(resourcePath);
|
|
218
|
-
const ext = sha1.includes(".") ? "" : ".png";
|
|
219
|
-
const relativePath = `assets/screenshots/${sha1}${ext}`;
|
|
220
|
-
const fullPath = import_path.default.join(outputDir, relativePath);
|
|
221
|
-
await import_fs.default.promises.writeFile(fullPath, buffer);
|
|
222
|
-
assetMap.set(sha1, `./${relativePath}`);
|
|
223
|
-
} catch {
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
const resourceEntries = entries.filter((name) => name.startsWith("resources/") && !screenshotSha1s.has(name.replace("resources/", "")));
|
|
228
|
-
for (const entryName of resourceEntries) {
|
|
229
|
-
const sha1 = entryName.replace("resources/", "");
|
|
230
|
-
try {
|
|
231
|
-
const buffer = await zipFile.read(entryName);
|
|
232
|
-
const text = buffer.toString("utf-8");
|
|
233
|
-
if (text.startsWith("<!") || text.startsWith("<html") || text.includes("<head") || text.includes("<body")) {
|
|
234
|
-
const ext = sha1.endsWith(".html") ? "" : ".html";
|
|
235
|
-
const relativePath = `assets/snapshots/${sha1}${ext}`;
|
|
236
|
-
const fullPath = import_path.default.join(outputDir, relativePath);
|
|
237
|
-
await import_fs.default.promises.writeFile(fullPath, text);
|
|
238
|
-
assetMap.set(sha1, `./${relativePath}`);
|
|
239
|
-
}
|
|
240
|
-
} catch {
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
for (const snapshot of context.snapshots) {
|
|
244
|
-
if (snapshot.html && snapshot.snapshotName) {
|
|
245
|
-
try {
|
|
246
|
-
const html = renderSnapshotToHtml(snapshot);
|
|
247
|
-
const safeName = snapshot.snapshotName.replace(/[^a-zA-Z0-9@_-]/g, "_");
|
|
248
|
-
const relativePath = `assets/snapshots/${safeName}.html`;
|
|
249
|
-
const fullPath = import_path.default.join(outputDir, relativePath);
|
|
250
|
-
await import_fs.default.promises.writeFile(fullPath, html);
|
|
251
|
-
assetMap.set(snapshot.snapshotName, `./${relativePath}`);
|
|
252
|
-
} catch {
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
zipFile.close();
|
|
257
|
-
return assetMap;
|
|
258
|
-
}
|
|
259
|
-
function generateIndexMarkdown(context, traceFile) {
|
|
260
|
-
const title = context.title || "Trace Export";
|
|
261
|
-
const duration = context.endTime - context.startTime;
|
|
262
|
-
const actionCount = context.actions.length;
|
|
263
|
-
const errorCount = context.errors.length + context.actions.filter((a) => a.error).length;
|
|
264
|
-
const hasErrors = errorCount > 0;
|
|
265
|
-
const errorSummary = collectErrorSummary(context);
|
|
266
|
-
let md = `# Trace Export: ${title}
|
|
267
|
-
|
|
268
|
-
`;
|
|
269
|
-
md += `**Test:** \`${title}\`
|
|
270
|
-
`;
|
|
271
|
-
md += `**Source:** \`${traceFile}\`
|
|
272
|
-
|
|
273
|
-
`;
|
|
274
|
-
md += `**Status:** ${hasErrors ? "FAILED" : "PASSED"} | **Duration:** ${duration}ms | **Actions:** ${actionCount} | **Errors:** ${errorCount}
|
|
275
|
-
|
|
276
|
-
`;
|
|
277
|
-
if (errorSummary.length > 0) {
|
|
278
|
-
md += `## Error Summary
|
|
279
|
-
`;
|
|
280
|
-
for (const error of errorSummary)
|
|
281
|
-
md += `- ${error}
|
|
282
|
-
`;
|
|
283
|
-
md += "\n";
|
|
284
|
-
}
|
|
285
|
-
md += `## Sections
|
|
286
|
-
`;
|
|
287
|
-
md += `- [Timeline](./timeline.md) - Step-by-step action timeline
|
|
288
|
-
`;
|
|
289
|
-
md += `- [Metadata](./metadata.md) - Browser/environment info
|
|
290
|
-
`;
|
|
291
|
-
md += `- [Errors](./errors.md) - Full error details with stack traces
|
|
292
|
-
`;
|
|
293
|
-
md += `- [Console](./console.md) - Browser console output
|
|
294
|
-
`;
|
|
295
|
-
md += `- [Network](./network.md) - HTTP request log
|
|
296
|
-
`;
|
|
297
|
-
return md;
|
|
298
|
-
}
|
|
299
|
-
function collectErrorSummary(context) {
|
|
300
|
-
const errors = [];
|
|
301
|
-
for (const error of context.errors)
|
|
302
|
-
errors.push(truncateString(error.message, 100));
|
|
303
|
-
for (const action of context.actions) {
|
|
304
|
-
if (action.error)
|
|
305
|
-
errors.push(truncateString(action.error.message, 100));
|
|
306
|
-
}
|
|
307
|
-
return errors.slice(0, 10);
|
|
308
|
-
}
|
|
309
|
-
function generateMetadataMarkdown(context) {
|
|
310
|
-
let md = `# Trace Metadata
|
|
311
|
-
|
|
312
|
-
`;
|
|
313
|
-
md += `## Environment
|
|
314
|
-
|
|
315
|
-
`;
|
|
316
|
-
md += `| Property | Value |
|
|
317
|
-
`;
|
|
318
|
-
md += `|----------|-------|
|
|
319
|
-
`;
|
|
320
|
-
md += `| Browser | ${context.browserName || "Unknown"} |
|
|
321
|
-
`;
|
|
322
|
-
if (context.channel)
|
|
323
|
-
md += `| Channel | ${context.channel} |
|
|
324
|
-
`;
|
|
325
|
-
if (context.platform)
|
|
326
|
-
md += `| Platform | ${context.platform} |
|
|
327
|
-
`;
|
|
328
|
-
if (context.playwrightVersion)
|
|
329
|
-
md += `| Playwright Version | ${context.playwrightVersion} |
|
|
330
|
-
`;
|
|
331
|
-
if (context.sdkLanguage)
|
|
332
|
-
md += `| SDK Language | ${context.sdkLanguage} |
|
|
333
|
-
`;
|
|
334
|
-
md += `
|
|
335
|
-
## Context Options
|
|
336
|
-
|
|
337
|
-
`;
|
|
338
|
-
md += `| Property | Value |
|
|
339
|
-
`;
|
|
340
|
-
md += `|----------|-------|
|
|
341
|
-
`;
|
|
342
|
-
if (context.options.viewport)
|
|
343
|
-
md += `| Viewport | ${context.options.viewport.width}x${context.options.viewport.height} |
|
|
344
|
-
`;
|
|
345
|
-
if (context.options.deviceScaleFactor)
|
|
346
|
-
md += `| Device Scale Factor | ${context.options.deviceScaleFactor} |
|
|
347
|
-
`;
|
|
348
|
-
if (context.options.isMobile !== void 0)
|
|
349
|
-
md += `| Mobile | ${context.options.isMobile} |
|
|
350
|
-
`;
|
|
351
|
-
if (context.options.userAgent)
|
|
352
|
-
md += `| User Agent | ${truncateString(context.options.userAgent, 80)} |
|
|
353
|
-
`;
|
|
354
|
-
if (context.options.baseURL)
|
|
355
|
-
md += `| Base URL | ${context.options.baseURL} |
|
|
356
|
-
`;
|
|
357
|
-
md += `
|
|
358
|
-
## Timing
|
|
359
|
-
|
|
360
|
-
`;
|
|
361
|
-
md += `| Property | Value |
|
|
362
|
-
`;
|
|
363
|
-
md += `|----------|-------|
|
|
364
|
-
`;
|
|
365
|
-
md += `| Wall Time | ${new Date(context.wallTime).toISOString()} |
|
|
366
|
-
`;
|
|
367
|
-
md += `| Duration | ${context.endTime - context.startTime}ms |
|
|
368
|
-
`;
|
|
369
|
-
return md;
|
|
370
|
-
}
|
|
371
|
-
function generateTimelineMarkdown(actions, assetMap) {
|
|
372
|
-
if (actions.length === 0)
|
|
373
|
-
return `# Actions Timeline
|
|
374
|
-
|
|
375
|
-
No actions recorded.
|
|
376
|
-
`;
|
|
377
|
-
const startTime = actions[0]?.startTime || 0;
|
|
378
|
-
const totalDuration = actions.length > 0 ? (actions[actions.length - 1].endTime || actions[actions.length - 1].startTime) - startTime : 0;
|
|
379
|
-
let md = `# Actions Timeline
|
|
380
|
-
|
|
381
|
-
`;
|
|
382
|
-
md += `Total actions: ${actions.length} | Duration: ${totalDuration}ms
|
|
383
|
-
|
|
384
|
-
`;
|
|
385
|
-
md += `---
|
|
386
|
-
|
|
387
|
-
`;
|
|
388
|
-
for (let i = 0; i < actions.length; i++) {
|
|
389
|
-
const action = actions[i];
|
|
390
|
-
const relativeTime = action.startTime - startTime;
|
|
391
|
-
const duration = (action.endTime || action.startTime) - action.startTime;
|
|
392
|
-
const hasError = !!action.error;
|
|
393
|
-
md += `## ${i + 1}. [${relativeTime}ms] ${action.class}.${action.method}${hasError ? " - ERROR" : ""}
|
|
394
|
-
|
|
395
|
-
`;
|
|
396
|
-
if (action.params && Object.keys(action.params).length > 0) {
|
|
397
|
-
const paramsStr = formatParams(action.params);
|
|
398
|
-
md += `- **Params:** \`${paramsStr}\`
|
|
399
|
-
`;
|
|
400
|
-
}
|
|
401
|
-
if (hasError)
|
|
402
|
-
md += `- **Error:** ${action.error.message}
|
|
403
|
-
`;
|
|
404
|
-
else if (action.result !== void 0)
|
|
405
|
-
md += `- **Result:** ${formatResult(action.result)}
|
|
406
|
-
`;
|
|
407
|
-
else
|
|
408
|
-
md += `- **Result:** Success
|
|
409
|
-
`;
|
|
410
|
-
md += `- **Duration:** ${duration}ms
|
|
411
|
-
`;
|
|
412
|
-
if (action.stack && action.stack.length > 0) {
|
|
413
|
-
const frame = action.stack[0];
|
|
414
|
-
md += `- **Source:** \`${frame.file}:${frame.line}\`
|
|
415
|
-
`;
|
|
416
|
-
}
|
|
417
|
-
const beforeSnapshot = action.beforeSnapshot ? resolveSnapshotLink(action.beforeSnapshot, assetMap) : null;
|
|
418
|
-
const afterSnapshot = action.afterSnapshot ? resolveSnapshotLink(action.afterSnapshot, assetMap) : null;
|
|
419
|
-
if (beforeSnapshot || afterSnapshot) {
|
|
420
|
-
const links = [];
|
|
421
|
-
if (beforeSnapshot)
|
|
422
|
-
links.push(`[before](${beforeSnapshot})`);
|
|
423
|
-
if (afterSnapshot)
|
|
424
|
-
links.push(`[after](${afterSnapshot})`);
|
|
425
|
-
md += `- **Snapshots:** ${links.join(" | ")}
|
|
426
|
-
`;
|
|
427
|
-
}
|
|
428
|
-
if (action.log && action.log.length > 0) {
|
|
429
|
-
md += `
|
|
430
|
-
<details><summary>Action Log</summary>
|
|
431
|
-
|
|
432
|
-
`;
|
|
433
|
-
for (const entry of action.log)
|
|
434
|
-
md += `- ${entry.message}
|
|
435
|
-
`;
|
|
436
|
-
md += `
|
|
437
|
-
</details>
|
|
438
|
-
`;
|
|
439
|
-
}
|
|
440
|
-
if (hasError && action.stack && action.stack.length > 0) {
|
|
441
|
-
md += `
|
|
442
|
-
<details><summary>Stack Trace</summary>
|
|
443
|
-
|
|
444
|
-
`;
|
|
445
|
-
md += "```\n";
|
|
446
|
-
md += `Error: ${action.error.message}
|
|
447
|
-
`;
|
|
448
|
-
for (const frame of action.stack)
|
|
449
|
-
md += ` at ${frame.function || "(anonymous)"} (${frame.file}:${frame.line}:${frame.column})
|
|
450
|
-
`;
|
|
451
|
-
md += "```\n\n";
|
|
452
|
-
md += `</details>
|
|
453
|
-
`;
|
|
454
|
-
}
|
|
455
|
-
md += `
|
|
456
|
-
---
|
|
457
|
-
|
|
458
|
-
`;
|
|
459
|
-
}
|
|
460
|
-
return md;
|
|
461
|
-
}
|
|
462
|
-
function resolveSnapshotLink(snapshotName, assetMap) {
|
|
463
|
-
if (assetMap.has(snapshotName))
|
|
464
|
-
return assetMap.get(snapshotName);
|
|
465
|
-
for (const [key, assetPath] of assetMap) {
|
|
466
|
-
if (snapshotName.includes(key) || key.includes(snapshotName))
|
|
467
|
-
return assetPath;
|
|
468
|
-
}
|
|
469
|
-
return null;
|
|
470
|
-
}
|
|
471
|
-
function generateErrorsMarkdown(errors, actions) {
|
|
472
|
-
const allErrors = [];
|
|
473
|
-
for (const error of errors) {
|
|
474
|
-
allErrors.push({
|
|
475
|
-
message: error.message,
|
|
476
|
-
stack: error.stack
|
|
477
|
-
});
|
|
478
|
-
}
|
|
479
|
-
for (const action of actions) {
|
|
480
|
-
if (action.error) {
|
|
481
|
-
allErrors.push({
|
|
482
|
-
message: action.error.message,
|
|
483
|
-
stack: action.stack,
|
|
484
|
-
source: action.stack?.[0] ? `${action.stack[0].file}:${action.stack[0].line}` : void 0
|
|
485
|
-
});
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
if (allErrors.length === 0)
|
|
489
|
-
return `# Errors
|
|
490
|
-
|
|
491
|
-
No errors recorded.
|
|
492
|
-
`;
|
|
493
|
-
let md = `# Errors
|
|
494
|
-
|
|
495
|
-
`;
|
|
496
|
-
md += `Total errors: ${allErrors.length}
|
|
497
|
-
|
|
498
|
-
`;
|
|
499
|
-
for (let i = 0; i < allErrors.length; i++) {
|
|
500
|
-
const error = allErrors[i];
|
|
501
|
-
md += `## Error ${i + 1}
|
|
502
|
-
|
|
503
|
-
`;
|
|
504
|
-
md += `**Message:** ${error.message}
|
|
505
|
-
|
|
506
|
-
`;
|
|
507
|
-
if (error.source)
|
|
508
|
-
md += `**Source:** \`${error.source}\`
|
|
509
|
-
|
|
510
|
-
`;
|
|
511
|
-
if (error.stack && error.stack.length > 0) {
|
|
512
|
-
md += `**Stack Trace:**
|
|
513
|
-
|
|
514
|
-
`;
|
|
515
|
-
md += "```\n";
|
|
516
|
-
for (const frame of error.stack)
|
|
517
|
-
md += ` at ${frame.function || "(anonymous)"} (${frame.file}:${frame.line}:${frame.column})
|
|
518
|
-
`;
|
|
519
|
-
md += "```\n\n";
|
|
520
|
-
}
|
|
521
|
-
md += `---
|
|
522
|
-
|
|
523
|
-
`;
|
|
524
|
-
}
|
|
525
|
-
return md;
|
|
526
|
-
}
|
|
527
|
-
function generateConsoleMarkdown(events) {
|
|
528
|
-
const consoleEvents = events.filter((e) => e.type === "console");
|
|
529
|
-
if (consoleEvents.length === 0)
|
|
530
|
-
return `# Console Log
|
|
531
|
-
|
|
532
|
-
No console messages recorded.
|
|
533
|
-
`;
|
|
534
|
-
let md = `# Console Log
|
|
535
|
-
|
|
536
|
-
`;
|
|
537
|
-
md += `Total messages: ${consoleEvents.length}
|
|
538
|
-
|
|
539
|
-
`;
|
|
540
|
-
md += `| Time | Type | Message | Location |
|
|
541
|
-
`;
|
|
542
|
-
md += `|------|------|---------|----------|
|
|
543
|
-
`;
|
|
544
|
-
for (const event of consoleEvents) {
|
|
545
|
-
const message = truncateString(event.text || "", 100).replace(/\|/g, "\\|").replace(/\n/g, " ");
|
|
546
|
-
const location = event.location ? `${event.location.url}:${event.location.lineNumber}` : "";
|
|
547
|
-
md += `| ${event.time}ms | ${event.messageType || "log"} | ${message} | ${truncateString(location, 50)} |
|
|
548
|
-
`;
|
|
549
|
-
}
|
|
550
|
-
return md;
|
|
551
|
-
}
|
|
552
|
-
function generateNetworkMarkdown(resources) {
|
|
553
|
-
if (resources.length === 0)
|
|
554
|
-
return `# Network Log
|
|
555
|
-
|
|
556
|
-
No network requests recorded.
|
|
557
|
-
`;
|
|
558
|
-
let md = `# Network Log
|
|
559
|
-
|
|
560
|
-
`;
|
|
561
|
-
md += `Total requests: ${resources.length}
|
|
562
|
-
|
|
563
|
-
`;
|
|
564
|
-
md += `| # | Method | URL | Status | Size |
|
|
565
|
-
`;
|
|
566
|
-
md += `|---|--------|-----|--------|------|
|
|
567
|
-
`;
|
|
568
|
-
const failedRequests = [];
|
|
569
|
-
for (let i = 0; i < resources.length; i++) {
|
|
570
|
-
const resource = resources[i];
|
|
571
|
-
const url = truncateString(resource.request.url, 60);
|
|
572
|
-
const status = resource.response.status;
|
|
573
|
-
const size = formatSize(resource.response.content?.size || 0);
|
|
574
|
-
md += `| ${i + 1} | ${resource.request.method} | ${url} | ${status} | ${size} |
|
|
575
|
-
`;
|
|
576
|
-
if (status >= 400)
|
|
577
|
-
failedRequests.push(resource);
|
|
578
|
-
}
|
|
579
|
-
if (failedRequests.length > 0) {
|
|
580
|
-
md += `
|
|
581
|
-
## Failed Requests
|
|
582
|
-
|
|
583
|
-
`;
|
|
584
|
-
for (const resource of failedRequests) {
|
|
585
|
-
md += `### ${resource.request.method} ${truncateString(resource.request.url, 80)} - ${resource.response.status}
|
|
586
|
-
|
|
587
|
-
`;
|
|
588
|
-
if (resource.response._failureText)
|
|
589
|
-
md += `**Failure:** ${resource.response._failureText}
|
|
590
|
-
|
|
591
|
-
`;
|
|
592
|
-
if (resource.response.content?.text) {
|
|
593
|
-
md += `<details><summary>Response</summary>
|
|
594
|
-
|
|
595
|
-
`;
|
|
596
|
-
md += "```\n";
|
|
597
|
-
md += truncateString(resource.response.content.text, 1e3);
|
|
598
|
-
md += "\n```\n\n";
|
|
599
|
-
md += `</details>
|
|
600
|
-
|
|
601
|
-
`;
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
}
|
|
605
|
-
return md;
|
|
606
|
-
}
|
|
607
|
-
function renderSnapshotToHtml(snapshot) {
|
|
608
|
-
const parts = [];
|
|
609
|
-
parts.push("<!DOCTYPE html>");
|
|
610
|
-
parts.push(`<!-- Playwright Snapshot: ${snapshot.snapshotName} -->`);
|
|
611
|
-
parts.push(`<!-- URL: ${snapshot.frameUrl} -->`);
|
|
612
|
-
parts.push(`<!-- Timestamp: ${snapshot.timestamp} -->`);
|
|
613
|
-
renderNode(snapshot.html, parts);
|
|
614
|
-
return parts.join("");
|
|
615
|
-
}
|
|
616
|
-
function renderNode(node, parts) {
|
|
617
|
-
if (typeof node === "string") {
|
|
618
|
-
parts.push(escapeHtml(node));
|
|
619
|
-
return;
|
|
620
|
-
}
|
|
621
|
-
if (!Array.isArray(node))
|
|
622
|
-
return;
|
|
623
|
-
if (Array.isArray(node[0]))
|
|
624
|
-
return;
|
|
625
|
-
const [tagName, ...rest] = node;
|
|
626
|
-
if (typeof tagName !== "string")
|
|
627
|
-
return;
|
|
628
|
-
let attrs = {};
|
|
629
|
-
let children = [];
|
|
630
|
-
if (rest.length > 0 && typeof rest[0] === "object" && !Array.isArray(rest[0])) {
|
|
631
|
-
attrs = rest[0] || {};
|
|
632
|
-
children = rest.slice(1);
|
|
633
|
-
} else {
|
|
634
|
-
children = rest;
|
|
635
|
-
}
|
|
636
|
-
parts.push(`<${tagName.toLowerCase()}`);
|
|
637
|
-
for (const [key, value] of Object.entries(attrs)) {
|
|
638
|
-
if (key.startsWith("__playwright"))
|
|
639
|
-
continue;
|
|
640
|
-
parts.push(` ${key}="${escapeHtml(String(value))}"`);
|
|
641
|
-
}
|
|
642
|
-
parts.push(">");
|
|
643
|
-
for (const child of children)
|
|
644
|
-
renderNode(child, parts);
|
|
645
|
-
const selfClosing = ["area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "param", "source", "track", "wbr"];
|
|
646
|
-
if (!selfClosing.includes(tagName.toLowerCase()))
|
|
647
|
-
parts.push(`</${tagName.toLowerCase()}>`);
|
|
648
|
-
}
|
|
649
|
-
function escapeHtml(text) {
|
|
650
|
-
return text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
651
|
-
}
|
|
652
|
-
function truncateString(str, maxLength) {
|
|
653
|
-
if (str.length <= maxLength)
|
|
654
|
-
return str;
|
|
655
|
-
return str.substring(0, maxLength - 3) + "...";
|
|
656
|
-
}
|
|
657
|
-
function formatParams(params) {
|
|
658
|
-
const str = JSON.stringify(params);
|
|
659
|
-
return truncateString(str, 200);
|
|
660
|
-
}
|
|
661
|
-
function formatResult(result) {
|
|
662
|
-
if (result === null || result === void 0)
|
|
663
|
-
return "null";
|
|
664
|
-
if (typeof result === "string")
|
|
665
|
-
return truncateString(result, 100);
|
|
666
|
-
const str = JSON.stringify(result);
|
|
667
|
-
return truncateString(str, 100);
|
|
668
|
-
}
|
|
669
|
-
function formatSize(bytes) {
|
|
670
|
-
if (bytes < 1024)
|
|
671
|
-
return `${bytes}B`;
|
|
672
|
-
if (bytes < 1024 * 1024)
|
|
673
|
-
return `${(bytes / 1024).toFixed(1)}KB`;
|
|
674
|
-
return `${(bytes / (1024 * 1024)).toFixed(1)}MB`;
|
|
675
|
-
}
|
|
676
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
677
|
-
0 && (module.exports = {
|
|
678
|
-
exportTraceToMarkdown
|
|
679
|
-
});
|