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 ) => {
@@ -254,7 +254,9 @@ declare global {
254254
255255function snapshotScript ( viewport : ViewportSize , ...targetIds : ( string | undefined ) [ ] ) {
256256 function applyPlaywrightAttributes ( viewport : ViewportSize , ...targetIds : ( string | undefined ) [ ] ) {
257- const searchParams = new URLSearchParams ( location . search ) ;
257+ // eslint-disable-next-line no-restricted-globals
258+ const win = window ;
259+ const searchParams = new URLSearchParams ( win . location . search ) ;
258260 const shouldPopulateCanvasFromScreenshot = searchParams . has ( 'shouldPopulateCanvasFromScreenshot' ) ;
259261 const isUnderTest = searchParams . has ( 'isUnderTest' ) ;
260262
@@ -268,7 +270,7 @@ function snapshotScript(viewport: ViewportSize, ...targetIds: (string | undefine
268270 viewport,
269271 frames : new WeakMap ( ) ,
270272 } ;
271- window [ '__playwright_frame_bounding_rects__' ] = frameBoundingRectsInfo ;
273+ win [ '__playwright_frame_bounding_rects__' ] = frameBoundingRectsInfo ;
272274
273275 const kPointerWarningTitle = 'Recorded click position in absolute coordinates did not' +
274276 ' match the center of the clicked element. This is likely due to a difference between' +
@@ -279,7 +281,7 @@ function snapshotScript(viewport: ViewportSize, ...targetIds: (string | undefine
279281 const targetElements : Element [ ] = [ ] ;
280282 const canvasElements : HTMLCanvasElement [ ] = [ ] ;
281283
282- let topSnapshotWindow : Window = window ;
284+ let topSnapshotWindow : Window = win ;
283285 while ( topSnapshotWindow !== topSnapshotWindow . parent && ! topSnapshotWindow . location . pathname . match ( / \/ p a g e @ [ a - z 0 - 9 ] + $ / ) )
284286 topSnapshotWindow = topSnapshotWindow . parent ;
285287
@@ -342,7 +344,7 @@ function snapshotScript(viewport: ViewportSize, ...targetIds: (string | undefine
342344 iframe . setAttribute ( 'src' , 'data:text/html,<body style="background: #ddd"></body>' ) ;
343345 } else {
344346 // Retain query parameters to inherit name=, time=, pointX=, pointY= and other values from parent.
345- const url = new URL ( window . location . href ) ;
347+ const url = new URL ( win . location . href ) ;
346348 // We can be loading iframe from within iframe, reset base to be absolute.
347349 const index = url . pathname . lastIndexOf ( '/snapshot/' ) ;
348350 if ( index !== - 1 )
@@ -354,10 +356,10 @@ function snapshotScript(viewport: ViewportSize, ...targetIds: (string | undefine
354356
355357 {
356358 const body = root . querySelector ( `body[__playwright_custom_elements__]` ) ;
357- if ( body && window . customElements ) {
359+ if ( body && win . customElements ) {
358360 const customElements = ( body . getAttribute ( '__playwright_custom_elements__' ) || '' ) . split ( ',' ) ;
359361 for ( const elementName of customElements )
360- window . customElements . define ( elementName , class extends HTMLElement { } ) ;
362+ win . customElements . define ( elementName , class extends HTMLElement { } ) ;
361363 }
362364 }
363365
@@ -387,7 +389,7 @@ function snapshotScript(viewport: ViewportSize, ...targetIds: (string | undefine
387389 } ;
388390
389391 const onLoad = ( ) => {
390- window . removeEventListener ( 'load' , onLoad ) ;
392+ win . removeEventListener ( 'load' , onLoad ) ;
391393 for ( const element of scrollTops ) {
392394 element . scrollTop = + element . getAttribute ( '__playwright_scroll_top_' ) ! ;
393395 element . removeAttribute ( '__playwright_scroll_top_' ) ;
@@ -401,19 +403,19 @@ function snapshotScript(viewport: ViewportSize, ...targetIds: (string | undefine
401403 frameBoundingRectsInfo . frames . get ( element ) ! . scrollLeft = element . scrollTop ;
402404 }
403405
404- document . styleSheets [ 0 ] . disabled = true ;
406+ win . document . styleSheets [ 0 ] . disabled = true ;
405407
406- const search = new URL ( window . location . href ) . searchParams ;
407- const isTopFrame = window === topSnapshotWindow ;
408+ const search = new URL ( win . location . href ) . searchParams ;
409+ const isTopFrame = win === topSnapshotWindow ;
408410
409411 if ( search . get ( 'pointX' ) && search . get ( 'pointY' ) ) {
410412 const pointX = + search . get ( 'pointX' ) ! ;
411413 const pointY = + search . get ( 'pointY' ) ! ;
412414 const hasInputTarget = search . has ( 'hasInputTarget' ) ;
413415 const hasTargetElements = targetElements . length > 0 ;
414- const roots = document . documentElement ? [ document . documentElement ] : [ ] ;
416+ const roots = win . document . documentElement ? [ win . document . documentElement ] : [ ] ;
415417 for ( const target of ( hasTargetElements ? targetElements : roots ) ) {
416- const pointElement = document . createElement ( 'x-pw-pointer' ) ;
418+ const pointElement = win . document . createElement ( 'x-pw-pointer' ) ;
417419 pointElement . style . position = 'fixed' ;
418420 pointElement . style . backgroundColor = '#f44336' ;
419421 pointElement . style . width = '20px' ;
@@ -436,7 +438,7 @@ function snapshotScript(viewport: ViewportSize, ...targetIds: (string | undefine
436438 // "Warning symbol" indicates that action point is not 100% correct.
437439 // Note that action point is relative to the top frame, so we can only compare in the top frame.
438440 if ( isTopFrame && ( Math . abs ( centerX - pointX ) >= 10 || Math . abs ( centerY - pointY ) >= 10 ) ) {
439- const warningElement = document . createElement ( 'x-pw-pointer-warning' ) ;
441+ const warningElement = win . document . createElement ( 'x-pw-pointer-warning' ) ;
440442 warningElement . textContent = '⚠' ;
441443 warningElement . style . fontSize = '19px' ;
442444 warningElement . style . color = 'white' ;
@@ -445,21 +447,21 @@ function snapshotScript(viewport: ViewportSize, ...targetIds: (string | undefine
445447 pointElement . appendChild ( warningElement ) ;
446448 pointElement . setAttribute ( 'title' , kPointerWarningTitle ) ;
447449 }
448- document . documentElement . appendChild ( pointElement ) ;
450+ win . document . documentElement . appendChild ( pointElement ) ;
449451 } else if ( isTopFrame && ! hasInputTarget ) {
450452 // For actions without a target element, e.g. page.mouse.move(),
451453 // show the point at the recorded location, which is relative to the top frame.
452454 pointElement . style . left = pointX + 'px' ;
453455 pointElement . style . top = pointY + 'px' ;
454- document . documentElement . appendChild ( pointElement ) ;
456+ win . document . documentElement . appendChild ( pointElement ) ;
455457 }
456458 }
457459 }
458460
459461 if ( canvasElements . length > 0 ) {
460462 function drawCheckerboard ( context : CanvasRenderingContext2D , canvas : HTMLCanvasElement ) {
461463 function createCheckerboardPattern ( ) {
462- const pattern = document . createElement ( 'canvas' ) ;
464+ const pattern = win . document . createElement ( 'canvas' ) ;
463465 pattern . width = pattern . width / Math . floor ( pattern . width / 24 ) ;
464466 pattern . height = pattern . height / Math . floor ( pattern . height / 24 ) ;
465467 const context = pattern . getContext ( '2d' ) ! ;
@@ -492,7 +494,7 @@ function snapshotScript(viewport: ViewportSize, ...targetIds: (string | undefine
492494 continue ;
493495 }
494496
495- let currWindow : Window = window ;
497+ let currWindow : Window = win ;
496498 while ( currWindow !== topSnapshotWindow ) {
497499 const iframe = currWindow . frameElement ! ;
498500 currWindow = currWindow . parent ;
@@ -553,10 +555,10 @@ function snapshotScript(viewport: ViewportSize, ...targetIds: (string | undefine
553555 }
554556 } ;
555557
556- const onDOMContentLoaded = ( ) => visit ( document ) ;
558+ const onDOMContentLoaded = ( ) => visit ( win . document ) ;
557559
558- window . addEventListener ( 'load' , onLoad ) ;
559- window . addEventListener ( 'DOMContentLoaded' , onDOMContentLoaded ) ;
560+ win . addEventListener ( 'load' , onLoad ) ;
561+ win . addEventListener ( 'DOMContentLoaded' , onDOMContentLoaded ) ;
560562 }
561563
562564 return `\n(${ applyPlaywrightAttributes . toString ( ) } )(${ JSON . stringify ( viewport ) } ${ targetIds . map ( id => `, "${ id } "` ) . join ( '' ) } )` ;
0 commit comments