@skrillex1224/playwright-toolkit 2.1.202 → 2.1.204
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/dist/index.cjs +114 -59
- package/dist/index.cjs.map +2 -2
- package/dist/index.js +114 -59
- package/dist/index.js.map +2 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -3067,6 +3067,7 @@ var Captcha = {
|
|
|
3067
3067
|
};
|
|
3068
3068
|
|
|
3069
3069
|
// src/mutation.js
|
|
3070
|
+
var import_node_crypto = require("node:crypto");
|
|
3070
3071
|
var import_uuid2 = require("uuid");
|
|
3071
3072
|
var logger10 = createInternalLogger("Mutation");
|
|
3072
3073
|
var MUTATION_MONITOR_MODE = Object.freeze({
|
|
@@ -3273,82 +3274,136 @@ var Mutation = {
|
|
|
3273
3274
|
if (text.length <= max) return text;
|
|
3274
3275
|
return `${text.slice(0, max)}...`;
|
|
3275
3276
|
};
|
|
3277
|
+
const normalizeText = (value) => String(value || "").replace(/\s+/g, " ").trim();
|
|
3278
|
+
const normalizeHtml = (value) => String(value || "").trim();
|
|
3279
|
+
const hashSnapshot = (value) => (0, import_node_crypto.createHash)("sha256").update(String(value || "")).digest("hex");
|
|
3276
3280
|
const buildState = async () => {
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
const
|
|
3281
|
-
|
|
3282
|
-
|
|
3283
|
-
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
|
|
3287
|
-
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
|
|
3281
|
+
const items = [];
|
|
3282
|
+
const describeElement = async (elementHandle) => {
|
|
3283
|
+
return await elementHandle.evaluate((node) => {
|
|
3284
|
+
const tagName = String(node?.tagName || "").toUpperCase();
|
|
3285
|
+
return {
|
|
3286
|
+
tagName,
|
|
3287
|
+
id: String(node?.id || "").trim(),
|
|
3288
|
+
name: String(node?.getAttribute?.("name") || "").trim()
|
|
3289
|
+
};
|
|
3290
|
+
});
|
|
3291
|
+
};
|
|
3292
|
+
const readElementSnapshot = async (elementHandle) => {
|
|
3293
|
+
return await elementHandle.evaluate((node) => {
|
|
3294
|
+
const text = String(node?.innerText || node?.textContent || "");
|
|
3295
|
+
const html = String(node?.innerHTML || node?.outerHTML || "");
|
|
3296
|
+
return {
|
|
3297
|
+
text,
|
|
3298
|
+
html
|
|
3299
|
+
};
|
|
3300
|
+
});
|
|
3301
|
+
};
|
|
3302
|
+
const readFrameSnapshot = async (frame) => {
|
|
3303
|
+
return await frame.evaluate(() => {
|
|
3304
|
+
const root = document.documentElement || document.body;
|
|
3305
|
+
const text = String(root?.innerText || root?.textContent || "");
|
|
3306
|
+
const html = String(root?.innerHTML || "");
|
|
3307
|
+
return {
|
|
3308
|
+
text,
|
|
3309
|
+
html,
|
|
3310
|
+
url: window.location.href,
|
|
3311
|
+
readyState: document.readyState
|
|
3312
|
+
};
|
|
3313
|
+
});
|
|
3314
|
+
};
|
|
3315
|
+
for (const selector of selectorList) {
|
|
3316
|
+
let handles = [];
|
|
3317
|
+
try {
|
|
3318
|
+
handles = await page.locator(selector).elementHandles();
|
|
3319
|
+
} catch {
|
|
3320
|
+
continue;
|
|
3321
|
+
}
|
|
3322
|
+
for (let index = 0; index < handles.length; index += 1) {
|
|
3323
|
+
const handle = handles[index];
|
|
3294
3324
|
try {
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
nodes.forEach((node, index) => {
|
|
3300
|
-
const isIframe = node?.tagName === "IFRAME";
|
|
3301
|
-
let text = "";
|
|
3302
|
-
let html = "";
|
|
3325
|
+
const descriptor = await describeElement(handle);
|
|
3326
|
+
const tagName = descriptor?.tagName || "";
|
|
3327
|
+
const isFrameElement = tagName === "IFRAME" || tagName === "FRAME";
|
|
3328
|
+
const nodeName = descriptor?.id || descriptor?.name || "no-id";
|
|
3303
3329
|
let source = "main";
|
|
3304
3330
|
let path2 = `${selector}[${index}]`;
|
|
3305
|
-
|
|
3331
|
+
let text = "";
|
|
3332
|
+
let html = "";
|
|
3333
|
+
let frameUrl = "";
|
|
3334
|
+
let readyState = "";
|
|
3335
|
+
if (isFrameElement) {
|
|
3306
3336
|
source = "iframe";
|
|
3307
|
-
path2 = `${selector}[${index}]::iframe(${
|
|
3308
|
-
|
|
3309
|
-
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
text = normalizeText(
|
|
3313
|
-
html =
|
|
3337
|
+
path2 = `${selector}[${index}]::iframe(${nodeName})`;
|
|
3338
|
+
const frame = await handle.contentFrame();
|
|
3339
|
+
if (frame) {
|
|
3340
|
+
try {
|
|
3341
|
+
const frameSnapshot = await readFrameSnapshot(frame);
|
|
3342
|
+
text = normalizeText(frameSnapshot?.text || "");
|
|
3343
|
+
html = normalizeHtml(frameSnapshot?.html || "");
|
|
3344
|
+
frameUrl = String(frameSnapshot?.url || "").trim();
|
|
3345
|
+
readyState = String(frameSnapshot?.readyState || "").trim();
|
|
3346
|
+
} catch (error) {
|
|
3347
|
+
source = "iframe-unreadable";
|
|
3348
|
+
readyState = error?.name || "unreadable";
|
|
3314
3349
|
}
|
|
3315
|
-
}
|
|
3350
|
+
} else {
|
|
3351
|
+
source = "iframe-detached";
|
|
3316
3352
|
}
|
|
3317
3353
|
} else {
|
|
3318
|
-
|
|
3319
|
-
|
|
3354
|
+
try {
|
|
3355
|
+
const elementSnapshot = await readElementSnapshot(handle);
|
|
3356
|
+
text = normalizeText(elementSnapshot?.text || "");
|
|
3357
|
+
html = normalizeHtml(elementSnapshot?.html || "");
|
|
3358
|
+
} catch (error) {
|
|
3359
|
+
source = "main-unreadable";
|
|
3360
|
+
readyState = error?.name || "unreadable";
|
|
3361
|
+
}
|
|
3320
3362
|
}
|
|
3321
|
-
const snapshot = text
|
|
3363
|
+
const snapshot = text;
|
|
3322
3364
|
items.push({
|
|
3323
3365
|
selector,
|
|
3324
3366
|
source,
|
|
3325
3367
|
path: path2,
|
|
3326
3368
|
text,
|
|
3327
3369
|
html,
|
|
3370
|
+
frameUrl,
|
|
3371
|
+
readyState,
|
|
3328
3372
|
snapshot
|
|
3329
3373
|
});
|
|
3330
|
-
}
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
|
|
3350
|
-
|
|
3351
|
-
|
|
3374
|
+
} finally {
|
|
3375
|
+
await handle.dispose().catch(() => {
|
|
3376
|
+
});
|
|
3377
|
+
}
|
|
3378
|
+
}
|
|
3379
|
+
}
|
|
3380
|
+
const serializedSnapshot = items.map((item) => JSON.stringify({
|
|
3381
|
+
path: item.path,
|
|
3382
|
+
source: item.source,
|
|
3383
|
+
frameUrl: item.frameUrl,
|
|
3384
|
+
readyState: item.readyState,
|
|
3385
|
+
snapshot: item.snapshot
|
|
3386
|
+
})).join("||");
|
|
3387
|
+
const summaryText = items.map((item) => item.text).join("\n").trim();
|
|
3388
|
+
const summaryHtml = items.map((item) => item.html).join("\n");
|
|
3389
|
+
const hasMatched = items.length > 0;
|
|
3390
|
+
const primary = items.length > 0 ? items[items.length - 1] : null;
|
|
3391
|
+
return {
|
|
3392
|
+
hasMatched,
|
|
3393
|
+
snapshotKey: hashSnapshot(serializedSnapshot),
|
|
3394
|
+
text: summaryText,
|
|
3395
|
+
html: summaryHtml,
|
|
3396
|
+
snapshotLength: serializedSnapshot.length,
|
|
3397
|
+
itemCount: items.length,
|
|
3398
|
+
primaryPath: primary?.path || "",
|
|
3399
|
+
mutationNodes: items.map((item) => ({
|
|
3400
|
+
html: item.html,
|
|
3401
|
+
text: item.text,
|
|
3402
|
+
mutationType: item.source,
|
|
3403
|
+
frameUrl: item.frameUrl,
|
|
3404
|
+
readyState: item.readyState
|
|
3405
|
+
}))
|
|
3406
|
+
};
|
|
3352
3407
|
};
|
|
3353
3408
|
const invokeMutationCallback = async (context) => {
|
|
3354
3409
|
if (!onMutation) return "__CONTINUE__";
|