@@ -29,11 +29,12 @@ import type { CSSComplexSelectorList } from '../../utils/isomorphic/cssParser';
29
29
import { generateSelector , type GenerateSelectorOptions } from './selectorGenerator' ;
30
30
import type * as channels from '@protocol/channels' ;
31
31
import { Highlight } from './highlight' ;
32
- import { getChecked , getAriaDisabled , getAriaRole , getElementAccessibleName , getElementAccessibleDescription } from './roleUtils' ;
32
+ import { getChecked , getAriaDisabled , getAriaRole , getElementAccessibleName , getElementAccessibleDescription , beginAriaCaches , endAriaCaches } from './roleUtils' ;
33
33
import { kLayoutSelectorNames , type LayoutSelectorName , layoutSelectorScore } from './layoutSelectorUtils' ;
34
34
import { asLocator } from '../../utils/isomorphic/locatorGenerators' ;
35
35
import type { Language } from '../../utils/isomorphic/locatorGenerators' ;
36
- import { cacheNormalizedWhitespaces , normalizeWhiteSpace , trimStringWithEllipsis } from '../../utils/isomorphic/stringUtils' ;
36
+ import { cacheNormalizedWhitespaces , escapeHTML , escapeHTMLAttribute , normalizeWhiteSpace , trimStringWithEllipsis } from '../../utils/isomorphic/stringUtils' ;
37
+ import { generateSimpleDom , generateSimpleDomNode , selectorForSimpleDomNodeId } from './simpleDom' ;
37
38
38
39
export type FrameExpectParams = Omit < channels . FrameExpectParams , 'expectedValue' > & { expectedValue ?: any } ;
39
40
@@ -66,7 +67,28 @@ export class InjectedScript {
66
67
// eslint-disable-next-line no-restricted-globals
67
68
readonly window : Window & typeof globalThis ;
68
69
readonly document : Document ;
69
- readonly utils = { isInsideScope, elementText, asLocator, normalizeWhiteSpace, cacheNormalizedWhitespaces } ;
70
+
71
+ // Recorder must use any external dependencies through InjectedScript.
72
+ // Otherwise it will end up with a copy of all modules it uses, and any
73
+ // module-level globals will be duplicated, which leads to subtle bugs.
74
+ readonly utils = {
75
+ asLocator,
76
+ beginAriaCaches,
77
+ cacheNormalizedWhitespaces,
78
+ elementText,
79
+ endAriaCaches,
80
+ escapeHTML,
81
+ escapeHTMLAttribute,
82
+ generateSimpleDom : generateSimpleDom . bind ( undefined , this ) ,
83
+ generateSimpleDomNode : generateSimpleDomNode . bind ( undefined , this ) ,
84
+ getAriaRole,
85
+ getElementAccessibleDescription,
86
+ getElementAccessibleName,
87
+ isElementVisible,
88
+ isInsideScope,
89
+ normalizeWhiteSpace,
90
+ selectorForSimpleDomNodeId : selectorForSimpleDomNodeId . bind ( undefined , this ) ,
91
+ } ;
70
92
71
93
// eslint-disable-next-line no-restricted-globals
72
94
constructor ( window : Window & typeof globalThis , isUnderTest : boolean , sdkLanguage : Language , testIdAttributeNameForStrictErrorAndConsoleCodegen : string , stableRafCount : number , browserName : string , customEngines : { name : string , engine : SelectorEngine } [ ] ) {
@@ -426,10 +448,6 @@ export class InjectedScript {
426
448
return new constrFunction ( this , params ) ;
427
449
}
428
450
429
- isVisible ( element : Element ) : boolean {
430
- return isElementVisible ( element ) ;
431
- }
432
-
433
451
async viewportRatio ( element : Element ) : Promise < number > {
434
452
return await new Promise ( resolve => {
435
453
const observer = new IntersectionObserver ( entries => {
@@ -567,9 +585,9 @@ export class InjectedScript {
567
585
}
568
586
569
587
if ( state === 'visible' )
570
- return this . isVisible ( element ) ;
588
+ return isElementVisible ( element ) ;
571
589
if ( state === 'hidden' )
572
- return ! this . isVisible ( element ) ;
590
+ return ! isElementVisible ( element ) ;
573
591
574
592
const disabled = getAriaDisabled ( element ) ;
575
593
if ( state === 'disabled' )
@@ -1296,18 +1314,6 @@ export class InjectedScript {
1296
1314
}
1297
1315
throw this . createStacklessError ( 'Unknown expect matcher: ' + expression ) ;
1298
1316
}
1299
-
1300
- getElementAccessibleName ( element : Element , includeHidden ?: boolean ) : string {
1301
- return getElementAccessibleName ( element , ! ! includeHidden ) ;
1302
- }
1303
-
1304
- getElementAccessibleDescription ( element : Element , includeHidden ?: boolean ) : string {
1305
- return getElementAccessibleDescription ( element , ! ! includeHidden ) ;
1306
- }
1307
-
1308
- getAriaRole ( element : Element ) {
1309
- return getAriaRole ( element ) ;
1310
- }
1311
1317
}
1312
1318
1313
1319
const autoClosingTags = new Set ( [ 'AREA' , 'BASE' , 'BR' , 'COL' , 'COMMAND' , 'EMBED' , 'HR' , 'IMG' , 'INPUT' , 'KEYGEN' , 'LINK' , 'MENUITEM' , 'META' , 'PARAM' , 'SOURCE' , 'TRACK' , 'WBR' ] ) ;
0 commit comments