Im currently coding a program that gets data from an API and passes them with a loop into a html string that represents the data as a website. I want to create an Image of that website. My problem is that the image is created before the data is getting read. I get the data with $ajax jQuery.
The html file itself loads perfectly fine, displaying the data correct.
Im using NodeHTMLtoImage
var _htmlTemplate = ` ...HTML STUFF
<body>    ....
          const timelineList = document.getElementById('list');
          $.ajax(settings).done(function (response) {
              const jsonData = response.data.point1
              for (const packageInfo of jsonData) {
                  const listItem = document.createElement('li');
                  const timestamp = document.createElement('span');
                  timestamp.textContent = packageInfo.changeTime;
                  listItem.appendChild(timestamp);
          
                  const description = document.createElement('p');
                  description.textContent = packageInfo.description;
                  listItem.appendChild(description);
            
                  timelineList.appendChild(listItem);
              }
          });
            
      </script>
      <div id="users"></div>
      </body>
      </html>
      `
                
          const image = await nodeHtmlToImage({
            html: _htmlTemplate,
            quality: 100,
            type: 'jpeg',
            puppeteerArgs: {
              args: ['--no-sandbox'],
            },
            encoding: 'buffer',
          });
I tried this as well, but it didn't work:
async function createImage() {
try {
    const imagePath = await nodeHtmlToImage({
        html: html,
        output: './test.png'
    });
} catch (error) {
    console.error(error);
}
} createImage();
 
    