lazyscout 0.3.1 → 0.3.2
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
|
@@ -30,7 +30,8 @@ function fingerprintState(input) {
|
|
|
30
30
|
expanded,
|
|
31
31
|
visible
|
|
32
32
|
})),
|
|
33
|
-
stateContent: [...input.stateContent].sort()
|
|
33
|
+
stateContent: [...input.stateContent].sort(),
|
|
34
|
+
validationMessages: [...input.validationMessages].sort()
|
|
34
35
|
});
|
|
35
36
|
let hash = 2166136261;
|
|
36
37
|
for (let index = 0; index < canonical.length; index += 1) {
|
|
@@ -422,6 +423,13 @@ function collectPageData() {
|
|
|
422
423
|
return false;
|
|
423
424
|
if (el instanceof HTMLInputElement && el.type === "hidden")
|
|
424
425
|
return false;
|
|
426
|
+
if (el instanceof HTMLElement) {
|
|
427
|
+
const style = window.getComputedStyle(el);
|
|
428
|
+
if (el.hidden || style.display === "none" || style.visibility === "hidden" || style.opacity === "0")
|
|
429
|
+
return false;
|
|
430
|
+
if (el.getClientRects().length === 0)
|
|
431
|
+
return false;
|
|
432
|
+
}
|
|
425
433
|
return true;
|
|
426
434
|
}
|
|
427
435
|
function collect(selector, kind, defaultRole) {
|
|
@@ -455,11 +463,17 @@ function collectPageData() {
|
|
|
455
463
|
textareas: collect("textarea", "textarea", "textbox"),
|
|
456
464
|
selects: collect("select", "select", "combobox"),
|
|
457
465
|
forms,
|
|
458
|
-
visibleDialogs: Array.from(document.querySelectorAll('[role="dialog"], dialog[open], [aria-modal="true"]')).filter(isCollectable).map((element) => accessibleName(element) || cleanText(element.textContent).slice(0, 120)).filter(Boolean).slice(0, 20),
|
|
459
|
-
interactions: Array.from(document.querySelectorAll('[role="tab"], [role="tablist"] [aria-controls], [aria-expanded], select')).filter(isCollectable).map((element) => {
|
|
466
|
+
visibleDialogs: Array.from(document.querySelectorAll('[role="dialog"], dialog[open], [aria-modal="true"], .modal-backdrop:not(.hidden), .modal:not(.hidden), .drawer:not(.hidden)')).filter(isCollectable).map((element) => accessibleName(element) || cleanText(element.querySelector("h1, h2, h3")?.textContent) || cleanText(element.textContent).slice(0, 120)).filter(Boolean).slice(0, 20),
|
|
467
|
+
interactions: Array.from(document.querySelectorAll('[role="tab"], [role="tablist"] [aria-controls], [aria-expanded], [aria-haspopup], [data-toggle], [data-bs-toggle], [data-modal], [data-drawer], [data-tab], details[data-accordion], select')).filter(isCollectable).map((element) => {
|
|
460
468
|
const role = attr(element, "role") || (element instanceof HTMLSelectElement ? "combobox" : "button");
|
|
461
469
|
const expanded = element.getAttribute("aria-expanded");
|
|
462
|
-
const
|
|
470
|
+
const popup = element.getAttribute("aria-haspopup");
|
|
471
|
+
const toggle = element.getAttribute("data-toggle") || element.getAttribute("data-bs-toggle");
|
|
472
|
+
const dataModal = element.hasAttribute("data-modal");
|
|
473
|
+
const dataDrawer = element.hasAttribute("data-drawer");
|
|
474
|
+
const dataTab = element.hasAttribute("data-tab");
|
|
475
|
+
const accordion = element.matches("details[data-accordion]");
|
|
476
|
+
const kind = role === "tab" || dataTab ? "tab" : dataDrawer ? "drawer" : popup === "dialog" || toggle === "modal" || dataModal ? "dialog" : popup === "menu" || popup === "listbox" || toggle === "dropdown" ? "dropdown" : accordion ? "accordion" : element instanceof HTMLSelectElement ? "dropdown" : element.matches("[aria-expanded]") ? "accordion" : "dialog";
|
|
463
477
|
return {
|
|
464
478
|
kind,
|
|
465
479
|
name: accessibleName(element),
|
|
@@ -469,7 +483,8 @@ function collectPageData() {
|
|
|
469
483
|
visible: true
|
|
470
484
|
};
|
|
471
485
|
}).filter((item) => item.name).slice(0, 40),
|
|
472
|
-
stateContent: Array.from(document.querySelectorAll('[aria-live], [data-state], [data-testid*="state" i]')).filter(isCollectable).map((element) => cleanText(element.textContent)).filter(Boolean).slice(0, 30)
|
|
486
|
+
stateContent: Array.from(document.querySelectorAll('[aria-live], [data-state], [data-testid*="state" i]')).filter(isCollectable).map((element) => cleanText(element.textContent)).filter(Boolean).slice(0, 30),
|
|
487
|
+
validationMessages: Array.from(document.querySelectorAll('[role="alert"], [aria-invalid="true"], .error, .errors, .invalid-feedback')).filter(isCollectable).map((element) => cleanText(element.textContent)).filter(Boolean).slice(0, 20)
|
|
473
488
|
};
|
|
474
489
|
}
|
|
475
490
|
|
|
@@ -559,16 +574,7 @@ function mapToPageModel(raw, meta) {
|
|
|
559
574
|
const textareas = raw.textareas.map(toUIElement);
|
|
560
575
|
const selects = raw.selects.map(toUIElement);
|
|
561
576
|
const controls = [...links, ...buttons, ...inputs, ...textareas, ...selects];
|
|
562
|
-
const
|
|
563
|
-
url: meta.finalUrl,
|
|
564
|
-
title: raw.title,
|
|
565
|
-
visibleDialogs: raw.visibleDialogs,
|
|
566
|
-
headings: raw.headings,
|
|
567
|
-
controls,
|
|
568
|
-
interactions: raw.interactions,
|
|
569
|
-
stateContent: raw.stateContent
|
|
570
|
-
};
|
|
571
|
-
const fingerprint = fingerprintState(stateInput);
|
|
577
|
+
const state = createPageState(raw, meta.finalUrl, controls);
|
|
572
578
|
return {
|
|
573
579
|
url: meta.url,
|
|
574
580
|
finalUrl: meta.finalUrl,
|
|
@@ -583,9 +589,40 @@ function mapToPageModel(raw, meta) {
|
|
|
583
589
|
selects,
|
|
584
590
|
forms: raw.forms.map(toFormInfo),
|
|
585
591
|
apiRequests: meta.apiRequests ?? [],
|
|
586
|
-
state
|
|
592
|
+
state
|
|
587
593
|
};
|
|
588
594
|
}
|
|
595
|
+
function createPageState(raw, url, controls) {
|
|
596
|
+
const stateInput = {
|
|
597
|
+
url,
|
|
598
|
+
title: raw.title,
|
|
599
|
+
name: stateName(raw, url),
|
|
600
|
+
type: stateType(raw),
|
|
601
|
+
discoveredAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
602
|
+
visibleDialogs: raw.visibleDialogs,
|
|
603
|
+
headings: raw.headings,
|
|
604
|
+
controls,
|
|
605
|
+
interactions: raw.interactions,
|
|
606
|
+
stateContent: raw.stateContent,
|
|
607
|
+
validationMessages: raw.validationMessages
|
|
608
|
+
};
|
|
609
|
+
const fingerprint = fingerprintState(stateInput);
|
|
610
|
+
return { id: stateId(url, fingerprint), ...stateInput, fingerprint };
|
|
611
|
+
}
|
|
612
|
+
function stateName(raw, url) {
|
|
613
|
+
if (raw.visibleDialogs[0])
|
|
614
|
+
return raw.visibleDialogs[0];
|
|
615
|
+
if (raw.validationMessages[0])
|
|
616
|
+
return raw.validationMessages[0];
|
|
617
|
+
return raw.title || new URL(url).pathname || "Page";
|
|
618
|
+
}
|
|
619
|
+
function stateType(raw) {
|
|
620
|
+
if (raw.visibleDialogs.length)
|
|
621
|
+
return "dialog";
|
|
622
|
+
if (raw.validationMessages.length)
|
|
623
|
+
return "validation";
|
|
624
|
+
return "page";
|
|
625
|
+
}
|
|
589
626
|
|
|
590
627
|
// ../../packages/explorer/dist/errors.js
|
|
591
628
|
function toExploreIssue(url, error) {
|
|
@@ -638,15 +675,24 @@ var CANDIDATES = [
|
|
|
638
675
|
{ channel: "chrome", label: "Google Chrome" },
|
|
639
676
|
{ channel: "msedge", label: "Microsoft Edge" }
|
|
640
677
|
];
|
|
641
|
-
async function launchBrowser() {
|
|
678
|
+
async function launchBrowser(options = {}) {
|
|
642
679
|
const failures = [];
|
|
643
680
|
for (const candidate of CANDIDATES) {
|
|
644
681
|
try {
|
|
682
|
+
if (options.userDataDir) {
|
|
683
|
+
const context2 = await chromium.launchPersistentContext(options.userDataDir, {
|
|
684
|
+
headless: options.headless ?? true,
|
|
685
|
+
viewport: { width: 1366, height: 900 },
|
|
686
|
+
...candidate.channel ? { channel: candidate.channel } : {}
|
|
687
|
+
});
|
|
688
|
+
return { context: context2, label: candidate.label, close: () => context2.close() };
|
|
689
|
+
}
|
|
645
690
|
const browser = await chromium.launch({
|
|
646
|
-
headless: true,
|
|
691
|
+
headless: options.headless ?? true,
|
|
647
692
|
...candidate.channel ? { channel: candidate.channel } : {}
|
|
648
693
|
});
|
|
649
|
-
|
|
694
|
+
const context = await browser.newContext({ viewport: { width: 1366, height: 900 } });
|
|
695
|
+
return { context, label: candidate.label, close: () => browser.close() };
|
|
650
696
|
} catch (error) {
|
|
651
697
|
failures.push(candidate.label);
|
|
652
698
|
void error;
|
|
@@ -661,7 +707,12 @@ var DEFAULT_EXPLORE_OPTIONS = {
|
|
|
661
707
|
maxDepth: 3,
|
|
662
708
|
pageTimeoutMs: 2e4,
|
|
663
709
|
totalTimeoutMs: 12e4,
|
|
664
|
-
waitAfterNavigationMs: 750
|
|
710
|
+
waitAfterNavigationMs: 750,
|
|
711
|
+
maxStatesPerPage: 8,
|
|
712
|
+
maxActionsPerState: 8,
|
|
713
|
+
maxTotalStates: 80,
|
|
714
|
+
actionTimeoutMs: 2e3,
|
|
715
|
+
stateDiscoveryTimeoutMs: 350
|
|
665
716
|
};
|
|
666
717
|
async function exploreWebsite(startUrl, options = {}, policy = LOCAL_QA_POLICY) {
|
|
667
718
|
const config2 = { ...DEFAULT_EXPLORE_OPTIONS, ...options };
|
|
@@ -675,11 +726,19 @@ async function exploreWebsite(startUrl, options = {}, policy = LOCAL_QA_POLICY)
|
|
|
675
726
|
const issues = [];
|
|
676
727
|
const visited = /* @__PURE__ */ new Set();
|
|
677
728
|
const queue = [{ url: entryUrl, depth: 0 }];
|
|
729
|
+
const actionGraph = {
|
|
730
|
+
states: [],
|
|
731
|
+
edges: [],
|
|
732
|
+
visitedStateIds: [],
|
|
733
|
+
visitedActionKeys: [],
|
|
734
|
+
failedActionKeys: [],
|
|
735
|
+
blockedActionKeys: []
|
|
736
|
+
};
|
|
678
737
|
let urlsSkipped = 0;
|
|
679
738
|
let limitReached = "none";
|
|
680
|
-
const
|
|
739
|
+
const launched = await launchBrowser();
|
|
740
|
+
const { context, label: browserLabel } = launched;
|
|
681
741
|
try {
|
|
682
|
-
const context = await browser.newContext({ viewport: { width: 1366, height: 900 } });
|
|
683
742
|
context.setDefaultTimeout(config2.pageTimeoutMs);
|
|
684
743
|
const page = await context.newPage();
|
|
685
744
|
while (queue.length > 0) {
|
|
@@ -709,6 +768,8 @@ async function exploreWebsite(startUrl, options = {}, policy = LOCAL_QA_POLICY)
|
|
|
709
768
|
}
|
|
710
769
|
visited.add(finalKey);
|
|
711
770
|
pages.push(result.page);
|
|
771
|
+
addState(actionGraph, result.page.state);
|
|
772
|
+
await discoverSafeStates(page, result.page, config2, origin, actionGraph);
|
|
712
773
|
if (item.depth >= config2.maxDepth) {
|
|
713
774
|
if (result.page.links.length > 0)
|
|
714
775
|
limitReached = limitReached === "none" ? "max-depth" : limitReached;
|
|
@@ -728,8 +789,9 @@ async function exploreWebsite(startUrl, options = {}, policy = LOCAL_QA_POLICY)
|
|
|
728
789
|
}
|
|
729
790
|
}
|
|
730
791
|
} finally {
|
|
731
|
-
await
|
|
792
|
+
await launched.close().catch(() => void 0);
|
|
732
793
|
}
|
|
794
|
+
addNavigationEdges(pages, actionGraph);
|
|
733
795
|
return {
|
|
734
796
|
startUrl: entryUrl,
|
|
735
797
|
origin,
|
|
@@ -742,63 +804,112 @@ async function exploreWebsite(startUrl, options = {}, policy = LOCAL_QA_POLICY)
|
|
|
742
804
|
durationMs: Date.now() - startedAt,
|
|
743
805
|
limitReached
|
|
744
806
|
},
|
|
745
|
-
actionGraph
|
|
807
|
+
actionGraph
|
|
746
808
|
};
|
|
747
809
|
}
|
|
748
|
-
function
|
|
749
|
-
const states = pages.flatMap((page) => page.state ? [page.state] : []);
|
|
750
|
-
const edges = [];
|
|
751
|
-
const visitedActionKeys = [];
|
|
752
|
-
const failedActionKeys = [];
|
|
753
|
-
const blockedActionKeys = [];
|
|
810
|
+
function addNavigationEdges(pages, graph) {
|
|
754
811
|
for (const page of pages) {
|
|
755
|
-
const
|
|
756
|
-
if (!
|
|
812
|
+
const source = page.state;
|
|
813
|
+
if (!source)
|
|
757
814
|
continue;
|
|
758
|
-
const fromStateId = state.id;
|
|
759
815
|
for (const link of page.links) {
|
|
760
816
|
if (!link.href || !link.accessibleName)
|
|
761
817
|
continue;
|
|
762
|
-
const
|
|
818
|
+
const safe = canFollowLink(link.href, link.accessibleName);
|
|
819
|
+
const target = pages.find((candidate) => candidate.finalUrl === link.href || candidate.url === link.href)?.state;
|
|
763
820
|
const action = {
|
|
821
|
+
id: `${source.id}|navigate|${link.cssSelector}`,
|
|
764
822
|
type: "navigate",
|
|
823
|
+
description: `Navigate to \u201C${link.accessibleName}\u201D`,
|
|
765
824
|
target: link.accessibleName,
|
|
766
825
|
selector: link.cssSelector,
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
const status = action.safe ? targetPage ? "visited" : "discovered" : "blocked";
|
|
771
|
-
edges.push({ fromStateId, toStateId: targetPage?.state?.id, action, status });
|
|
772
|
-
if (status === "visited")
|
|
773
|
-
visitedActionKeys.push(key);
|
|
774
|
-
if (status === "blocked")
|
|
775
|
-
blockedActionKeys.push(key);
|
|
776
|
-
}
|
|
777
|
-
for (const interaction of state.interactions) {
|
|
778
|
-
const destructive = isDestructiveLabel(interaction.name);
|
|
779
|
-
const type = interaction.kind === "tab" ? "selectTab" : interaction.kind === "accordion" ? "expandAccordion" : interaction.kind === "dropdown" ? "openDropdown" : interaction.expanded ? "closeDialog" : "openModal";
|
|
780
|
-
const key = `${fromStateId}|${type}|${interaction.cssSelector}`;
|
|
781
|
-
const action = {
|
|
782
|
-
type,
|
|
783
|
-
target: interaction.name,
|
|
784
|
-
selector: interaction.cssSelector,
|
|
785
|
-
safe: !destructive,
|
|
786
|
-
reason: destructive ? "Destructive action was discovered but not executed" : void 0
|
|
826
|
+
locator: { role: link.role, name: link.accessibleName },
|
|
827
|
+
safe,
|
|
828
|
+
reason: safe ? void 0 : "Unsafe link was discovered but not opened"
|
|
787
829
|
};
|
|
788
|
-
|
|
789
|
-
if (
|
|
790
|
-
blockedActionKeys.push(
|
|
830
|
+
addEdge(graph, source.id, target?.id, action, safe && target ? "visited" : safe ? "discovered" : "blocked");
|
|
831
|
+
if (!safe)
|
|
832
|
+
graph.blockedActionKeys.push(action.id);
|
|
791
833
|
}
|
|
792
834
|
}
|
|
835
|
+
}
|
|
836
|
+
function addState(graph, state) {
|
|
837
|
+
if (!state || graph.states.some((candidate) => candidate.id === state.id))
|
|
838
|
+
return;
|
|
839
|
+
graph.states.push(state);
|
|
840
|
+
graph.visitedStateIds.push(state.id);
|
|
841
|
+
}
|
|
842
|
+
async function discoverSafeStates(page, source, config2, origin, graph) {
|
|
843
|
+
const initial = source.state;
|
|
844
|
+
if (!initial || graph.states.length >= config2.maxTotalStates)
|
|
845
|
+
return;
|
|
846
|
+
const sourceUrl = source.finalUrl;
|
|
847
|
+
const interactions = initial.interactions.slice(0, config2.maxActionsPerState);
|
|
848
|
+
let statesForPage = 1;
|
|
849
|
+
for (const interaction of interactions) {
|
|
850
|
+
if (statesForPage >= config2.maxStatesPerPage || graph.states.length >= config2.maxTotalStates)
|
|
851
|
+
break;
|
|
852
|
+
const action = actionFromInteraction(initial.id, interaction);
|
|
853
|
+
const actionKey = action.id;
|
|
854
|
+
if (graph.visitedActionKeys.includes(actionKey) || graph.failedActionKeys.includes(actionKey))
|
|
855
|
+
continue;
|
|
856
|
+
if (!action.safe) {
|
|
857
|
+
addEdge(graph, initial.id, void 0, action, "blocked");
|
|
858
|
+
graph.blockedActionKeys.push(actionKey);
|
|
859
|
+
continue;
|
|
860
|
+
}
|
|
861
|
+
try {
|
|
862
|
+
await page.locator(interaction.cssSelector).click({ timeout: config2.actionTimeoutMs });
|
|
863
|
+
await page.waitForTimeout(config2.stateDiscoveryTimeoutMs);
|
|
864
|
+
if (!isSameOrigin(page.url(), origin)) {
|
|
865
|
+
addEdge(graph, initial.id, void 0, { ...action, safe: false, reason: "Action left the approved origin" }, "blocked");
|
|
866
|
+
graph.blockedActionKeys.push(actionKey);
|
|
867
|
+
continue;
|
|
868
|
+
}
|
|
869
|
+
const raw = await page.evaluate(collectPageData);
|
|
870
|
+
const observed = mapToPageModel(raw, {
|
|
871
|
+
url: page.url(),
|
|
872
|
+
finalUrl: page.url(),
|
|
873
|
+
depth: source.depth,
|
|
874
|
+
statusCode: source.statusCode
|
|
875
|
+
}).state;
|
|
876
|
+
if (!observed)
|
|
877
|
+
continue;
|
|
878
|
+
addState(graph, observed);
|
|
879
|
+
addEdge(graph, initial.id, observed.id, action, "visited");
|
|
880
|
+
graph.visitedActionKeys.push(actionKey);
|
|
881
|
+
if (observed.id !== initial.id)
|
|
882
|
+
statesForPage += 1;
|
|
883
|
+
} catch (error) {
|
|
884
|
+
addEdge(graph, initial.id, void 0, action, "failed");
|
|
885
|
+
graph.failedActionKeys.push(actionKey);
|
|
886
|
+
} finally {
|
|
887
|
+
await page.goto(sourceUrl, { waitUntil: "domcontentloaded", timeout: config2.pageTimeoutMs }).catch(() => void 0);
|
|
888
|
+
await page.waitForTimeout(Math.min(config2.waitAfterNavigationMs, 300));
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
function actionFromInteraction(stateId2, interaction) {
|
|
893
|
+
const type = interaction.kind === "tab" ? "selectTab" : interaction.kind === "accordion" ? "expandAccordion" : interaction.kind === "dropdown" ? "openDropdown" : interaction.expanded ? "closeDialog" : "openModal";
|
|
894
|
+
const destructive = isDestructiveLabel(interaction.name);
|
|
895
|
+
const description = `${type === "selectTab" ? "Select" : type === "expandAccordion" ? "Expand" : "Open"} \u201C${interaction.name}\u201D`;
|
|
793
896
|
return {
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
897
|
+
id: `${stateId2}|${type}|${interaction.cssSelector}`,
|
|
898
|
+
type,
|
|
899
|
+
description,
|
|
900
|
+
target: interaction.name,
|
|
901
|
+
selector: interaction.cssSelector,
|
|
902
|
+
locator: { role: interaction.role, name: interaction.name },
|
|
903
|
+
safe: !destructive,
|
|
904
|
+
reason: destructive ? "Destructive action was discovered but not executed" : void 0
|
|
800
905
|
};
|
|
801
906
|
}
|
|
907
|
+
function addEdge(graph, fromStateId, toStateId, action, status) {
|
|
908
|
+
const id = `${fromStateId}|${action.id}|${toStateId ?? status}`;
|
|
909
|
+
if (graph.edges.some((edge) => edge.id === id))
|
|
910
|
+
return;
|
|
911
|
+
graph.edges.push({ id, fromStateId, toStateId, action, status });
|
|
912
|
+
}
|
|
802
913
|
async function visitPage(page, item, config2) {
|
|
803
914
|
try {
|
|
804
915
|
const apiRequests = [];
|
|
@@ -867,6 +978,321 @@ async function visitPage(page, item, config2) {
|
|
|
867
978
|
}
|
|
868
979
|
}
|
|
869
980
|
|
|
981
|
+
// ../../packages/explorer/dist/recorder/recorderScript.js
|
|
982
|
+
function recorderInitScript() {
|
|
983
|
+
const scope = window;
|
|
984
|
+
const marker = document;
|
|
985
|
+
if (marker.__lazyscoutRecorderReady)
|
|
986
|
+
return;
|
|
987
|
+
marker.__lazyscoutRecorderReady = true;
|
|
988
|
+
const CLICKABLE = 'a,button,input,select,textarea,[role="button"],[role="link"],[role="tab"],[role="menuitem"],[role="checkbox"],[role="radio"],[role="option"]';
|
|
989
|
+
const NON_TEXT_INPUTS = ["button", "submit", "reset", "checkbox", "radio", "file", "image"];
|
|
990
|
+
const send = (event) => {
|
|
991
|
+
try {
|
|
992
|
+
void scope.__lazyscoutRecord?.(event);
|
|
993
|
+
} catch {
|
|
994
|
+
}
|
|
995
|
+
};
|
|
996
|
+
const clean = (value) => (value ?? "").replace(/\s+/g, " ").trim().slice(0, 120);
|
|
997
|
+
const inputType = (element) => element.tagName.toLowerCase() === "input" ? element.type.toLowerCase() : "";
|
|
998
|
+
const roleOf = (element) => {
|
|
999
|
+
const explicit = element.getAttribute("role");
|
|
1000
|
+
if (explicit)
|
|
1001
|
+
return explicit;
|
|
1002
|
+
const tag = element.tagName.toLowerCase();
|
|
1003
|
+
if (tag === "a")
|
|
1004
|
+
return element.hasAttribute("href") ? "link" : void 0;
|
|
1005
|
+
if (tag === "button")
|
|
1006
|
+
return "button";
|
|
1007
|
+
if (tag === "select")
|
|
1008
|
+
return "combobox";
|
|
1009
|
+
if (tag === "textarea")
|
|
1010
|
+
return "textbox";
|
|
1011
|
+
if (/^h[1-6]$/.test(tag))
|
|
1012
|
+
return "heading";
|
|
1013
|
+
if (tag !== "input")
|
|
1014
|
+
return void 0;
|
|
1015
|
+
const type = inputType(element);
|
|
1016
|
+
if (type === "button" || type === "submit" || type === "reset" || type === "image")
|
|
1017
|
+
return "button";
|
|
1018
|
+
if (type === "checkbox")
|
|
1019
|
+
return "checkbox";
|
|
1020
|
+
if (type === "radio")
|
|
1021
|
+
return "radio";
|
|
1022
|
+
if (type === "range")
|
|
1023
|
+
return "slider";
|
|
1024
|
+
if (type === "number")
|
|
1025
|
+
return "spinbutton";
|
|
1026
|
+
if (type === "search")
|
|
1027
|
+
return "searchbox";
|
|
1028
|
+
if (type === "hidden")
|
|
1029
|
+
return void 0;
|
|
1030
|
+
return "textbox";
|
|
1031
|
+
};
|
|
1032
|
+
const labelOf2 = (element) => {
|
|
1033
|
+
const id = element.getAttribute("id");
|
|
1034
|
+
if (id) {
|
|
1035
|
+
const explicit = document.querySelector(`label[for="${CSS.escape(id)}"]`);
|
|
1036
|
+
const value = clean(explicit?.textContent);
|
|
1037
|
+
if (value)
|
|
1038
|
+
return value;
|
|
1039
|
+
}
|
|
1040
|
+
const wrapping = element.closest("label");
|
|
1041
|
+
return clean(wrapping?.textContent) || void 0;
|
|
1042
|
+
};
|
|
1043
|
+
const accessibleName = (element) => {
|
|
1044
|
+
const aria = clean(element.getAttribute("aria-label"));
|
|
1045
|
+
if (aria)
|
|
1046
|
+
return aria;
|
|
1047
|
+
const labelledBy = element.getAttribute("aria-labelledby");
|
|
1048
|
+
if (labelledBy) {
|
|
1049
|
+
const parts = labelledBy.split(/\s+/).map((ref) => document.getElementById(ref)?.textContent ?? "");
|
|
1050
|
+
const joined = clean(parts.join(" "));
|
|
1051
|
+
if (joined)
|
|
1052
|
+
return joined;
|
|
1053
|
+
}
|
|
1054
|
+
const label = labelOf2(element);
|
|
1055
|
+
if (label)
|
|
1056
|
+
return label;
|
|
1057
|
+
const title = clean(element.getAttribute("title"));
|
|
1058
|
+
if (title)
|
|
1059
|
+
return title;
|
|
1060
|
+
const alt = clean(element.getAttribute("alt"));
|
|
1061
|
+
if (alt)
|
|
1062
|
+
return alt;
|
|
1063
|
+
if (element.tagName.toLowerCase() === "input") {
|
|
1064
|
+
const type = inputType(element);
|
|
1065
|
+
if (type === "button" || type === "submit" || type === "reset") {
|
|
1066
|
+
const value = clean(element.getAttribute("value"));
|
|
1067
|
+
if (value)
|
|
1068
|
+
return value;
|
|
1069
|
+
}
|
|
1070
|
+
return void 0;
|
|
1071
|
+
}
|
|
1072
|
+
return clean(element.textContent) || void 0;
|
|
1073
|
+
};
|
|
1074
|
+
const cssPath = (element) => {
|
|
1075
|
+
const testId = element.getAttribute("data-testid") ?? element.getAttribute("data-test-id") ?? element.getAttribute("data-test");
|
|
1076
|
+
if (testId)
|
|
1077
|
+
return `[data-testid="${testId}"]`;
|
|
1078
|
+
const id = element.getAttribute("id");
|
|
1079
|
+
if (id && !/\d{4,}/.test(id))
|
|
1080
|
+
return `#${CSS.escape(id)}`;
|
|
1081
|
+
const name = element.getAttribute("name");
|
|
1082
|
+
if (name)
|
|
1083
|
+
return `${element.tagName.toLowerCase()}[name="${CSS.escape(name)}"]`;
|
|
1084
|
+
const parts = [];
|
|
1085
|
+
let node = element;
|
|
1086
|
+
let depth = 0;
|
|
1087
|
+
while (node && depth < 4) {
|
|
1088
|
+
const parent = node.parentElement;
|
|
1089
|
+
let part = node.tagName.toLowerCase();
|
|
1090
|
+
if (parent) {
|
|
1091
|
+
const tagName = node.tagName;
|
|
1092
|
+
const siblings = Array.from(parent.children).filter((child) => child.tagName === tagName);
|
|
1093
|
+
if (siblings.length > 1)
|
|
1094
|
+
part += `:nth-of-type(${siblings.indexOf(node) + 1})`;
|
|
1095
|
+
}
|
|
1096
|
+
parts.unshift(part);
|
|
1097
|
+
node = parent;
|
|
1098
|
+
depth += 1;
|
|
1099
|
+
}
|
|
1100
|
+
return parts.join(" > ");
|
|
1101
|
+
};
|
|
1102
|
+
const targetOf = (element) => {
|
|
1103
|
+
const role = roleOf(element);
|
|
1104
|
+
return {
|
|
1105
|
+
role,
|
|
1106
|
+
name: accessibleName(element),
|
|
1107
|
+
// Only offer text matching where there is no role to match on.
|
|
1108
|
+
text: role ? void 0 : clean(element.textContent) || void 0,
|
|
1109
|
+
label: labelOf2(element),
|
|
1110
|
+
placeholder: clean(element.getAttribute("placeholder")) || void 0,
|
|
1111
|
+
cssSelector: cssPath(element)
|
|
1112
|
+
};
|
|
1113
|
+
};
|
|
1114
|
+
document.addEventListener("click", (event) => {
|
|
1115
|
+
const origin = event.target instanceof Element ? event.target : null;
|
|
1116
|
+
const element = origin?.closest(CLICKABLE);
|
|
1117
|
+
if (!element)
|
|
1118
|
+
return;
|
|
1119
|
+
const tag = element.tagName.toLowerCase();
|
|
1120
|
+
if (tag === "select")
|
|
1121
|
+
return;
|
|
1122
|
+
if (tag === "textarea")
|
|
1123
|
+
return;
|
|
1124
|
+
if (tag === "input" && !NON_TEXT_INPUTS.includes(inputType(element)))
|
|
1125
|
+
return;
|
|
1126
|
+
send({ kind: "click", target: targetOf(element), url: location.href });
|
|
1127
|
+
}, true);
|
|
1128
|
+
const pendingFlush = /* @__PURE__ */ new WeakMap();
|
|
1129
|
+
const flushField = (element) => {
|
|
1130
|
+
const timer = pendingFlush.get(element);
|
|
1131
|
+
if (timer !== void 0) {
|
|
1132
|
+
clearTimeout(timer);
|
|
1133
|
+
pendingFlush.delete(element);
|
|
1134
|
+
}
|
|
1135
|
+
const tag = element.tagName.toLowerCase();
|
|
1136
|
+
if (tag === "textarea") {
|
|
1137
|
+
send({
|
|
1138
|
+
kind: "fill",
|
|
1139
|
+
target: targetOf(element),
|
|
1140
|
+
value: element.value.slice(0, 200),
|
|
1141
|
+
url: location.href
|
|
1142
|
+
});
|
|
1143
|
+
return;
|
|
1144
|
+
}
|
|
1145
|
+
if (tag !== "input")
|
|
1146
|
+
return;
|
|
1147
|
+
const input = element;
|
|
1148
|
+
const type = inputType(element);
|
|
1149
|
+
if (NON_TEXT_INPUTS.includes(type))
|
|
1150
|
+
return;
|
|
1151
|
+
if (type === "password") {
|
|
1152
|
+
send({ kind: "fill", target: targetOf(element), value: "", secret: true, url: location.href });
|
|
1153
|
+
return;
|
|
1154
|
+
}
|
|
1155
|
+
send({ kind: "fill", target: targetOf(element), value: input.value.slice(0, 200), url: location.href });
|
|
1156
|
+
};
|
|
1157
|
+
document.addEventListener("input", (event) => {
|
|
1158
|
+
const element = event.target instanceof Element ? event.target : null;
|
|
1159
|
+
if (!element)
|
|
1160
|
+
return;
|
|
1161
|
+
const tag = element.tagName.toLowerCase();
|
|
1162
|
+
if (tag !== "input" && tag !== "textarea")
|
|
1163
|
+
return;
|
|
1164
|
+
const existing = pendingFlush.get(element);
|
|
1165
|
+
if (existing !== void 0)
|
|
1166
|
+
clearTimeout(existing);
|
|
1167
|
+
pendingFlush.set(element, setTimeout(() => flushField(element), 400));
|
|
1168
|
+
}, true);
|
|
1169
|
+
document.addEventListener("change", (event) => {
|
|
1170
|
+
const element = event.target instanceof Element ? event.target : null;
|
|
1171
|
+
if (!element)
|
|
1172
|
+
return;
|
|
1173
|
+
const tag = element.tagName.toLowerCase();
|
|
1174
|
+
if (tag === "select") {
|
|
1175
|
+
const select = element;
|
|
1176
|
+
const option = select.options[select.selectedIndex];
|
|
1177
|
+
send({
|
|
1178
|
+
kind: "select",
|
|
1179
|
+
target: targetOf(element),
|
|
1180
|
+
option: clean(option?.text) || select.value,
|
|
1181
|
+
url: location.href
|
|
1182
|
+
});
|
|
1183
|
+
return;
|
|
1184
|
+
}
|
|
1185
|
+
flushField(element);
|
|
1186
|
+
}, true);
|
|
1187
|
+
window.addEventListener("pagehide", () => {
|
|
1188
|
+
const active = document.activeElement;
|
|
1189
|
+
if (active)
|
|
1190
|
+
flushField(active);
|
|
1191
|
+
});
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
// ../../packages/explorer/dist/recorder/attachRecorder.js
|
|
1195
|
+
var SECRET_PLACEHOLDER = "{{TEST_PASSWORD}}";
|
|
1196
|
+
var MAX_RECORDED_STEPS = 200;
|
|
1197
|
+
function closingAssertion(lastActionUrl, finalUrl) {
|
|
1198
|
+
if (!finalUrl || finalUrl === lastActionUrl)
|
|
1199
|
+
return void 0;
|
|
1200
|
+
let path;
|
|
1201
|
+
try {
|
|
1202
|
+
path = new URL(finalUrl).pathname;
|
|
1203
|
+
} catch {
|
|
1204
|
+
return void 0;
|
|
1205
|
+
}
|
|
1206
|
+
if (!path || path === "/")
|
|
1207
|
+
return void 0;
|
|
1208
|
+
return { type: "assertUrl", urlContains: path };
|
|
1209
|
+
}
|
|
1210
|
+
var sameTarget = (left, right) => left.cssSelector === right.cssSelector && left.role === right.role && left.name === right.name;
|
|
1211
|
+
function compactTarget(target) {
|
|
1212
|
+
const entries = Object.entries(target).filter(([, value]) => value !== void 0 && value !== "");
|
|
1213
|
+
return Object.fromEntries(entries);
|
|
1214
|
+
}
|
|
1215
|
+
function buildStep(event) {
|
|
1216
|
+
const target = compactTarget(event.target);
|
|
1217
|
+
if (event.kind === "click")
|
|
1218
|
+
return { type: "click", target };
|
|
1219
|
+
if (event.kind === "select")
|
|
1220
|
+
return { type: "select", target, option: event.option };
|
|
1221
|
+
return { type: "fill", target, value: event.secret ? SECRET_PLACEHOLDER : event.value };
|
|
1222
|
+
}
|
|
1223
|
+
async function attachRecorder(context, startUrl, options = {}) {
|
|
1224
|
+
const steps = [];
|
|
1225
|
+
let lastUrl = "";
|
|
1226
|
+
let finalUrl = "";
|
|
1227
|
+
let sawPage = false;
|
|
1228
|
+
let ended = false;
|
|
1229
|
+
const end = () => {
|
|
1230
|
+
if (ended)
|
|
1231
|
+
return;
|
|
1232
|
+
ended = true;
|
|
1233
|
+
options.onEnded?.();
|
|
1234
|
+
};
|
|
1235
|
+
const pushNavigate = (url) => {
|
|
1236
|
+
if (!url || url === "about:blank" || url === lastUrl)
|
|
1237
|
+
return;
|
|
1238
|
+
lastUrl = url;
|
|
1239
|
+
if (steps.length < MAX_RECORDED_STEPS)
|
|
1240
|
+
steps.push({ type: "navigate", url });
|
|
1241
|
+
};
|
|
1242
|
+
const record = (event) => {
|
|
1243
|
+
if (steps.length >= MAX_RECORDED_STEPS)
|
|
1244
|
+
return;
|
|
1245
|
+
pushNavigate(event.url);
|
|
1246
|
+
const step = buildStep(event);
|
|
1247
|
+
if (!step)
|
|
1248
|
+
return;
|
|
1249
|
+
const previous = steps[steps.length - 1];
|
|
1250
|
+
if (step.type === "fill" && previous && previous.type === "fill" && sameTarget(previous.target, step.target) && previous.value !== SECRET_PLACEHOLDER) {
|
|
1251
|
+
steps[steps.length - 1] = step;
|
|
1252
|
+
return;
|
|
1253
|
+
}
|
|
1254
|
+
steps.push(step);
|
|
1255
|
+
};
|
|
1256
|
+
await context.exposeBinding("__lazyscoutRecord", (_source, event) => {
|
|
1257
|
+
try {
|
|
1258
|
+
record(event);
|
|
1259
|
+
} catch {
|
|
1260
|
+
}
|
|
1261
|
+
});
|
|
1262
|
+
await context.addInitScript(recorderInitScript);
|
|
1263
|
+
const inject = (page) => {
|
|
1264
|
+
void page.evaluate(recorderInitScript).catch(() => void 0);
|
|
1265
|
+
};
|
|
1266
|
+
const watchPage = (page) => {
|
|
1267
|
+
sawPage = true;
|
|
1268
|
+
inject(page);
|
|
1269
|
+
page.on("domcontentloaded", () => inject(page));
|
|
1270
|
+
page.on("framenavigated", (frame) => {
|
|
1271
|
+
if (frame !== page.mainFrame())
|
|
1272
|
+
return;
|
|
1273
|
+
const url = frame.url();
|
|
1274
|
+
if (url && url !== "about:blank")
|
|
1275
|
+
finalUrl = url;
|
|
1276
|
+
});
|
|
1277
|
+
page.on("close", () => {
|
|
1278
|
+
if (sawPage && context.pages().length === 0)
|
|
1279
|
+
end();
|
|
1280
|
+
});
|
|
1281
|
+
};
|
|
1282
|
+
context.pages().forEach(watchPage);
|
|
1283
|
+
context.on("page", watchPage);
|
|
1284
|
+
context.on("close", end);
|
|
1285
|
+
pushNavigate(startUrl);
|
|
1286
|
+
return {
|
|
1287
|
+
steps: () => steps.slice(),
|
|
1288
|
+
finalize: () => {
|
|
1289
|
+
const closing = closingAssertion(lastUrl, finalUrl);
|
|
1290
|
+
return closing ? [...steps, closing] : steps.slice();
|
|
1291
|
+
},
|
|
1292
|
+
currentUrl: () => lastUrl
|
|
1293
|
+
};
|
|
1294
|
+
}
|
|
1295
|
+
|
|
870
1296
|
// ../../packages/generators/dist/moduleNames.js
|
|
871
1297
|
function assignModules(pages) {
|
|
872
1298
|
const result = /* @__PURE__ */ new Map();
|
|
@@ -1436,7 +1862,10 @@ function registerAnalyzeRoute(app) {
|
|
|
1436
1862
|
const firstIssue = result.issues[0];
|
|
1437
1863
|
throw new ExplorerError(firstIssue?.code ?? "navigation-failed", firstIssue?.message ?? "Could not open the website.", "Check that the URL is correct and the website is available.");
|
|
1438
1864
|
}
|
|
1439
|
-
const testCases =
|
|
1865
|
+
const testCases = [
|
|
1866
|
+
...generateTestCases(result.pages, { language: body.language ?? "en" }),
|
|
1867
|
+
...generateStateFlowTestCases(result.actionGraph)
|
|
1868
|
+
];
|
|
1440
1869
|
const runEvents = [
|
|
1441
1870
|
{
|
|
1442
1871
|
timestamp: new Date(Date.now() - result.stats.durationMs).toISOString(),
|
|
@@ -1462,6 +1891,23 @@ function registerAnalyzeRoute(app) {
|
|
|
1462
1891
|
message: `${interaction.kind}: ${interaction.name}`
|
|
1463
1892
|
}))
|
|
1464
1893
|
]),
|
|
1894
|
+
...result.actionGraph.states.map((state) => ({
|
|
1895
|
+
timestamp: state.discoveredAt,
|
|
1896
|
+
eventType: "state-discovered",
|
|
1897
|
+
currentUrl: state.url,
|
|
1898
|
+
currentStateId: state.id,
|
|
1899
|
+
result: "passed",
|
|
1900
|
+
message: `State observed: ${state.name || state.title || state.url}`
|
|
1901
|
+
})),
|
|
1902
|
+
...result.actionGraph.edges.map((edge) => ({
|
|
1903
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1904
|
+
eventType: edge.status === "blocked" ? "action-blocked" : edge.status === "failed" ? "action-failed" : edge.status === "visited" ? "action-executed" : "transition-discovered",
|
|
1905
|
+
currentUrl: result.actionGraph.states.find((state) => state.id === edge.fromStateId)?.url,
|
|
1906
|
+
currentStateId: edge.fromStateId,
|
|
1907
|
+
action: edge.action,
|
|
1908
|
+
result: edge.status === "blocked" ? "blocked" : edge.status === "failed" ? "failed" : edge.status === "visited" ? "passed" : "warning",
|
|
1909
|
+
message: edge.action.description
|
|
1910
|
+
})),
|
|
1465
1911
|
...result.issues.map((issue) => ({
|
|
1466
1912
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1467
1913
|
eventType: "error",
|
|
@@ -1498,6 +1944,56 @@ function registerAnalyzeRoute(app) {
|
|
|
1498
1944
|
}
|
|
1499
1945
|
});
|
|
1500
1946
|
}
|
|
1947
|
+
function generateStateFlowTestCases(graph) {
|
|
1948
|
+
const states = new Map(graph.states.map((state) => [state.id, state]));
|
|
1949
|
+
let sequence = 1;
|
|
1950
|
+
return graph.edges.flatMap((edge) => {
|
|
1951
|
+
if (edge.status !== "visited" || !edge.toStateId || edge.fromStateId === edge.toStateId)
|
|
1952
|
+
return [];
|
|
1953
|
+
const target = states.get(edge.toStateId);
|
|
1954
|
+
const source = states.get(edge.fromStateId);
|
|
1955
|
+
if (!target || !source)
|
|
1956
|
+
return [];
|
|
1957
|
+
const observation = expectedObservation(target);
|
|
1958
|
+
const id = `TC-FLOW-${String(sequence).padStart(3, "0")}`;
|
|
1959
|
+
sequence += 1;
|
|
1960
|
+
return [
|
|
1961
|
+
{
|
|
1962
|
+
id,
|
|
1963
|
+
module: "FLOW",
|
|
1964
|
+
tags: ["state-flow"],
|
|
1965
|
+
title: `${edge.action.description} reaches ${target.name}`,
|
|
1966
|
+
preconditions: [`The application is available at ${source.url}`],
|
|
1967
|
+
steps: [
|
|
1968
|
+
{ type: "navigate", url: source.url },
|
|
1969
|
+
{
|
|
1970
|
+
type: "click",
|
|
1971
|
+
target: {
|
|
1972
|
+
role: edge.action.locator?.role,
|
|
1973
|
+
name: edge.action.locator?.name,
|
|
1974
|
+
cssSelector: edge.action.selector
|
|
1975
|
+
}
|
|
1976
|
+
}
|
|
1977
|
+
],
|
|
1978
|
+
expectedResult: observation ?? "Observed state requires tester review before automation.",
|
|
1979
|
+
type: target.type === "validation" || target.type === "error" ? "validation" : "positive",
|
|
1980
|
+
priority: "medium",
|
|
1981
|
+
automationStatus: observation ? "ready" : "needs-review",
|
|
1982
|
+
sourceUrl: source.url,
|
|
1983
|
+
notes: observation ? "Generated from an observed UI state transition." : "Explorer observed a new UI state but no stable assertion text."
|
|
1984
|
+
}
|
|
1985
|
+
];
|
|
1986
|
+
});
|
|
1987
|
+
}
|
|
1988
|
+
function expectedObservation(state) {
|
|
1989
|
+
if (state.visibleDialogs[0])
|
|
1990
|
+
return `Dialog "${state.visibleDialogs[0]}" is visible.`;
|
|
1991
|
+
if (state.validationMessages[0])
|
|
1992
|
+
return `Validation message "${state.validationMessages[0]}" is visible.`;
|
|
1993
|
+
if (state.headings[0])
|
|
1994
|
+
return `Heading "${state.headings[0]}" is visible.`;
|
|
1995
|
+
return void 0;
|
|
1996
|
+
}
|
|
1501
1997
|
function buildApiChecks(pages) {
|
|
1502
1998
|
const seen = /* @__PURE__ */ new Set();
|
|
1503
1999
|
const checks = [];
|
|
@@ -1704,6 +2200,9 @@ async function openWorkspace(root) {
|
|
|
1704
2200
|
else
|
|
1705
2201
|
await execFileAsync("xdg-open", [root]);
|
|
1706
2202
|
}
|
|
2203
|
+
async function browserProfileDirectory(root, projectId) {
|
|
2204
|
+
return join(await ensureProject(root, projectId), "browser-profile");
|
|
2205
|
+
}
|
|
1707
2206
|
async function readProject(root, projectId) {
|
|
1708
2207
|
try {
|
|
1709
2208
|
const directory = projectDirectory(root, projectId);
|
|
@@ -1719,7 +2218,7 @@ async function readProject(root, projectId) {
|
|
|
1719
2218
|
async function ensureProject(root, projectId) {
|
|
1720
2219
|
await ensureWorkspace(root);
|
|
1721
2220
|
const directory = projectDirectory(root, projectId);
|
|
1722
|
-
await Promise.all(["automation", "screenshots", "bugs", "reports", "logs"].map((name) => mkdir(join(directory, name), { recursive: true })));
|
|
2221
|
+
await Promise.all(["automation", "screenshots", "bugs", "reports", "logs", "browser-profile"].map((name) => mkdir(join(directory, name), { recursive: true })));
|
|
1723
2222
|
return directory;
|
|
1724
2223
|
}
|
|
1725
2224
|
function projectDirectory(root, projectId) {
|
|
@@ -1828,7 +2327,7 @@ function registerAutomationRunRoute(app, workspaceRoot) {
|
|
|
1828
2327
|
if (!active)
|
|
1829
2328
|
return reply.send({ stopped: false });
|
|
1830
2329
|
active.stopped = true;
|
|
1831
|
-
await active.
|
|
2330
|
+
await active.close?.().catch(() => void 0);
|
|
1832
2331
|
return reply.send({ stopped: true });
|
|
1833
2332
|
});
|
|
1834
2333
|
app.post("/api/automation/run", async (request, reply) => {
|
|
@@ -1884,16 +2383,17 @@ function registerAutomationRunRoute(app, workspaceRoot) {
|
|
|
1884
2383
|
}
|
|
1885
2384
|
const active = { stopped: false };
|
|
1886
2385
|
activeRuns.set(runId, active);
|
|
1887
|
-
let
|
|
2386
|
+
let close;
|
|
1888
2387
|
let page;
|
|
1889
2388
|
const capturedScreenshots = [];
|
|
1890
2389
|
try {
|
|
1891
|
-
const
|
|
1892
|
-
|
|
1893
|
-
|
|
2390
|
+
const profile = body.projectId ? await browserProfileDirectory(workspaceRoot, body.projectId) : void 0;
|
|
2391
|
+
const launched = await launchBrowser({ userDataDir: profile });
|
|
2392
|
+
close = launched.close;
|
|
2393
|
+
active.close = close;
|
|
1894
2394
|
if (active.stopped)
|
|
1895
2395
|
throw new Error("Run stopped by user");
|
|
1896
|
-
const
|
|
2396
|
+
const { context } = launched;
|
|
1897
2397
|
context.setDefaultTimeout(STEP_TIMEOUT_MS);
|
|
1898
2398
|
page = await context.newPage();
|
|
1899
2399
|
if (typeof body.code === "string" && body.code.trim()) {
|
|
@@ -1942,7 +2442,7 @@ function registerAutomationRunRoute(app, workspaceRoot) {
|
|
|
1942
2442
|
});
|
|
1943
2443
|
} finally {
|
|
1944
2444
|
activeRuns.delete(runId);
|
|
1945
|
-
await
|
|
2445
|
+
await close?.().catch(() => void 0);
|
|
1946
2446
|
}
|
|
1947
2447
|
});
|
|
1948
2448
|
}
|
|
@@ -2164,6 +2664,11 @@ function parseEditedLocator(page, expression) {
|
|
|
2164
2664
|
const name = parseStringLiteral(roleMatch[2]);
|
|
2165
2665
|
return { locator: page.getByRole(role, { name }), label: name };
|
|
2166
2666
|
}
|
|
2667
|
+
const roleOnlyMatch = expression.match(new RegExp(`^page\\.getByRole\\((${STRING_LITERAL})\\)$`));
|
|
2668
|
+
if (roleOnlyMatch) {
|
|
2669
|
+
const role = parseStringLiteral(roleOnlyMatch[1]);
|
|
2670
|
+
return { locator: page.getByRole(role), label: role };
|
|
2671
|
+
}
|
|
2167
2672
|
for (const [method, create] of [
|
|
2168
2673
|
["getByLabel", (value) => page.getByLabel(value)],
|
|
2169
2674
|
["getByPlaceholder", (value) => page.getByPlaceholder(value)],
|
|
@@ -2597,6 +3102,16 @@ function registerWorkspaceRoutes(app, root) {
|
|
|
2597
3102
|
await deleteProject(root, request.params.projectId);
|
|
2598
3103
|
return reply.send({ deleted: true });
|
|
2599
3104
|
});
|
|
3105
|
+
app.post("/api/workspace/projects/:projectId/auth-session", async (request, reply) => {
|
|
3106
|
+
const body = request.body;
|
|
3107
|
+
if (!body?.url)
|
|
3108
|
+
return reply.status(400).send({ error: { code: "invalid-url", message: "A login URL is required." } });
|
|
3109
|
+
const profile = await browserProfileDirectory(root, request.params.projectId);
|
|
3110
|
+
const launched = await launchBrowser({ userDataDir: profile, headless: false });
|
|
3111
|
+
const page = launched.context.pages()[0] ?? await launched.context.newPage();
|
|
3112
|
+
await page.goto(body.url, { waitUntil: "domcontentloaded" });
|
|
3113
|
+
return reply.send({ opened: true });
|
|
3114
|
+
});
|
|
2600
3115
|
app.get("/api/workspace/projects/:projectId/screenshots", async (request) => readScreenshots(root, request.params.projectId));
|
|
2601
3116
|
app.post("/api/workspace/projects/:projectId/screenshots", async (request) => saveScreenshot(root, request.params.projectId, request.body));
|
|
2602
3117
|
app.get("/api/workspace/projects/:projectId/screenshots/:name", async (request, reply) => {
|
|
@@ -2634,6 +3149,115 @@ function registerWorkspaceRoutes(app, root) {
|
|
|
2634
3149
|
});
|
|
2635
3150
|
}
|
|
2636
3151
|
|
|
3152
|
+
// ../server/dist/recorderSessions.js
|
|
3153
|
+
function idleRecorderState(projectId) {
|
|
3154
|
+
return { projectId, status: "idle", startUrl: "", startedAt: "", steps: [] };
|
|
3155
|
+
}
|
|
3156
|
+
var RecorderSessions = class {
|
|
3157
|
+
launch;
|
|
3158
|
+
sessions = /* @__PURE__ */ new Map();
|
|
3159
|
+
constructor(launch) {
|
|
3160
|
+
this.launch = launch;
|
|
3161
|
+
}
|
|
3162
|
+
isRunning(projectId) {
|
|
3163
|
+
const session = this.sessions.get(projectId);
|
|
3164
|
+
return Boolean(session && !session.closed);
|
|
3165
|
+
}
|
|
3166
|
+
state(projectId) {
|
|
3167
|
+
const session = this.sessions.get(projectId);
|
|
3168
|
+
if (!session)
|
|
3169
|
+
return idleRecorderState(projectId);
|
|
3170
|
+
return {
|
|
3171
|
+
projectId: session.projectId,
|
|
3172
|
+
status: session.closed ? "stopped" : "recording",
|
|
3173
|
+
startUrl: session.startUrl,
|
|
3174
|
+
startedAt: session.startedAt,
|
|
3175
|
+
browserLabel: session.browserLabel,
|
|
3176
|
+
steps: session.finalSteps ?? session.handle.steps()
|
|
3177
|
+
};
|
|
3178
|
+
}
|
|
3179
|
+
async start(projectId, startUrl) {
|
|
3180
|
+
const launched = await this.launch(projectId);
|
|
3181
|
+
const handle = await attachRecorder(launched.context, startUrl, {
|
|
3182
|
+
onEnded: () => {
|
|
3183
|
+
const current = this.sessions.get(projectId);
|
|
3184
|
+
if (current)
|
|
3185
|
+
void this.finish(current);
|
|
3186
|
+
}
|
|
3187
|
+
});
|
|
3188
|
+
const session = {
|
|
3189
|
+
projectId,
|
|
3190
|
+
startUrl,
|
|
3191
|
+
startedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3192
|
+
browserLabel: launched.label,
|
|
3193
|
+
handle,
|
|
3194
|
+
close: launched.close,
|
|
3195
|
+
closed: false
|
|
3196
|
+
};
|
|
3197
|
+
this.sessions.set(projectId, session);
|
|
3198
|
+
const page = launched.context.pages()[0] ?? await launched.context.newPage();
|
|
3199
|
+
await page.goto(startUrl, { waitUntil: "domcontentloaded" });
|
|
3200
|
+
return this.state(projectId);
|
|
3201
|
+
}
|
|
3202
|
+
async stop(projectId) {
|
|
3203
|
+
const session = this.sessions.get(projectId);
|
|
3204
|
+
if (!session)
|
|
3205
|
+
return idleRecorderState(projectId);
|
|
3206
|
+
await this.finish(session);
|
|
3207
|
+
return this.state(projectId);
|
|
3208
|
+
}
|
|
3209
|
+
async closeAll() {
|
|
3210
|
+
await Promise.all([...this.sessions.values()].map((session) => this.finish(session)));
|
|
3211
|
+
this.sessions.clear();
|
|
3212
|
+
}
|
|
3213
|
+
async finish(session) {
|
|
3214
|
+
if (session.closed)
|
|
3215
|
+
return;
|
|
3216
|
+
session.finalSteps = session.handle.finalize();
|
|
3217
|
+
session.closed = true;
|
|
3218
|
+
await session.close().catch(() => void 0);
|
|
3219
|
+
}
|
|
3220
|
+
};
|
|
3221
|
+
|
|
3222
|
+
// ../server/dist/routes/recorder.js
|
|
3223
|
+
function registerRecorderRoutes(app, workspaceRoot, options = {}) {
|
|
3224
|
+
const launch = options.launch ?? (async (projectId) => launchBrowser({ userDataDir: await browserProfileDirectory(workspaceRoot, projectId), headless: false }));
|
|
3225
|
+
const sessions = new RecorderSessions(launch);
|
|
3226
|
+
app.post("/api/recorder/:projectId/start", async (request, reply) => {
|
|
3227
|
+
const { projectId } = request.params;
|
|
3228
|
+
const body = request.body;
|
|
3229
|
+
if (!body?.url)
|
|
3230
|
+
return reply.status(400).send({ error: { code: "invalid-url", message: "A start URL is required." } });
|
|
3231
|
+
const check = checkTargetUrl(body.url, config.urlPolicy);
|
|
3232
|
+
if (!check.ok)
|
|
3233
|
+
return reply.status(400).send({ error: { code: check.code, message: check.message } });
|
|
3234
|
+
if (sessions.isRunning(projectId))
|
|
3235
|
+
return reply.status(409).send({
|
|
3236
|
+
error: {
|
|
3237
|
+
code: "recorder-busy",
|
|
3238
|
+
message: "A recording is already running for this Project.",
|
|
3239
|
+
hint: "Stop the current recording before starting another one."
|
|
3240
|
+
}
|
|
3241
|
+
});
|
|
3242
|
+
try {
|
|
3243
|
+
return reply.send(await sessions.start(projectId, check.url.toString()));
|
|
3244
|
+
} catch (error) {
|
|
3245
|
+
return reply.status(500).send({
|
|
3246
|
+
error: {
|
|
3247
|
+
code: "browser-error",
|
|
3248
|
+
message: error instanceof Error ? error.message : "The browser could not be started.",
|
|
3249
|
+
hint: "Close any other LazyScout browser for this Project and try again."
|
|
3250
|
+
}
|
|
3251
|
+
});
|
|
3252
|
+
}
|
|
3253
|
+
});
|
|
3254
|
+
app.get("/api/recorder/:projectId", async (request) => sessions.state(request.params.projectId));
|
|
3255
|
+
app.post("/api/recorder/:projectId/stop", async (request, reply) => reply.send(await sessions.stop(request.params.projectId)));
|
|
3256
|
+
app.addHook("onClose", async () => {
|
|
3257
|
+
await sessions.closeAll();
|
|
3258
|
+
});
|
|
3259
|
+
}
|
|
3260
|
+
|
|
2637
3261
|
// ../server/dist/app.js
|
|
2638
3262
|
function buildApp(options = {}) {
|
|
2639
3263
|
const app = Fastify({
|
|
@@ -2651,6 +3275,7 @@ function buildApp(options = {}) {
|
|
|
2651
3275
|
registerLoadTestRoute(app);
|
|
2652
3276
|
registerVersionRoutes(app, appVersion);
|
|
2653
3277
|
registerWorkspaceRoutes(app, workspaceRoot);
|
|
3278
|
+
registerRecorderRoutes(app, workspaceRoot);
|
|
2654
3279
|
if (options.staticDir) {
|
|
2655
3280
|
app.register(fastifyStatic, { root: options.staticDir });
|
|
2656
3281
|
app.setNotFoundHandler(async (request, reply) => {
|
|
@@ -2678,7 +3303,7 @@ async function openInBrowser(url) {
|
|
|
2678
3303
|
}
|
|
2679
3304
|
|
|
2680
3305
|
// src/version.ts
|
|
2681
|
-
var VERSION = true ? "0.3.
|
|
3306
|
+
var VERSION = true ? "0.3.2" : "0.0.0-dev";
|
|
2682
3307
|
|
|
2683
3308
|
// src/commands/serve.ts
|
|
2684
3309
|
var DEFAULT_PORT = 4321;
|
|
@@ -2751,7 +3376,8 @@ npx lazyscout scan https://example.com --max-pages 10 --csv report.csv
|
|
|
2751
3376
|
|
|
2752
3377
|
Explorer Behavior
|
|
2753
3378
|
LazyScout only explores URLs within the same origin.
|
|
2754
|
-
It
|
|
3379
|
+
It follows links and tries a small, safe set of UI controls such as tabs and dialogs.
|
|
3380
|
+
It never submits forms or fills credentials automatically.
|
|
2755
3381
|
`;
|
|
2756
3382
|
async function main() {
|
|
2757
3383
|
const { values, positionals } = parseArgs({
|