@@ -112,8 +112,11 @@ export function isAncestor(
112
112
return false ;
113
113
}
114
114
115
- export function getElementsByTagName ( tag : string ) : HTMLElement [ ] {
116
- return Array . prototype . slice . call ( document . getElementsByTagName ( tag ) , 0 ) ;
115
+ export function getElementsByTagName (
116
+ tag : string ,
117
+ document : ParentNode
118
+ ) : HTMLElement [ ] {
119
+ return Array . prototype . slice . call ( document . querySelectorAll ( tag ) , 0 ) ;
117
120
}
118
121
119
122
export interface IFocusTracker extends IDisposable {
@@ -288,10 +291,29 @@ export function addTestId(element: HTMLElement, id: string): void {
288
291
element . setAttribute ( 'data-testid' , id ) ;
289
292
}
290
293
291
- export function disableIframePointEvents ( ) {
294
+ export function disableIframePointEvents ( rootNode : ParentNode = document ) {
295
+ const includeShadowDom = true ;
296
+
297
+ const shadowRoots = [ ] ;
298
+
299
+ if ( includeShadowDom ) {
300
+ const items = rootNode . querySelectorAll ( '*' ) ;
301
+
302
+ for ( let i = 0 ; i < items . length ; i ++ ) {
303
+ const item = items [ i ] ;
304
+ if ( item . shadowRoot ) {
305
+ shadowRoots . push ( item . shadowRoot ) ;
306
+ }
307
+ }
308
+ }
309
+
292
310
const iframes : HTMLElement [ ] = [
293
- ...getElementsByTagName ( 'iframe' ) ,
294
- ...getElementsByTagName ( 'webview' ) ,
311
+ ...getElementsByTagName ( 'iframe' , rootNode ) ,
312
+ ...getElementsByTagName ( 'webview' , rootNode ) ,
313
+ ...shadowRoots . flatMap ( ( root ) => [
314
+ ...getElementsByTagName ( 'iframe' , root ) ,
315
+ ...getElementsByTagName ( 'webview' , root ) ,
316
+ ] ) ,
295
317
] ;
296
318
297
319
const original = new WeakMap < HTMLElement , string > ( ) ; // don't hold onto HTMLElement references longer than required
0 commit comments