Reputation: 502
I'm using Puppeteer. The variable passed doesn't work. I need this variable to be used inside the browser's context. Here's the stripped down version of the code :
let currentPost = 1;
await page.evaluate(async (currentPost) => {
await new Promise((currentPost, resolve, reject) => {
var timer = setInterval(() => {
console.log(currentPost);
resolve();
}, 100);
});
}, currentPost);
Upvotes: 2
Views: 679
Reputation: 18036
Promise accepts in two arguments: resolve and reject. remove the current Post arg and it will work as expected.
let currentPost = 1;
await page.evaluate(async (currentPost) => {
await new Promise((resolve, reject) => {
var timer = setInterval(() => {
console.log(currentPost);
resolve();
}, 100);
});
}, currentPost);
Upvotes: 3