Reputation:
I would like to trigger a function that runs in node from the browser. How can I do this?
let log = () => console.log("helsadfl");
await page.evaluate((log) => {
document.addEventListener("click", function () {
console.log(log);
});
}, log);
Additional: Why is this not able to console.log the target?
await page.exposeFunction("log", (e) => console.log(e.target));
await page.evaluate(() => {
document.addEventListener("click", log);
});
Upvotes: 3
Views: 920
Reputation: 13782
await page.exposeFunction('log', () => console.log("helsadfl"));
await page.evaluate(() => {
document.addEventListener("click", async () => {
await window.log();
});
});
Upvotes: 2