@@ -54,8 +54,12 @@ function installBrowserDomParserShim() {
5454 if ( ! element || ! $ ( element ) . parent ( ) . length ) {
5555 return null ;
5656 }
57+ const parentElement = $ ( element ) . parent ( ) [ 0 ] ;
5758 return {
5859 insertBefore ( child , reference ) {
60+ if ( $ ( reference . cheerioElement ) . parent ( ) [ 0 ] !== parentElement ) {
61+ throw new Error ( 'NotFoundError' ) ;
62+ }
5963 $ ( reference . cheerioElement ) . before ( child . cheerioElement ) ;
6064 } ,
6165 } ;
@@ -405,18 +409,22 @@ describe('HTML Visibility Analyzer', () => {
405409 expect ( text ) . to . not . include ( 'Play Pause' ) ;
406410 } ) ;
407411
408- it ( 'should remove Google Maps widget container (.gm-style) and its label text' , async ( ) => {
412+ it ( 'should preserve InfoWindow content while removing Google Maps runtime text' , async ( ) => {
409413 const html = `<html><body>
410414 <h1>Estaciones de servicio</h1>
411415 <p>Encuentra tu estación más cercana.</p>
412416 <div id="map-container">
413417 <div class="gm-style">
414418 <div class="gm-style-iw">
419+ <div class="gm-style-iw-chr">
420+ <div class="gm-style-iw-ch">Estación Repsol Centro</div>
421+ <button aria-label="Close">Close window</button>
422+ </div>
415423 <div class="gm-style-iw-d">
416- <h2>Estación Repsol Centro</h2>
417424 <p>Calle Mayor 1, Madrid</p>
418425 </div>
419426 </div>
427+ <div class="gm-style-iw">Legacy InfoWindow: Sevilla office.</div>
420428 <div class="gm-bundled-control">
421429 <div class="gmnoprint">
422430 <div class="gm-svpc">Pegman</div>
@@ -437,6 +445,8 @@ describe('HTML Visibility Analyzer', () => {
437445 expect ( text ) . to . include ( 'Horario' ) ;
438446 expect ( text ) . to . include ( 'Estación Repsol Centro' ) ;
439447 expect ( text ) . to . include ( 'Calle Mayor 1, Madrid' ) ;
448+ expect ( text ) . to . include ( 'Legacy InfoWindow: Sevilla office.' ) ;
449+ expect ( text ) . to . not . include ( 'Close window' ) ;
440450 expect ( text ) . to . not . include ( 'Map data' ) ;
441451 expect ( text ) . to . not . include ( 'Pegman' ) ;
442452 expect ( text ) . to . not . include ( '40.4168' ) ;
@@ -540,6 +550,11 @@ describe('HTML Visibility Analyzer', () => {
540550 <div>Sorry, we have no imagery here.</div>
541551 <div class="gm-style-cc">Map Data Terms</div>
542552 <div class="gm-style-iw">Open Madrid location details.</div>
553+ <div class="gm-style-iw">
554+ <div class="gm-style-iw-ch">Barcelona office.</div>
555+ <div class="gm-style-iw-d">Carrer de Mallorca 1.</div>
556+ <button>Close window</button>
557+ </div>
543558 </div>
544559 <gmp-map>
545560 <gmp-advanced-marker>Customer-authored marker details.</gmp-advanced-marker>
@@ -552,7 +567,10 @@ describe('HTML Visibility Analyzer', () => {
552567 expect ( text ) . to . include ( 'Office locations' ) ;
553568 expect ( text ) . to . include ( 'Real office content.' ) ;
554569 expect ( text ) . to . include ( 'Open Madrid location details.' ) ;
570+ expect ( text ) . to . include ( 'Barcelona office.' ) ;
571+ expect ( text ) . to . include ( 'Carrer de Mallorca 1.' ) ;
555572 expect ( text ) . to . include ( 'Customer-authored marker details.' ) ;
573+ expect ( text ) . to . not . include ( 'Close window' ) ;
556574 expect ( text ) . to . not . include ( 'Sorry, we have no imagery here' ) ;
557575 expect ( text ) . to . not . include ( 'Map Data' ) ;
558576 } finally {
@@ -619,13 +637,21 @@ describe('HTML Visibility Analyzer', () => {
619637 <div class="gm-style">
620638 <div>Sorry, we have no imagery here.</div>
621639 <div class="gm-style-cc">Map data ©2026 Google</div>
640+ <div class="gm-style-iw">
641+ <div class="gm-style-iw-ch">Madrid office.</div>
642+ <div class="gm-style-iw-d">Calle Mayor 1.</div>
643+ <button>Close window</button>
644+ </div>
622645 </div>
623646 <p>Madrid office details.</p>
624647 </body></html>` ;
625648
626649 const { currentRenderedHtml } = await generateMarkdownDiff ( serverHtml , clientHtml , false ) ;
627650
628651 expect ( currentRenderedHtml ) . to . include ( 'Madrid office details.' ) ;
652+ expect ( currentRenderedHtml ) . to . include ( 'Madrid office.' ) ;
653+ expect ( currentRenderedHtml ) . to . include ( 'Calle Mayor 1.' ) ;
654+ expect ( currentRenderedHtml ) . to . not . include ( 'Close window' ) ;
629655 expect ( currentRenderedHtml ) . to . not . include ( 'Sorry, we have no imagery here.' ) ;
630656 expect ( currentRenderedHtml ) . to . not . include ( 'Map data' ) ;
631657 } ) ;
0 commit comments