@@ -156,42 +156,18 @@ export class MarkdownPreview {
156156 return false ;
157157 }
158158
159+ const blob = new Blob ( [ code ] , { type : 'text/html' } ) ;
160+ const blobUrl = URL . createObjectURL ( blob ) ;
161+
159162 const iframe = document . createElement ( 'iframe' ) ;
160163 iframe . className = 'html-preview-frame' ;
161164 iframe . sandbox = 'allow-scripts allow-same-origin' ;
162- iframe . srcdoc = code ;
165+ iframe . src = blobUrl ;
163166 slot . appendChild ( iframe ) ;
164167
165- // Catch errors from the iframe (works for same-origin srcdoc scripts)
166168 iframe . addEventListener ( 'load' , ( ) => {
169+ URL . revokeObjectURL ( blobUrl ) ;
167170 iframe . classList . add ( 'loaded' ) ;
168- try {
169- const win = iframe . contentWindow ;
170- if ( ! win ) return ;
171- const errors = [ ] ;
172- win . addEventListener ( 'error' , ( ev ) => {
173- errors . push ( {
174- message : ev . message || 'Unknown error' ,
175- filename : ev . filename || '' ,
176- lineno : ev . lineno || 0 ,
177- colno : ev . colno || 0 ,
178- stack : ( ev . error && ev . error . stack ) || '' ,
179- } ) ;
180- this . _renderIframeErrors ( iframe , errors ) ;
181- } ) ;
182- win . addEventListener ( 'unhandledrejection' , ( ev ) => {
183- errors . push ( {
184- message : 'Unhandled rejection: ' + String ( ev . reason ) ,
185- filename : '' ,
186- lineno : 0 ,
187- colno : 0 ,
188- stack : ( ev . reason && ev . reason . stack ) || '' ,
189- } ) ;
190- this . _renderIframeErrors ( iframe , errors ) ;
191- } ) ;
192- } catch {
193- // Cross-origin iframe — can't attach error handlers
194- }
195171 } ) ;
196172
197173 return true ;
0 commit comments