1414 * limitations under the License.
1515 */
1616
17- import { escapeHTMLAttribute , escapeHTML } from '@isomorphic /stringUtils' ;
17+ import { escapeHTMLAttribute , escapeHTML } from '.. /stringUtils' ;
1818
1919import type { FrameSnapshot , NodeNameAttributesChildNodesSnapshot , NodeSnapshot , RenderedFrameSnapshot , ResourceSnapshot , SubtreeReferenceSnapshot } from '@trace/snapshot' ;
20- import type { PageEntry } from '../types /entries' ;
21- import type { LRUCache } from './lruCache' ;
20+ import type { PageEntry } from './entries' ;
21+ import type { LRUCache } from '.. /lruCache' ;
2222
2323function findClosest < T > ( items : T [ ] , metric : ( v : T ) => number , target : number ) {
2424 return items . find ( ( item , index ) => {
@@ -256,7 +256,9 @@ declare global {
256256
257257function snapshotScript ( viewport : ViewportSize , ...targetIds : ( string | undefined ) [ ] ) {
258258 function applyPlaywrightAttributes ( viewport : ViewportSize , ...targetIds : ( string | undefined ) [ ] ) {
259- const searchParams = new URLSearchParams ( location . search ) ;
259+ // eslint-disable-next-line no-restricted-globals
260+ const win = window ;
261+ const searchParams = new URLSearchParams ( win . location . search ) ;
260262 const shouldPopulateCanvasFromScreenshot = searchParams . has ( 'shouldPopulateCanvasFromScreenshot' ) ;
261263 const isUnderTest = searchParams . has ( 'isUnderTest' ) ;
262264
@@ -270,7 +272,7 @@ function snapshotScript(viewport: ViewportSize, ...targetIds: (string | undefine
270272 viewport,
271273 frames : new WeakMap ( ) ,
272274 } ;
273- window [ '__playwright_frame_bounding_rects__' ] = frameBoundingRectsInfo ;
275+ win [ '__playwright_frame_bounding_rects__' ] = frameBoundingRectsInfo ;
274276
275277 const kPointerWarningTitle = 'Recorded click position in absolute coordinates did not' +
276278 ' match the center of the clicked element. This is likely due to a difference between' +
@@ -281,7 +283,7 @@ function snapshotScript(viewport: ViewportSize, ...targetIds: (string | undefine
281283 const targetElements : Element [ ] = [ ] ;
282284 const canvasElements : HTMLCanvasElement [ ] = [ ] ;
283285
284- let topSnapshotWindow : Window = window ;
286+ let topSnapshotWindow : Window = win ;
285287 while ( topSnapshotWindow !== topSnapshotWindow . parent && ! topSnapshotWindow . location . pathname . match ( / \/ p a g e @ [ a - z 0 - 9 ] + $ / ) )
286288 topSnapshotWindow = topSnapshotWindow . parent ;
287289
@@ -344,7 +346,7 @@ function snapshotScript(viewport: ViewportSize, ...targetIds: (string | undefine
344346 iframe . setAttribute ( 'src' , 'data:text/html,<body style="background: #ddd"></body>' ) ;
345347 } else {
346348 // Retain query parameters to inherit name=, time=, pointX=, pointY= and other values from parent.
347- const url = new URL ( window . location . href ) ;
349+ const url = new URL ( win . location . href ) ;
348350 // We can be loading iframe from within iframe, reset base to be absolute.
349351 const index = url . pathname . lastIndexOf ( '/snapshot/' ) ;
350352 if ( index !== - 1 )
@@ -356,10 +358,10 @@ function snapshotScript(viewport: ViewportSize, ...targetIds: (string | undefine
356358
357359 {
358360 const body = root . querySelector ( `body[__playwright_custom_elements__]` ) ;
359- if ( body && window . customElements ) {
361+ if ( body && win . customElements ) {
360362 const customElements = ( body . getAttribute ( '__playwright_custom_elements__' ) || '' ) . split ( ',' ) ;
361363 for ( const elementName of customElements )
362- window . customElements . define ( elementName , class extends HTMLElement { } ) ;
364+ win . customElements . define ( elementName , class extends HTMLElement { } ) ;
363365 }
364366 }
365367
@@ -391,7 +393,7 @@ function snapshotScript(viewport: ViewportSize, ...targetIds: (string | undefine
391393 } ;
392394
393395 const onLoad = ( ) => {
394- window . removeEventListener ( 'load' , onLoad ) ;
396+ win . removeEventListener ( 'load' , onLoad ) ;
395397 for ( const element of scrollTops ) {
396398 element . scrollTop = + element . getAttribute ( '__playwright_scroll_top_' ) ! ;
397399 element . removeAttribute ( '__playwright_scroll_top_' ) ;
@@ -405,19 +407,19 @@ function snapshotScript(viewport: ViewportSize, ...targetIds: (string | undefine
405407 frameBoundingRectsInfo . frames . get ( element ) ! . scrollLeft = element . scrollTop ;
406408 }
407409
408- document . styleSheets [ 0 ] . disabled = true ;
410+ win . document . styleSheets [ 0 ] . disabled = true ;
409411
410- const search = new URL ( window . location . href ) . searchParams ;
411- const isTopFrame = window === topSnapshotWindow ;
412+ const search = new URL ( win . location . href ) . searchParams ;
413+ const isTopFrame = win === topSnapshotWindow ;
412414
413415 if ( search . get ( 'pointX' ) && search . get ( 'pointY' ) ) {
414416 const pointX = + search . get ( 'pointX' ) ! ;
415417 const pointY = + search . get ( 'pointY' ) ! ;
416418 const hasInputTarget = search . has ( 'hasInputTarget' ) ;
417419 const hasTargetElements = targetElements . length > 0 ;
418- const roots = document . documentElement ? [ document . documentElement ] : [ ] ;
420+ const roots = win . document . documentElement ? [ win . document . documentElement ] : [ ] ;
419421 for ( const target of ( hasTargetElements ? targetElements : roots ) ) {
420- const pointElement = document . createElement ( 'x-pw-pointer' ) ;
422+ const pointElement = win . document . createElement ( 'x-pw-pointer' ) ;
421423 pointElement . style . position = 'fixed' ;
422424 pointElement . style . backgroundColor = '#f44336' ;
423425 pointElement . style . width = '20px' ;
@@ -440,7 +442,7 @@ function snapshotScript(viewport: ViewportSize, ...targetIds: (string | undefine
440442 // "Warning symbol" indicates that action point is not 100% correct.
441443 // Note that action point is relative to the top frame, so we can only compare in the top frame.
442444 if ( isTopFrame && ( Math . abs ( centerX - pointX ) >= 10 || Math . abs ( centerY - pointY ) >= 10 ) ) {
443- const warningElement = document . createElement ( 'x-pw-pointer-warning' ) ;
445+ const warningElement = win . document . createElement ( 'x-pw-pointer-warning' ) ;
444446 warningElement . textContent = '⚠' ;
445447 warningElement . style . fontSize = '19px' ;
446448 warningElement . style . color = 'white' ;
@@ -449,21 +451,21 @@ function snapshotScript(viewport: ViewportSize, ...targetIds: (string | undefine
449451 pointElement . appendChild ( warningElement ) ;
450452 pointElement . setAttribute ( 'title' , kPointerWarningTitle ) ;
451453 }
452- document . documentElement . appendChild ( pointElement ) ;
454+ win . document . documentElement . appendChild ( pointElement ) ;
453455 } else if ( isTopFrame && ! hasInputTarget ) {
454456 // For actions without a target element, e.g. page.mouse.move(),
455457 // show the point at the recorded location, which is relative to the top frame.
456458 pointElement . style . left = pointX + 'px' ;
457459 pointElement . style . top = pointY + 'px' ;
458- document . documentElement . appendChild ( pointElement ) ;
460+ win . document . documentElement . appendChild ( pointElement ) ;
459461 }
460462 }
461463 }
462464
463465 if ( canvasElements . length > 0 ) {
464466 function drawCheckerboard ( context : CanvasRenderingContext2D , canvas : HTMLCanvasElement ) {
465467 function createCheckerboardPattern ( ) {
466- const pattern = document . createElement ( 'canvas' ) ;
468+ const pattern = win . document . createElement ( 'canvas' ) ;
467469 pattern . width = pattern . width / Math . floor ( pattern . width / 24 ) ;
468470 pattern . height = pattern . height / Math . floor ( pattern . height / 24 ) ;
469471 const context = pattern . getContext ( '2d' ) ! ;
@@ -496,7 +498,7 @@ function snapshotScript(viewport: ViewportSize, ...targetIds: (string | undefine
496498 continue ;
497499 }
498500
499- let currWindow : Window = window ;
501+ let currWindow : Window = win ;
500502 while ( currWindow !== topSnapshotWindow ) {
501503 const iframe = currWindow . frameElement ! ;
502504 currWindow = currWindow . parent ;
@@ -557,10 +559,10 @@ function snapshotScript(viewport: ViewportSize, ...targetIds: (string | undefine
557559 }
558560 } ;
559561
560- const onDOMContentLoaded = ( ) => visit ( document ) ;
562+ const onDOMContentLoaded = ( ) => visit ( win . document ) ;
561563
562- window . addEventListener ( 'load' , onLoad ) ;
563- window . addEventListener ( 'DOMContentLoaded' , onDOMContentLoaded ) ;
564+ win . addEventListener ( 'load' , onLoad ) ;
565+ win . addEventListener ( 'DOMContentLoaded' , onDOMContentLoaded ) ;
564566 }
565567
566568 return `\n(${ applyPlaywrightAttributes . toString ( ) } )(${ JSON . stringify ( viewport ) } ${ targetIds . map ( id => `, "${ id } "` ) . join ( '' ) } )` ;
0 commit comments