@@ -44,6 +44,7 @@ import type { LayoutSelectorName } from './layoutSelectorUtils';
4444import type { SelectorEngine , SelectorRoot } from './selectorEngine' ;
4545import type { GenerateSelectorOptions } from './selectorGenerator' ;
4646import type { ElementText , TextMatcher } from './selectorUtils' ;
47+ import type { Builtins } from '@isomorphic/builtins' ;
4748
4849
4950export type FrameExpectParams = Omit < channels . FrameExpectParams , 'expectedValue' > & { expectedValue ?: any } ;
@@ -64,6 +65,18 @@ interface WebKitLegacyDeviceMotionEvent extends DeviceMotionEvent {
6465 readonly initDeviceMotionEvent : ( type : string , bubbles : boolean , cancelable : boolean , acceleration : DeviceMotionEventAcceleration , accelerationIncludingGravity : DeviceMotionEventAcceleration , rotationRate : DeviceMotionEventRotationRate , interval : number ) => void ;
6566}
6667
68+ export type InjectedScriptOptions = {
69+ isUnderTest : boolean ;
70+ sdkLanguage : Language ;
71+ // For strict error and codegen
72+ testIdAttributeName : string ;
73+ stableRafCount : number ;
74+ browserName : string ;
75+ inputFileRoleTextbox : boolean ;
76+ customEngines : { name : string , source : string } [ ] ;
77+ runtimeGuid : string ;
78+ } ;
79+
6780export class InjectedScript {
6881 private _engines : Map < string , SelectorEngine > ;
6982 readonly _evaluator : SelectorEvaluatorImpl ;
@@ -96,7 +109,7 @@ export class InjectedScript {
96109 isInsideScope,
97110 normalizeWhiteSpace,
98111 parseAriaSnapshot,
99- builtins : builtins ( ) ,
112+ builtins : null as unknown as Builtins ,
100113 } ;
101114
102115 private _autoClosingTags : Set < string > ;
@@ -108,15 +121,15 @@ export class InjectedScript {
108121 private _allHitTargetInterceptorEvents : Set < string > ;
109122
110123 // eslint-disable-next-line no-restricted-globals
111- constructor ( window : Window & typeof globalThis , isUnderTest : boolean , sdkLanguage : Language , testIdAttributeNameForStrictErrorAndConsoleCodegen : string , stableRafCount : number , browserName : string , inputFileRoleTextbox : boolean , customEngines : { name : string , engine : SelectorEngine } [ ] ) {
124+ constructor ( window : Window & typeof globalThis , options : InjectedScriptOptions ) {
112125 this . window = window ;
113126 this . document = window . document ;
114- this . isUnderTest = isUnderTest ;
127+ this . isUnderTest = options . isUnderTest ;
115128 // Make sure builtins are created from "window". This is important for InjectedScript instantiated
116129 // inside a trace viewer snapshot, where "window" differs from "globalThis".
117- this . utils . builtins = builtins ( window ) ;
118- this . _sdkLanguage = sdkLanguage ;
119- this . _testIdAttributeNameForStrictErrorAndConsoleCodegen = testIdAttributeNameForStrictErrorAndConsoleCodegen ;
130+ this . utils . builtins = builtins ( options . runtimeGuid , window ) ;
131+ this . _sdkLanguage = options . sdkLanguage ;
132+ this . _testIdAttributeNameForStrictErrorAndConsoleCodegen = options . testIdAttributeName ;
120133 this . _evaluator = new SelectorEvaluatorImpl ( ) ;
121134 this . consoleApi = new ConsoleAPI ( this ) ;
122135
@@ -216,17 +229,17 @@ export class InjectedScript {
216229 this . _engines . set ( 'internal:role' , createRoleEngine ( true ) ) ;
217230 this . _engines . set ( 'aria-ref' , this . _createAriaIdEngine ( ) ) ;
218231
219- for ( const { name, engine } of customEngines )
220- this . _engines . set ( name , engine ) ;
232+ for ( const { name, source } of options . customEngines )
233+ this . _engines . set ( name , this . eval ( source ) ) ;
221234
222- this . _stableRafCount = stableRafCount ;
223- this . _browserName = browserName ;
224- setGlobalOptions ( { browserNameForWorkarounds : browserName , inputFileRoleTextbox } ) ;
235+ this . _stableRafCount = options . stableRafCount ;
236+ this . _browserName = options . browserName ;
237+ setGlobalOptions ( { browserNameForWorkarounds : options . browserName , inputFileRoleTextbox : options . inputFileRoleTextbox } ) ;
225238
226239 this . _setupGlobalListenersRemovalDetection ( ) ;
227240 this . _setupHitTargetInterceptors ( ) ;
228241
229- if ( isUnderTest )
242+ if ( options . isUnderTest )
230243 ( this . window as any ) . __injectedScript = this ;
231244 }
232245
0 commit comments