In my Puppeteer script, I use file JS to execute before loading the page:
const preloadFile = fs.readFileSync('./file.js', 'utf8'); const id = await page.evaluateOnNewDocument(preloadFile);
file.js contains:
const i = setInterval(()=>{ if (window.turnstile) { clearInterval(i) window.turnstile.render = (a,b) => { b.userAgent = navigator.userAgent window.tsCallback = b.callback window.action = b.action window.data = b.cData console.log(b) return 'foo' } } },50)
This script prints an object (Action, Cdata, Callback...) on the browser console
I want to get this object from puppeter side and be able to call function callback().
I used page.evaluate() but it didn’t work for me
You can use my Puppeteer wrapper libraryhttps://github.com/wix-incubator/bubanai/pullsto achieve this goal (get the object from the browser console), use
new ConsoleDriver(context).getMessages()
method, and then convert the received object from the array to JSON...Or just copy the ConsoleDriver code into your project.
refer to
Usage examples