- #1
Darkmisc
- 203
- 27
- TL;DR Summary
- I'd like to use a variable from my JS file in my html file. This works fine until I use Puppeteer in the JS file. Then, it won't work.
Hi everyone
I'm using Visual Studio Code and would like to use a variable from a JavaScript file in my html code.
This is easy enough to do until I try using Puppeteer in the JS file. If I add the following line to the JS code, I can no longer call my JS variable in the html file.
I can work around this by saving the JS variable to a text file and then using the fetch method to get the data out of the file, but it's rather clunky.
Is there a more direct way to use JS variables in html while using Puppeteer?
Thanks
I'm using Visual Studio Code and would like to use a variable from a JavaScript file in my html code.
This is easy enough to do until I try using Puppeteer in the JS file. If I add the following line to the JS code, I can no longer call my JS variable in the html file.
Puppeteer:
const puppeteer = require("puppeteer")
I can work around this by saving the JS variable to a text file and then using the fetch method to get the data out of the file, but it's rather clunky.
fetch:
fetch('blah.txt')
.then(response => response.text())
.then(data => {
var myVariable = data;
var paragraphElement = document.getElementById("myParagraph");
paragraphElement.innerHTML = "wowee" + myVariable;
})
.catch(error => console.error(error));
Is there a more direct way to use JS variables in html while using Puppeteer?
Thanks