@@ -2990,19 +2990,38 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
29902990 locator ,
29912991 ) ;
29922992 const point = yield * evaluateWithDebugger <
2993- { x : number ; y : number } | { invalidSelector : true ; message : string } | { notFound : true }
2993+ | { x : number ; y : number }
2994+ | { invalidSelector : true ; message : string }
2995+ | {
2996+ notFound : true ;
2997+ failureKind : "missing" | "hidden" | "disabled" | "ambiguous" ;
2998+ matchCount ?: number ;
2999+ }
29943000 > (
29953001 tabId ,
29963002 send ,
29973003 `(() => {
29983004 try {
29993005 const injected = globalThis.__t3PlaywrightInjected;
30003006 const parsed = injected.parseSelector(${ locatorJson } );
3001- const element = injected.querySelector(parsed, document, true);
3002- if (!element) return { notFound: true };
3007+ let element;
3008+ try {
3009+ element = injected.querySelector(parsed, document, true);
3010+ } catch (error) {
3011+ const message = String(error);
3012+ if (message.toLowerCase().includes("strict mode")) {
3013+ const matches = injected.querySelectorAll
3014+ ? injected.querySelectorAll(parsed, document)
3015+ : [];
3016+ return { notFound: true, failureKind: "ambiguous", matchCount: matches.length || 2 };
3017+ }
3018+ throw error;
3019+ }
3020+ if (!element) return { notFound: true, failureKind: "missing" };
30033021 const visible = injected.elementState(element, "visible");
30043022 const enabled = injected.elementState(element, "enabled");
3005- if (!visible.matches || !enabled.matches) return { notFound: true };
3023+ if (!visible.matches) return { notFound: true, failureKind: "hidden" };
3024+ if (!enabled.matches) return { notFound: true, failureKind: "disabled" };
30063025 element.scrollIntoView({ block: "center", inline: "center" });
30073026 const rect = element.getBoundingClientRect();
30083027 return { x: rect.left + rect.width / 2, y: rect.top + rect.height / 2 };
@@ -3022,10 +3041,12 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
30223041 } ) ;
30233042 }
30243043 if ( "notFound" in point ) {
3025- return yield * new PreviewAutomationTargetNotFoundError ( {
3044+ return yield * raiseAutomationTargetLookupError ( {
30263045 operation : "click" ,
30273046 tabId,
30283047 ...automationSelectorDiagnostics ( input ) ,
3048+ failureKind : point . failureKind ,
3049+ ...( point . matchCount === undefined ? { } : { matchCount : point . matchCount } ) ,
30293050 } ) ;
30303051 }
30313052 return point ;
@@ -3668,21 +3689,85 @@ export class PreviewAutomationEvaluationError extends Schema.TaggedErrorClass<Pr
36683689 }
36693690}
36703691
3692+ const PreviewAutomationTargetLookupFields = {
3693+ operation : Schema . String ,
3694+ tabId : Schema . String ,
3695+ selectorKind : PreviewAutomationSelectorKind ,
3696+ selectorLength : Schema . optionalKey ( Schema . Number ) ,
3697+ } ;
3698+
36713699export class PreviewAutomationTargetNotFoundError extends Schema . TaggedErrorClass < PreviewAutomationTargetNotFoundError > ( ) (
36723700 "PreviewAutomationTargetNotFoundError" ,
3701+ PreviewAutomationTargetLookupFields ,
3702+ ) {
3703+ override get message ( ) : string {
3704+ const target = previewAutomationTargetLabel ( this . selectorKind , this . selectorLength ) ;
3705+ return `Preview automation ${ this . operation } could not find ${ target } in tab ${ this . tabId } ` ;
3706+ }
3707+ }
3708+
3709+ export class PreviewAutomationTargetHiddenError extends Schema . TaggedErrorClass < PreviewAutomationTargetHiddenError > ( ) (
3710+ "PreviewAutomationTargetHiddenError" ,
3711+ PreviewAutomationTargetLookupFields ,
3712+ ) {
3713+ override get message ( ) : string {
3714+ const target = previewAutomationTargetLabel ( this . selectorKind , this . selectorLength ) ;
3715+ return `Preview automation ${ this . operation } found ${ target } in tab ${ this . tabId } , but it is not visible` ;
3716+ }
3717+ }
3718+
3719+ export class PreviewAutomationTargetDisabledError extends Schema . TaggedErrorClass < PreviewAutomationTargetDisabledError > ( ) (
3720+ "PreviewAutomationTargetDisabledError" ,
3721+ PreviewAutomationTargetLookupFields ,
3722+ ) {
3723+ override get message ( ) : string {
3724+ const target = previewAutomationTargetLabel ( this . selectorKind , this . selectorLength ) ;
3725+ return `Preview automation ${ this . operation } found ${ target } in tab ${ this . tabId } , but it is disabled` ;
3726+ }
3727+ }
3728+
3729+ export class PreviewAutomationTargetAmbiguousError extends Schema . TaggedErrorClass < PreviewAutomationTargetAmbiguousError > ( ) (
3730+ "PreviewAutomationTargetAmbiguousError" ,
36733731 {
3674- operation : Schema . String ,
3675- tabId : Schema . String ,
3676- selectorKind : PreviewAutomationSelectorKind ,
3677- selectorLength : Schema . optionalKey ( Schema . Number ) ,
3732+ ...PreviewAutomationTargetLookupFields ,
3733+ matchCount : Schema . Number ,
36783734 } ,
36793735) {
36803736 override get message ( ) : string {
36813737 const target = previewAutomationTargetLabel ( this . selectorKind , this . selectorLength ) ;
3682- return `Preview automation ${ this . operation } could not find ${ target } in tab ${ this . tabId } ` ;
3738+ return `Preview automation ${ this . operation } matched ${ this . matchCount } elements for ${ target } in tab ${ this . tabId } ` ;
36833739 }
36843740}
36853741
3742+ const raiseAutomationTargetLookupError = ( input : {
3743+ readonly operation : string ;
3744+ readonly tabId : string ;
3745+ readonly selectorKind : PreviewAutomationSelectorKind ;
3746+ readonly selectorLength ?: number ;
3747+ readonly failureKind ?: "missing" | "hidden" | "disabled" | "ambiguous" ;
3748+ readonly matchCount ?: number ;
3749+ } ) => {
3750+ const shared = {
3751+ operation : input . operation ,
3752+ tabId : input . tabId ,
3753+ selectorKind : input . selectorKind ,
3754+ ...( input . selectorLength === undefined ? { } : { selectorLength : input . selectorLength } ) ,
3755+ } ;
3756+ if ( input . failureKind === "hidden" ) {
3757+ return new PreviewAutomationTargetHiddenError ( shared ) ;
3758+ }
3759+ if ( input . failureKind === "disabled" ) {
3760+ return new PreviewAutomationTargetDisabledError ( shared ) ;
3761+ }
3762+ if ( input . failureKind === "ambiguous" ) {
3763+ return new PreviewAutomationTargetAmbiguousError ( {
3764+ ...shared ,
3765+ matchCount : input . matchCount ?? 0 ,
3766+ } ) ;
3767+ }
3768+ return new PreviewAutomationTargetNotFoundError ( shared ) ;
3769+ } ;
3770+
36863771export class PreviewAutomationTargetNotEditableError extends Schema . TaggedErrorClass < PreviewAutomationTargetNotEditableError > ( ) (
36873772 "PreviewAutomationTargetNotEditableError" ,
36883773 {
@@ -3798,6 +3883,9 @@ export const PreviewManagerError = Schema.Union([
37983883 PreviewAutomationDebuggerAttachedError ,
37993884 PreviewAutomationEvaluationError ,
38003885 PreviewAutomationTargetNotFoundError ,
3886+ PreviewAutomationTargetHiddenError ,
3887+ PreviewAutomationTargetDisabledError ,
3888+ PreviewAutomationTargetAmbiguousError ,
38013889 PreviewAutomationTargetNotEditableError ,
38023890 PreviewAutomationCoordinatesOutsideViewportError ,
38033891 PreviewAutomationInvalidSelectorError ,
0 commit comments