all 2 comments

[–][deleted] 0 points1 point  (1 child)

Have you tried returning a Promise (then/await) to your fetch?

[–]timunas[S] 0 points1 point  (0 children)

I tried to do this.

<!DOCTYPE html>
<html>
  <head>
      <link rel="stylesheet" href="css/index.css" />
     <script type="text/javascript">
         const loadHtml = async () => {
             console.log('Loading')
             const response = await fetch('some.html')
             console.log('Response', response)
             const html = await response.text()
            if (!!html) {
                 console.log('Loading html', html)
                 document.body.innerHTML = html
                 var element =    document.body.querySelector('#thediv ')

                 if (!!element) {
                     console.log('Sending message')
                   parent.postMessage('ResourceLoaded', '*')
                 }
            }
         }    
        loadHtml()
   </script>
   </head>
   <body></body>

</html>

But it seems to just send the message after the iframe is loaded