@@ -162,6 +162,14 @@ function initDocument (document, window) {
162162  } 
163163
164164  process . nextTick ( async  ( )  =>  { 
165+     const  _tryDispatchEvent  =  ( target ,  event )  =>  { 
166+       try  { 
167+         target . dispatchEvent ( event ) ; 
168+       }  catch ( err )  { 
169+         console . warn ( err ) ; 
170+       } 
171+     } ; 
172+     
165173    if  ( body )  { 
166174      const  bodyChildNodes  =  body . childNodes ; 
167175      body . childNodes  =  new  window . NodeList ( ) ; 
@@ -173,7 +181,11 @@ function initDocument (document, window) {
173181      } 
174182
175183      body . childNodes  =  bodyChildNodes ; 
176-       body . _emit ( 'children' ,  Array . from ( bodyChildNodes ) ,  [ ] ,  null ,  null ) ; 
184+       try  { 
185+         body . _emit ( 'children' ,  Array . from ( bodyChildNodes ) ,  [ ] ,  null ,  null ) ; 
186+       }  catch ( err )  { 
187+         console . warn ( err ) ; 
188+       } 
177189
178190      try  { 
179191        await  GlobalContext . _runHtml ( document . body ,  window ) ; 
@@ -182,9 +194,9 @@ function initDocument (document, window) {
182194      } 
183195
184196      document . readyState  =  'interactive' ; 
185-       document . dispatchEvent ( new  Event ( 'readystatechange' ,  { target : document } ) ) ; 
197+       _tryDispatchEvent ( document ,   new  Event ( 'readystatechange' ,  { target : document } ) ) ; 
186198
187-       document . dispatchEvent ( new  Event ( 'DOMContentLoaded' ,  { 
199+       _tryDispatchEvent ( document ,   new  Event ( 'DOMContentLoaded' ,  { 
188200        target : document , 
189201        bubbles : true , 
190202      } ) ) ; 
@@ -196,19 +208,19 @@ function initDocument (document, window) {
196208      } 
197209
198210      document . readyState  =  'interactive' ; 
199-       document . dispatchEvent ( new  Event ( 'readystatechange' ,  { target : document } ) ) ; 
211+       _tryDispatchEvent ( document ,   new  Event ( 'readystatechange' ,  { target : document } ) ) ; 
200212
201-       document . dispatchEvent ( new  Event ( 'DOMContentLoaded' ,  { 
213+       _tryDispatchEvent ( document ,   new  Event ( 'DOMContentLoaded' ,  { 
202214        target : document , 
203215        bubbles : true , 
204216      } ) ) ; 
205217    } 
206218
207219    document . readyState  =  'complete' ; 
208-     document . dispatchEvent ( new  Event ( 'readystatechange' ,  { target : document } ) ) ; 
220+     _tryDispatchEvent ( document ,   new  Event ( 'readystatechange' ,  { target : document } ) ) ; 
209221
210222    document . dispatchEvent ( new  Event ( 'load' ,  { target : document } ) ) ; 
211-     window . dispatchEvent ( new  Event ( 'load' ,  { target : window } ) ) ; 
223+     _tryDispatchEvent ( window ,   new  Event ( 'load' ,  { target : window } ) ) ; 
212224
213225    parentPort . postMessage ( { 
214226      method : 'xrMode' , 
0 commit comments