将变量传递给箭头函数

Pass a variable to an arrow function

我正在使用 puppeteer,我正在尝试将变量传递给这样的箭头函数

    const token ='qwertyuisdfghjkl';

    await page.evaluate(token => {
      localStorage.setItem("token", token);
    });

但是tokenundefined

您需要将变量作为 page.evaluate

中的第二个参数传递
const token ='qwertyuisdfghjkl';

await page.evaluate(value => {
    localStorage.setItem("token", value);
}, token);

Docs

docs 表示将值作为第二个参数传递:

const token = 'qwertyuisdfghjkl'

await page.evaluate(value => {
    localStorage.setItem("token", value)
}, token)