I'm trying to render a page using puppeteer, extract the name of a dynamic javascript variable on the page, and return the variable as an object. I'm using puppeteer and node.js to do this.
I'm able to get the name of the javascript variable that is being generated on page but anytime I try to print it out to the console I am getting a "undefined" error. I've spent the better part of the morning trying to figure this out but I'm stumped. Here's the code below.
const puppeteer= require('puppeteer');
var url = 'https://www.website.com';
async function run () {
try {
const browser = await puppeteer.launch({
headless: true,
args: ['--no-sandbox']
});
const page = await browser.newPage();
await page.goto(url);
const flashVariableName = await page.evaluate( () => {
var start = document.documentElement.innerHTML.indexOf('var flashvariable_') + 'var '.length;
var tempDoc = document.documentElement.innerHTML.substr(start);
var end = tempDoc.indexOf(' =');
return tempDoc.substr(0, end);
});
console.log(await page.evaluate( (flashVariableName) => flashVariableName ));
await browser.close();
} catch(e){
console.log("Error Occurred", e)
}
}
run();

flashVariableName is returning the right name for the javascript variable on the page but how can I actually get access to the varialble?
