lazyscout 0.3.2 → 0.3.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/dist/index.js
CHANGED
|
@@ -243,6 +243,24 @@ function redactUrl(value) {
|
|
|
243
243
|
}
|
|
244
244
|
}
|
|
245
245
|
|
|
246
|
+
// ../../packages/core/dist/safety/blocklist.js
|
|
247
|
+
var MAX_BLOCK_KEYWORDS = 100;
|
|
248
|
+
var MAX_KEYWORD_LENGTH = 80;
|
|
249
|
+
function normalizeBlockedKeywords(value) {
|
|
250
|
+
if (!Array.isArray(value))
|
|
251
|
+
return [];
|
|
252
|
+
const cleaned = value.filter((keyword) => typeof keyword === "string").map((keyword) => keyword.trim().toLowerCase().slice(0, MAX_KEYWORD_LENGTH)).filter(Boolean);
|
|
253
|
+
return [...new Set(cleaned)].slice(0, MAX_BLOCK_KEYWORDS);
|
|
254
|
+
}
|
|
255
|
+
function isBlockedLabel(keywords, ...labels) {
|
|
256
|
+
if (keywords.length === 0)
|
|
257
|
+
return false;
|
|
258
|
+
const haystack = labels.filter(Boolean).join(" ").toLowerCase();
|
|
259
|
+
if (!haystack.trim())
|
|
260
|
+
return false;
|
|
261
|
+
return keywords.some((keyword) => keyword && haystack.includes(keyword.toLowerCase()));
|
|
262
|
+
}
|
|
263
|
+
|
|
246
264
|
// ../../packages/core/dist/testcase/describeStep.js
|
|
247
265
|
function describeTarget(target) {
|
|
248
266
|
const name = target.name || target.label || target.text || target.placeholder;
|
|
@@ -489,90 +507,37 @@ function collectPageData() {
|
|
|
489
507
|
}
|
|
490
508
|
|
|
491
509
|
// ../../packages/explorer/dist/safety.js
|
|
492
|
-
|
|
493
|
-
"delete",
|
|
494
|
-
"remove",
|
|
495
|
-
"destroy",
|
|
496
|
-
"erase",
|
|
497
|
-
"drop",
|
|
498
|
-
"reset",
|
|
499
|
-
"purchase",
|
|
500
|
-
"buy",
|
|
501
|
-
"checkout",
|
|
502
|
-
"pay",
|
|
503
|
-
"payment",
|
|
504
|
-
"transfer",
|
|
505
|
-
"withdraw",
|
|
506
|
-
"refund",
|
|
507
|
-
"send",
|
|
508
|
-
"submit order",
|
|
509
|
-
"place order",
|
|
510
|
-
"confirm payment",
|
|
511
|
-
"confirm order",
|
|
512
|
-
"logout",
|
|
513
|
-
"log out",
|
|
514
|
-
"sign out",
|
|
515
|
-
"signout",
|
|
516
|
-
"deactivate",
|
|
517
|
-
"disable account",
|
|
518
|
-
"delete account",
|
|
519
|
-
"close account",
|
|
520
|
-
"unsubscribe",
|
|
521
|
-
"cancel subscription",
|
|
522
|
-
"archive",
|
|
523
|
-
"publish",
|
|
524
|
-
"approve",
|
|
525
|
-
"reject",
|
|
526
|
-
"\u0E25\u0E1A",
|
|
527
|
-
"\u0E22\u0E01\u0E40\u0E25\u0E34\u0E01",
|
|
528
|
-
"\u0E0A\u0E33\u0E23\u0E30\u0E40\u0E07\u0E34\u0E19",
|
|
529
|
-
"\u0E08\u0E48\u0E32\u0E22",
|
|
530
|
-
"\u0E42\u0E2D\u0E19",
|
|
531
|
-
"\u0E0B\u0E37\u0E49\u0E2D",
|
|
532
|
-
"\u0E2A\u0E31\u0E48\u0E07\u0E0B\u0E37\u0E49\u0E2D",
|
|
533
|
-
"\u0E22\u0E37\u0E19\u0E22\u0E31\u0E19\u0E01\u0E32\u0E23\u0E0A\u0E33\u0E23\u0E30",
|
|
534
|
-
"\u0E2D\u0E2D\u0E01\u0E08\u0E32\u0E01\u0E23\u0E30\u0E1A\u0E1A",
|
|
535
|
-
"\u0E2A\u0E48\u0E07\u0E02\u0E49\u0E2D\u0E21\u0E39\u0E25",
|
|
536
|
-
"\u0E1A\u0E31\u0E19\u0E17\u0E36\u0E01"
|
|
537
|
-
];
|
|
538
|
-
function isDestructiveLabel(...labels) {
|
|
539
|
-
const haystack = labels.filter(Boolean).join(" ").toLowerCase();
|
|
540
|
-
if (!haystack.trim())
|
|
541
|
-
return false;
|
|
542
|
-
return DESTRUCTIVE_KEYWORDS.some((keyword) => haystack.includes(keyword));
|
|
543
|
-
}
|
|
544
|
-
function canFollowLink(href, accessibleName) {
|
|
510
|
+
function canFollowLink(href, accessibleName, keywords = []) {
|
|
545
511
|
if (!href)
|
|
546
512
|
return false;
|
|
547
|
-
|
|
548
|
-
return false;
|
|
549
|
-
return true;
|
|
513
|
+
return !isBlockedLabel(keywords, accessibleName, href);
|
|
550
514
|
}
|
|
551
515
|
|
|
552
516
|
// ../../packages/explorer/dist/mapToPageModel.js
|
|
553
|
-
function toUIElement(raw) {
|
|
517
|
+
function toUIElement(raw, keywords) {
|
|
554
518
|
return {
|
|
555
519
|
...raw,
|
|
556
|
-
destructive:
|
|
520
|
+
destructive: isBlockedLabel(keywords, raw.accessibleName, raw.text, raw.name, raw.id)
|
|
557
521
|
};
|
|
558
522
|
}
|
|
559
|
-
function toFormInfo(raw) {
|
|
523
|
+
function toFormInfo(raw, keywords) {
|
|
560
524
|
return {
|
|
561
525
|
id: raw.id,
|
|
562
526
|
name: raw.name,
|
|
563
527
|
action: raw.action,
|
|
564
528
|
method: raw.method,
|
|
565
529
|
accessibleName: raw.accessibleName,
|
|
566
|
-
fields: raw.fields.map(toUIElement),
|
|
567
|
-
submitButtons: raw.submitButtons.map(toUIElement)
|
|
530
|
+
fields: raw.fields.map((field) => toUIElement(field, keywords)),
|
|
531
|
+
submitButtons: raw.submitButtons.map((button) => toUIElement(button, keywords))
|
|
568
532
|
};
|
|
569
533
|
}
|
|
570
|
-
function mapToPageModel(raw, meta) {
|
|
571
|
-
const
|
|
572
|
-
const
|
|
573
|
-
const
|
|
574
|
-
const
|
|
575
|
-
const
|
|
534
|
+
function mapToPageModel(raw, meta, blockedKeywords = []) {
|
|
535
|
+
const toElement = (element) => toUIElement(element, blockedKeywords);
|
|
536
|
+
const links = raw.links.map(toElement);
|
|
537
|
+
const buttons = raw.buttons.map(toElement);
|
|
538
|
+
const inputs = raw.inputs.map(toElement);
|
|
539
|
+
const textareas = raw.textareas.map(toElement);
|
|
540
|
+
const selects = raw.selects.map(toElement);
|
|
576
541
|
const controls = [...links, ...buttons, ...inputs, ...textareas, ...selects];
|
|
577
542
|
const state = createPageState(raw, meta.finalUrl, controls);
|
|
578
543
|
return {
|
|
@@ -587,7 +552,7 @@ function mapToPageModel(raw, meta) {
|
|
|
587
552
|
inputs,
|
|
588
553
|
textareas,
|
|
589
554
|
selects,
|
|
590
|
-
forms: raw.forms.map(toFormInfo),
|
|
555
|
+
forms: raw.forms.map((form) => toFormInfo(form, blockedKeywords)),
|
|
591
556
|
apiRequests: meta.apiRequests ?? [],
|
|
592
557
|
state
|
|
593
558
|
};
|
|
@@ -712,7 +677,8 @@ var DEFAULT_EXPLORE_OPTIONS = {
|
|
|
712
677
|
maxActionsPerState: 8,
|
|
713
678
|
maxTotalStates: 80,
|
|
714
679
|
actionTimeoutMs: 2e3,
|
|
715
|
-
stateDiscoveryTimeoutMs: 350
|
|
680
|
+
stateDiscoveryTimeoutMs: 350,
|
|
681
|
+
blockedKeywords: []
|
|
716
682
|
};
|
|
717
683
|
async function exploreWebsite(startUrl, options = {}, policy = LOCAL_QA_POLICY) {
|
|
718
684
|
const config2 = { ...DEFAULT_EXPLORE_OPTIONS, ...options };
|
|
@@ -756,7 +722,7 @@ async function exploreWebsite(startUrl, options = {}, policy = LOCAL_QA_POLICY)
|
|
|
756
722
|
if (visited.has(item.url))
|
|
757
723
|
continue;
|
|
758
724
|
visited.add(item.url);
|
|
759
|
-
const result = await visitPage(page, item, config2);
|
|
725
|
+
const result = await visitPage(page, item, config2, config2.blockedKeywords);
|
|
760
726
|
if (result.kind === "issue") {
|
|
761
727
|
issues.push(result.issue);
|
|
762
728
|
continue;
|
|
@@ -776,7 +742,7 @@ async function exploreWebsite(startUrl, options = {}, policy = LOCAL_QA_POLICY)
|
|
|
776
742
|
continue;
|
|
777
743
|
}
|
|
778
744
|
for (const link of result.page.links) {
|
|
779
|
-
if (!canFollowLink(link.href, link.accessibleName))
|
|
745
|
+
if (!canFollowLink(link.href, link.accessibleName, config2.blockedKeywords))
|
|
780
746
|
continue;
|
|
781
747
|
if (!isSameOrigin(link.href, origin) || !isCrawlableUrl(link.href)) {
|
|
782
748
|
urlsSkipped++;
|
|
@@ -791,7 +757,7 @@ async function exploreWebsite(startUrl, options = {}, policy = LOCAL_QA_POLICY)
|
|
|
791
757
|
} finally {
|
|
792
758
|
await launched.close().catch(() => void 0);
|
|
793
759
|
}
|
|
794
|
-
addNavigationEdges(pages, actionGraph);
|
|
760
|
+
addNavigationEdges(pages, actionGraph, config2.blockedKeywords);
|
|
795
761
|
return {
|
|
796
762
|
startUrl: entryUrl,
|
|
797
763
|
origin,
|
|
@@ -807,7 +773,7 @@ async function exploreWebsite(startUrl, options = {}, policy = LOCAL_QA_POLICY)
|
|
|
807
773
|
actionGraph
|
|
808
774
|
};
|
|
809
775
|
}
|
|
810
|
-
function addNavigationEdges(pages, graph) {
|
|
776
|
+
function addNavigationEdges(pages, graph, keywords) {
|
|
811
777
|
for (const page of pages) {
|
|
812
778
|
const source = page.state;
|
|
813
779
|
if (!source)
|
|
@@ -815,7 +781,7 @@ function addNavigationEdges(pages, graph) {
|
|
|
815
781
|
for (const link of page.links) {
|
|
816
782
|
if (!link.href || !link.accessibleName)
|
|
817
783
|
continue;
|
|
818
|
-
const safe = canFollowLink(link.href, link.accessibleName);
|
|
784
|
+
const safe = canFollowLink(link.href, link.accessibleName, keywords);
|
|
819
785
|
const target = pages.find((candidate) => candidate.finalUrl === link.href || candidate.url === link.href)?.state;
|
|
820
786
|
const action = {
|
|
821
787
|
id: `${source.id}|navigate|${link.cssSelector}`,
|
|
@@ -825,7 +791,7 @@ function addNavigationEdges(pages, graph) {
|
|
|
825
791
|
selector: link.cssSelector,
|
|
826
792
|
locator: { role: link.role, name: link.accessibleName },
|
|
827
793
|
safe,
|
|
828
|
-
reason: safe ? void 0 : "
|
|
794
|
+
reason: safe ? void 0 : "Link matched the Project click filter and was not opened"
|
|
829
795
|
};
|
|
830
796
|
addEdge(graph, source.id, target?.id, action, safe && target ? "visited" : safe ? "discovered" : "blocked");
|
|
831
797
|
if (!safe)
|
|
@@ -849,7 +815,7 @@ async function discoverSafeStates(page, source, config2, origin, graph) {
|
|
|
849
815
|
for (const interaction of interactions) {
|
|
850
816
|
if (statesForPage >= config2.maxStatesPerPage || graph.states.length >= config2.maxTotalStates)
|
|
851
817
|
break;
|
|
852
|
-
const action = actionFromInteraction(initial.id, interaction);
|
|
818
|
+
const action = actionFromInteraction(initial.id, interaction, config2.blockedKeywords);
|
|
853
819
|
const actionKey = action.id;
|
|
854
820
|
if (graph.visitedActionKeys.includes(actionKey) || graph.failedActionKeys.includes(actionKey))
|
|
855
821
|
continue;
|
|
@@ -872,7 +838,7 @@ async function discoverSafeStates(page, source, config2, origin, graph) {
|
|
|
872
838
|
finalUrl: page.url(),
|
|
873
839
|
depth: source.depth,
|
|
874
840
|
statusCode: source.statusCode
|
|
875
|
-
}).state;
|
|
841
|
+
}, config2.blockedKeywords).state;
|
|
876
842
|
if (!observed)
|
|
877
843
|
continue;
|
|
878
844
|
addState(graph, observed);
|
|
@@ -889,9 +855,9 @@ async function discoverSafeStates(page, source, config2, origin, graph) {
|
|
|
889
855
|
}
|
|
890
856
|
}
|
|
891
857
|
}
|
|
892
|
-
function actionFromInteraction(stateId2, interaction) {
|
|
858
|
+
function actionFromInteraction(stateId2, interaction, keywords) {
|
|
893
859
|
const type = interaction.kind === "tab" ? "selectTab" : interaction.kind === "accordion" ? "expandAccordion" : interaction.kind === "dropdown" ? "openDropdown" : interaction.expanded ? "closeDialog" : "openModal";
|
|
894
|
-
const
|
|
860
|
+
const blocked = isBlockedLabel(keywords, interaction.name);
|
|
895
861
|
const description = `${type === "selectTab" ? "Select" : type === "expandAccordion" ? "Expand" : "Open"} \u201C${interaction.name}\u201D`;
|
|
896
862
|
return {
|
|
897
863
|
id: `${stateId2}|${type}|${interaction.cssSelector}`,
|
|
@@ -900,8 +866,8 @@ function actionFromInteraction(stateId2, interaction) {
|
|
|
900
866
|
target: interaction.name,
|
|
901
867
|
selector: interaction.cssSelector,
|
|
902
868
|
locator: { role: interaction.role, name: interaction.name },
|
|
903
|
-
safe: !
|
|
904
|
-
reason:
|
|
869
|
+
safe: !blocked,
|
|
870
|
+
reason: blocked ? "Action matched the Project click filter and was not executed" : void 0
|
|
905
871
|
};
|
|
906
872
|
}
|
|
907
873
|
function addEdge(graph, fromStateId, toStateId, action, status) {
|
|
@@ -910,7 +876,7 @@ function addEdge(graph, fromStateId, toStateId, action, status) {
|
|
|
910
876
|
return;
|
|
911
877
|
graph.edges.push({ id, fromStateId, toStateId, action, status });
|
|
912
878
|
}
|
|
913
|
-
async function visitPage(page, item, config2) {
|
|
879
|
+
async function visitPage(page, item, config2, keywords) {
|
|
914
880
|
try {
|
|
915
881
|
const apiRequests = [];
|
|
916
882
|
const requestStarted = /* @__PURE__ */ new Map();
|
|
@@ -971,7 +937,7 @@ async function visitPage(page, item, config2) {
|
|
|
971
937
|
depth: item.depth,
|
|
972
938
|
statusCode: status,
|
|
973
939
|
apiRequests
|
|
974
|
-
})
|
|
940
|
+
}, keywords)
|
|
975
941
|
};
|
|
976
942
|
} catch (error) {
|
|
977
943
|
return { kind: "issue", issue: toExploreIssue(item.url, error) };
|
|
@@ -1856,7 +1822,8 @@ function registerAnalyzeRoute(app) {
|
|
|
1856
1822
|
const result = await exploreWebsite(check.url.toString(), {
|
|
1857
1823
|
maxPages: clamp(body.maxPages, 1, config.limits.maxPages, config.limits.maxPages),
|
|
1858
1824
|
maxDepth: clamp(body.maxDepth, 0, config.limits.maxDepth, config.limits.maxDepth),
|
|
1859
|
-
waitAfterNavigationMs: clamp(body.waitAfterNavigationMs, 0, 5e3, 750)
|
|
1825
|
+
waitAfterNavigationMs: clamp(body.waitAfterNavigationMs, 0, 5e3, 750),
|
|
1826
|
+
blockedKeywords: normalizeBlockedKeywords(body.blockedKeywords)
|
|
1860
1827
|
}, config.urlPolicy);
|
|
1861
1828
|
if (result.pages.length === 0) {
|
|
1862
1829
|
const firstIssue = result.issues[0];
|
|
@@ -2334,6 +2301,7 @@ function registerAutomationRunRoute(app, workspaceRoot) {
|
|
|
2334
2301
|
const body = request.body;
|
|
2335
2302
|
const testCase = body.testCase;
|
|
2336
2303
|
const secrets = body.secrets;
|
|
2304
|
+
const blockedKeywords = normalizeBlockedKeywords(body.blockedKeywords);
|
|
2337
2305
|
const framework = body.framework ?? "playwright";
|
|
2338
2306
|
const runId = body.runId || crypto.randomUUID();
|
|
2339
2307
|
if (!testCase || !Array.isArray(testCase.steps))
|
|
@@ -2398,7 +2366,7 @@ function registerAutomationRunRoute(app, workspaceRoot) {
|
|
|
2398
2366
|
page = await context.newPage();
|
|
2399
2367
|
if (typeof body.code === "string" && body.code.trim()) {
|
|
2400
2368
|
addLog("info", "Running edited automation source");
|
|
2401
|
-
await executeEditedCode(page, body.code, testCase.id, capturedScreenshots, addLog, secrets);
|
|
2369
|
+
await executeEditedCode(page, body.code, testCase.id, capturedScreenshots, addLog, blockedKeywords, secrets);
|
|
2402
2370
|
if (active.stopped)
|
|
2403
2371
|
throw new Error("Run stopped by user");
|
|
2404
2372
|
addLog("pass", "\u2713 edited source completed");
|
|
@@ -2407,7 +2375,7 @@ function registerAutomationRunRoute(app, workspaceRoot) {
|
|
|
2407
2375
|
if (active.stopped)
|
|
2408
2376
|
throw new Error("Run stopped by user");
|
|
2409
2377
|
const stepStarted = Date.now();
|
|
2410
|
-
await executeStep(page, step, addLog, secrets);
|
|
2378
|
+
await executeStep(page, step, addLog, blockedKeywords, secrets);
|
|
2411
2379
|
if (active.stopped)
|
|
2412
2380
|
throw new Error("Run stopped by user");
|
|
2413
2381
|
addLog("pass", `\u2713 ${step.type}`, Date.now() - stepStarted);
|
|
@@ -2424,6 +2392,7 @@ function registerAutomationRunRoute(app, workspaceRoot) {
|
|
|
2424
2392
|
});
|
|
2425
2393
|
} catch (error) {
|
|
2426
2394
|
const message = redactSensitiveText(error instanceof Error ? error.message : String(error), secretValues);
|
|
2395
|
+
debugLocator("StepFailed", { testCaseId: testCase.id, url: page?.url(), error: message });
|
|
2427
2396
|
if (active.stopped) {
|
|
2428
2397
|
addLog("warn", "Run stopped by user", Date.now() - started);
|
|
2429
2398
|
await persistLog("stopped");
|
|
@@ -2449,7 +2418,7 @@ function registerAutomationRunRoute(app, workspaceRoot) {
|
|
|
2449
2418
|
function withScreenshotStatus(screenshots, status) {
|
|
2450
2419
|
return screenshots.map((screenshot) => ({ ...screenshot, status }));
|
|
2451
2420
|
}
|
|
2452
|
-
async function executeEditedCode(page, source, testCaseId, capturedScreenshots, addLog, projectSecrets) {
|
|
2421
|
+
async function executeEditedCode(page, source, testCaseId, capturedScreenshots, addLog, blockedKeywords, projectSecrets) {
|
|
2453
2422
|
const lines = source.split(/\r?\n/);
|
|
2454
2423
|
let executed = 0;
|
|
2455
2424
|
for (const rawLine of lines) {
|
|
@@ -2487,7 +2456,7 @@ async function executeEditedCode(page, source, testCaseId, capturedScreenshots,
|
|
|
2487
2456
|
const clickMatch = line.match(/^await (page\..+)\.click\(\)$/);
|
|
2488
2457
|
if (clickMatch) {
|
|
2489
2458
|
const target = parseEditedLocator(page, clickMatch[1]);
|
|
2490
|
-
await ensureSafeClick(target.locator, target.label);
|
|
2459
|
+
await ensureSafeClick(target.locator, target.label, blockedKeywords);
|
|
2491
2460
|
addLog("info", `\u2192 Clicking ${target.label}`);
|
|
2492
2461
|
await target.locator.click();
|
|
2493
2462
|
continue;
|
|
@@ -2650,14 +2619,44 @@ async function captureRequestedScreenshot(page, source, testCaseId) {
|
|
|
2650
2619
|
status: "passed"
|
|
2651
2620
|
};
|
|
2652
2621
|
}
|
|
2653
|
-
var STRING_LITERAL =
|
|
2622
|
+
var STRING_LITERAL = `(?:"(?:\\\\.|[^"\\\\])*"|'(?:\\\\.|[^'\\\\])*')`;
|
|
2654
2623
|
function parseStringLiteral(value) {
|
|
2655
|
-
const
|
|
2624
|
+
const quote = value[0];
|
|
2625
|
+
if (quote !== '"' && quote !== "'")
|
|
2626
|
+
throw new Error("Edited Playwright arguments must be quoted strings");
|
|
2627
|
+
const asJson = quote === '"' ? value : `"${value.slice(1, -1).replace(/\\'/g, "'").replace(/"/g, '\\"')}"`;
|
|
2628
|
+
let parsed;
|
|
2629
|
+
try {
|
|
2630
|
+
parsed = JSON.parse(asJson);
|
|
2631
|
+
} catch {
|
|
2632
|
+
throw new Error("Edited Playwright arguments must be quoted strings");
|
|
2633
|
+
}
|
|
2656
2634
|
if (typeof parsed !== "string")
|
|
2657
2635
|
throw new Error("Edited Playwright arguments must be strings");
|
|
2658
2636
|
return parsed;
|
|
2659
2637
|
}
|
|
2638
|
+
var INDEX_SUFFIX = /\.(first|last|nth)\((\d{0,4})\)$/;
|
|
2639
|
+
function applyIndexSuffix(expression) {
|
|
2640
|
+
const match = expression.match(INDEX_SUFFIX);
|
|
2641
|
+
if (!match)
|
|
2642
|
+
return { base: expression };
|
|
2643
|
+
const base = expression.slice(0, match.index);
|
|
2644
|
+
if (match[1] === "first")
|
|
2645
|
+
return { base, pick: (target) => target.first() };
|
|
2646
|
+
if (match[1] === "last")
|
|
2647
|
+
return { base, pick: (target) => target.last() };
|
|
2648
|
+
if (!match[2])
|
|
2649
|
+
return { base: expression };
|
|
2650
|
+
const index = Number(match[2]);
|
|
2651
|
+
return { base, pick: (target) => target.nth(index) };
|
|
2652
|
+
}
|
|
2660
2653
|
function parseEditedLocator(page, expression) {
|
|
2654
|
+
debugLocator("EditedSource", { expression });
|
|
2655
|
+
const { base, pick } = applyIndexSuffix(expression);
|
|
2656
|
+
const resolved = resolveLocatorExpression(page, base);
|
|
2657
|
+
return pick ? { locator: pick(resolved.locator), label: resolved.label } : resolved;
|
|
2658
|
+
}
|
|
2659
|
+
function resolveLocatorExpression(page, expression) {
|
|
2661
2660
|
const roleMatch = expression.match(new RegExp(`^page\\.getByRole\\((${STRING_LITERAL}),\\s*\\{\\s*name:\\s*(${STRING_LITERAL})\\s*\\}\\)$`));
|
|
2662
2661
|
if (roleMatch) {
|
|
2663
2662
|
const role = parseStringLiteral(roleMatch[1]);
|
|
@@ -2673,6 +2672,7 @@ function parseEditedLocator(page, expression) {
|
|
|
2673
2672
|
["getByLabel", (value) => page.getByLabel(value)],
|
|
2674
2673
|
["getByPlaceholder", (value) => page.getByPlaceholder(value)],
|
|
2675
2674
|
["getByText", (value) => page.getByText(value)],
|
|
2675
|
+
["getByTestId", (value) => page.getByTestId(value)],
|
|
2676
2676
|
["locator", (value) => page.locator(value)]
|
|
2677
2677
|
]) {
|
|
2678
2678
|
const match = expression.match(new RegExp(`^page\\.${method}\\((${STRING_LITERAL})\\)$`));
|
|
@@ -2681,9 +2681,10 @@ function parseEditedLocator(page, expression) {
|
|
|
2681
2681
|
return { locator: create(value), label: value };
|
|
2682
2682
|
}
|
|
2683
2683
|
}
|
|
2684
|
-
throw new Error(`Unsupported
|
|
2684
|
+
throw new Error(`Unsupported locator: ${expression.slice(0, 120)}
|
|
2685
|
+
Expected page.getByRole("button", { name: "Login" }), page.getByLabel/getByPlaceholder/getByText/getByTestId("\u2026") or page.locator("css"), optionally followed by .first(), .last() or .nth(n).`);
|
|
2685
2686
|
}
|
|
2686
|
-
async function executeStep(page, step, addLog, secrets) {
|
|
2687
|
+
async function executeStep(page, step, addLog, blockedKeywords, secrets) {
|
|
2687
2688
|
switch (step.type) {
|
|
2688
2689
|
case "navigate":
|
|
2689
2690
|
const checked = checkTargetUrl(step.url, config.urlPolicy);
|
|
@@ -2698,7 +2699,7 @@ async function executeStep(page, step, addLog, secrets) {
|
|
|
2698
2699
|
case "click": {
|
|
2699
2700
|
const name = step.target.name ?? step.target.text ?? step.target.cssSelector ?? "target";
|
|
2700
2701
|
const target = locator(page, step.target);
|
|
2701
|
-
await ensureSafeClick(target, name);
|
|
2702
|
+
await ensureSafeClick(target, name, blockedKeywords);
|
|
2702
2703
|
addLog("info", "Control found: " + name);
|
|
2703
2704
|
addLog("info", "\u2192 Clicking " + name);
|
|
2704
2705
|
await target.click();
|
|
@@ -2755,6 +2756,12 @@ function resolveSecret(value, projectSecrets) {
|
|
|
2755
2756
|
return secret ?? value;
|
|
2756
2757
|
}
|
|
2757
2758
|
function locator(page, target) {
|
|
2759
|
+
debugLocator("Resolver", {
|
|
2760
|
+
strategy: target.role && target.name ? "role" : target.label ? "label" : target.placeholder ? "placeholder" : target.text ? "text" : "css",
|
|
2761
|
+
role: target.role,
|
|
2762
|
+
name: target.name,
|
|
2763
|
+
cssSelector: target.cssSelector
|
|
2764
|
+
});
|
|
2758
2765
|
if (target.role && target.name)
|
|
2759
2766
|
return page.getByRole(target.role, { name: target.name });
|
|
2760
2767
|
if (target.label)
|
|
@@ -2765,7 +2772,15 @@ function locator(page, target) {
|
|
|
2765
2772
|
return page.getByText(target.text);
|
|
2766
2773
|
return page.locator(target.cssSelector ?? "");
|
|
2767
2774
|
}
|
|
2768
|
-
|
|
2775
|
+
function debugLocator(stage, detail) {
|
|
2776
|
+
if (!process.env.LAZYSCOUT_DEBUG_LOCATOR)
|
|
2777
|
+
return;
|
|
2778
|
+
const safe = Object.fromEntries(Object.entries(detail).filter(([, value]) => value !== void 0).map(([key, value]) => [key, typeof value === "string" ? redactSensitiveText(value) : value]));
|
|
2779
|
+
console.log(`[LazyScout:${stage}]`, safe);
|
|
2780
|
+
}
|
|
2781
|
+
async function ensureSafeClick(target, fallbackLabel, blockedKeywords) {
|
|
2782
|
+
if (blockedKeywords.length === 0)
|
|
2783
|
+
return;
|
|
2769
2784
|
const labels = await Promise.all([
|
|
2770
2785
|
target.getAttribute("aria-label").catch(() => null),
|
|
2771
2786
|
target.getAttribute("title").catch(() => null),
|
|
@@ -2773,8 +2788,8 @@ async function ensureSafeClick(target, fallbackLabel) {
|
|
|
2773
2788
|
target.getAttribute("id").catch(() => null),
|
|
2774
2789
|
target.innerText().catch(() => "")
|
|
2775
2790
|
]);
|
|
2776
|
-
if (
|
|
2777
|
-
throw new Error(`Blocked
|
|
2791
|
+
if (isBlockedLabel(blockedKeywords, fallbackLabel, ...labels.map((value) => value ?? void 0))) {
|
|
2792
|
+
throw new Error(`Blocked by the Project click filter: ${fallbackLabel}`);
|
|
2778
2793
|
}
|
|
2779
2794
|
}
|
|
2780
2795
|
|
|
@@ -3206,6 +3221,17 @@ var RecorderSessions = class {
|
|
|
3206
3221
|
await this.finish(session);
|
|
3207
3222
|
return this.state(projectId);
|
|
3208
3223
|
}
|
|
3224
|
+
/**
|
|
3225
|
+
* Forgets a session once the operator has saved or discarded it, so reopening
|
|
3226
|
+
* the panel starts a fresh recording instead of the previous one.
|
|
3227
|
+
*/
|
|
3228
|
+
async discard(projectId) {
|
|
3229
|
+
const session = this.sessions.get(projectId);
|
|
3230
|
+
this.sessions.delete(projectId);
|
|
3231
|
+
if (session)
|
|
3232
|
+
await this.finish(session);
|
|
3233
|
+
return idleRecorderState(projectId);
|
|
3234
|
+
}
|
|
3209
3235
|
async closeAll() {
|
|
3210
3236
|
await Promise.all([...this.sessions.values()].map((session) => this.finish(session)));
|
|
3211
3237
|
this.sessions.clear();
|
|
@@ -3253,6 +3279,7 @@ function registerRecorderRoutes(app, workspaceRoot, options = {}) {
|
|
|
3253
3279
|
});
|
|
3254
3280
|
app.get("/api/recorder/:projectId", async (request) => sessions.state(request.params.projectId));
|
|
3255
3281
|
app.post("/api/recorder/:projectId/stop", async (request, reply) => reply.send(await sessions.stop(request.params.projectId)));
|
|
3282
|
+
app.delete("/api/recorder/:projectId", async (request, reply) => reply.send(await sessions.discard(request.params.projectId)));
|
|
3256
3283
|
app.addHook("onClose", async () => {
|
|
3257
3284
|
await sessions.closeAll();
|
|
3258
3285
|
});
|
|
@@ -3303,7 +3330,7 @@ async function openInBrowser(url) {
|
|
|
3303
3330
|
}
|
|
3304
3331
|
|
|
3305
3332
|
// src/version.ts
|
|
3306
|
-
var VERSION = true ? "0.3.
|
|
3333
|
+
var VERSION = true ? "0.3.3" : "0.0.0-dev";
|
|
3307
3334
|
|
|
3308
3335
|
// src/commands/serve.ts
|
|
3309
3336
|
var DEFAULT_PORT = 4321;
|