@@ -896,30 +896,33 @@ class Playwright extends Helper {
896896        try  { 
897897          this . debugSection ( 'Playwright' ,  `registering custom locator strategy: ${ strategyName }  ) 
898898
899-           // Create a selector engine for this custom strategy 
900-           const  engine  =  { 
901-             query ( root ,  selector )  { 
899+           // Convert the function to a string and create the selector engine content 
900+           const  functionString  =  strategyFunction . toString ( ) 
901+           const  selectorEngine  =  ` 
902+             exports.query = (root, selector) => { 
902903              try { 
903-                 const  result  =  strategyFunction ( selector ,  root ) 
904-                 return  Array . isArray ( result )  ? result [ 0 ]  : result 
904+                 const strategyFunction = ${ functionString }  
905+                 const result = strategyFunction(selector, root); 
906+                 return Array.isArray(result) ? result[0] : result; 
905907              } catch (error) { 
906-                 console . warn ( ` Error in custom locator ' ${ strategyName } ':` ,  error ) 
907-                 return  null 
908+                 console.warn(' Error in custom locator " ${ strategyName } ":' , error);  
909+                 return null;  
908910              } 
909-             } , 
910- 
911-             queryAll ( root ,  selector )  { 
911+             };  
912+              
913+             exports. queryAll =  (root, selector) =>  { 
912914              try { 
913-                 const  result  =  strategyFunction ( selector ,  root ) 
914-                 return  Array . isArray ( result )  ? result  : result  ? [ result ]  : [ ] 
915+                 const strategyFunction = ${ functionString }  
916+                 const result = strategyFunction(selector, root); 
917+                 return Array.isArray(result) ? result : result ? [result] : []; 
915918              } catch (error) { 
916-                 console . warn ( ` Error in custom locator ' ${ strategyName } ':` ,  error ) 
917-                 return  [ ] 
919+                 console.warn(' Error in custom locator " ${ strategyName } ":' , error);  
920+                 return [];  
918921              } 
919-             } , 
920-           } 
922+             };  
923+           `  
921924
922-           await  playwright . selectors . register ( strategyName ,  engine ) 
925+           await  playwright . selectors . register ( strategyName ,  {   content :  selectorEngine   } ) 
923926        }  catch  ( error )  { 
924927          console . warn ( `Failed to register custom locator strategy '${ strategyName }  ,  error ) 
925928        } 
0 commit comments