错误:评估失败:无效参数:应该恰好是一个字符串。| Puppeteer .evaluate() 错误

Lev*_*per 4 javascript puppeteer

这是我第一次使用 puppeteer 进行测试。但我在运行时遇到了一个奇怪的错误

\n

我想做的是在页面中运行这个函数,但是

\n
const puppeteer = require('puppeteer');   \nlet browser, page,\n//evaluates to file://C:/Users/chris/Google Drive/code projects/text translation sheet/test/src/index.html\n    htmlFilepath = "file://" + path.resolve(__dirname, "src/index.html");\nbrowser = await puppeteer.launch();\npage = await browser.newPage();\nawait page.goto(htmlFilepath);   \npage.exposeFunction(getMaxWordsInContentArea.name, getMaxWordsInContentArea)\n      \nconst lastWordThatFit = await page.evaluate(function(){\n          \n    const el = document.querySelector('.line__target-language-text')\n    const elContainer = el.parent;\n    const lastFitWordIndex = getMaxWordsInContentArea(el,elContainer,["Call", "me", "Ishmael.", "Some", "years", "ago\xe2\x80\x94never", "mind", "how", "long", "precisely\xe2\x80\x94having", "little", "or", "no", "money", "in", "my", "purse,", "and", "nothing", "particular", "to", "interest", "me", "on", "shore,", "I", "thought", "I", "would", "sail", "about", "a", "little", "and", "see", "the", "watery", "part", "of", "the", "world.", "It", "is", "a", "way", "I", "have", "of", "driving", "off", "the", "spleen", "and", "regulating", "the", "circulation."])  \n                    \n    return lastFitWordIndex\n});\n
Run Code Online (Sandbox Code Playgroud)\n

有人看到这个有什么问题或者熟悉这个错误吗?

\n

Lev*_*per 11

await忘记在前面加上page.exposeFunction(getMaxWordsInContentArea.name, getMaxWordsInContentArea).

感谢@ZenMonkey 推动我更深入地挖掘。