@@ -266,7 +266,7 @@ define(function (require, exports, module) {
266266 async function _waitForIframeURL ( url ) {
267267 await awaitsFor ( ( ) => {
268268 let iFrame = testWindow . document . getElementById ( "panel-live-preview-frame" ) ;
269- return iFrame . src === url ;
269+ return iFrame && iFrame . src === url ;
270270 } , "external preview server " + url ) ;
271271 }
272272
@@ -494,8 +494,13 @@ define(function (require, exports, module) {
494494 await awaitsForDone ( SpecRunnerUtils . openProjectFiles ( [ "readme.md" ] ) ,
495495 "readme.md" ) ;
496496 await awaitsFor ( ( ) => {
497- let iFrame = testWindow . document . getElementById ( "panel-live-preview-frame" ) ;
498- return iFrame . src . endsWith ( "readme.md" ) ;
497+ let mdIFrame = testWindow . document . getElementById ( "panel-md-preview-frame" ) ;
498+ if ( ! mdIFrame || ! mdIFrame . contentWindow ) { return false ; }
499+ try {
500+ const activeFile = mdIFrame . contentWindow . __getActiveFilePath
501+ && mdIFrame . contentWindow . __getActiveFilePath ( ) ;
502+ return activeFile && activeFile . endsWith ( "readme.md" ) ;
503+ } catch ( e ) { return false ; }
499504 } , "readme.md live preview" ) ;
500505
501506 // now do html, it should load from the custom server
@@ -663,7 +668,7 @@ define(function (require, exports, module) {
663668 testWindow . $ ( "#toolbar-go-live" ) . click ( ) ;
664669 await awaitsFor ( ( ) => {
665670 let iFrame = testWindow . document . getElementById ( "panel-live-preview-frame" ) ;
666- if ( ! iFrame . src ) {
671+ if ( ! iFrame || ! iFrame . src ) {
667672 return false ;
668673 }
669674 const url = new URL ( iFrame . src ) ;
@@ -774,6 +779,7 @@ define(function (require, exports, module) {
774779 async function _forSVGLivePreview ( ) {
775780 await awaitsFor ( ( ) => {
776781 let iFrame = testWindow . document . getElementById ( "panel-live-preview-frame" ) ;
782+ if ( ! iFrame || ! iFrame . src ) { return false ; }
777783 let srcURL = new URL ( iFrame . src ) ;
778784 return srcURL . pathname . endsWith ( SVG_IMAGE_PATH ) ;
779785 } , "For svg image to be in live preview" ) ;
@@ -803,11 +809,22 @@ define(function (require, exports, module) {
803809 } , 30000 ) ;
804810
805811 async function _waitForIframeMDFile ( name ) {
812+ // The mdviewer uses a persistent iframe (panel-md-preview-frame) that loads mdViewer/index.html.
813+ // Content is sent via postMessage, so we verify by checking the active file path inside the iframe.
806814 await awaitsFor ( ( ) => {
807- let outerIFrame = testWindow . document . getElementById ( "panel-live-preview-frame" ) ;
808- let srcURL = new URL ( outerIFrame . src ) ;
809- return srcURL . pathname . endsWith ( name ) === true ;
810- } , "waiting for name- " + name ) ;
815+ let mdIFrame = testWindow . document . getElementById ( "panel-md-preview-frame" ) ;
816+ if ( ! mdIFrame || ! mdIFrame . contentWindow ) {
817+ return false ;
818+ }
819+ try {
820+ // doc-cache.js exposes activeFilePath — check it ends with the expected name
821+ const activeFile = mdIFrame . contentWindow . __getActiveFilePath
822+ && mdIFrame . contentWindow . __getActiveFilePath ( ) ;
823+ return activeFile && activeFile . endsWith ( name ) ;
824+ } catch ( e ) {
825+ return false ;
826+ }
827+ } , "waiting for md file: " + name ) ;
811828 }
812829
813830 it ( "should pin live previews pin markdown file" , async function ( ) {
0 commit comments