使用puppeteer登录whatsapp-web.js失败,请求技术协助
解决whatsapp-web.js登录时出现的"Cannot read properties of undefined (reading 'default')"错误
长期使用whatsapp-web.js,此前工具正常运行多日,近期登录时触发如下报错:
throw new Error('Evaluation failed: ' + helper_js_1.helper.getExceptionMessage(exceptionDetails)); ^ Error: Evaluation failed: TypeError: Cannot read properties of undefined (reading 'default') at __puppeteer_evaluation_script__:14:123 at ExecutionContext._evaluateInternal (C:\Users\54112\Downloads\postall-bot2\node_modules\puppeteer\lib\cjs\puppeteer\common\ExecutionContext.js:221:19) at processTicksAndRejections (node:internal/process/task_queues:96:5) at async ExecutionContext.evaluate (C:\Users\54112\Downloads\postall-bot2\node_modules\puppeteer\lib\cjs\puppeteer\common\ExecutionContext.js:110:16) at async Client.initialize (C:\Users\54112\Downloads\postall-bot2\node_modules\whatsapp-web.js\src\Client.js:267:9)
以下是针对性的解决步骤:
- 更新whatsapp-web.js到最新版本:WhatsApp Web会频繁更新,旧版本库易与网页端出现兼容性问题,执行命令:
npm install whatsapp-web.js@latest - 清除会话缓存:登录会话缓存损坏可能导致初始化失败,找到项目根目录下的
.wwebjs_cache文件夹并删除,随后重启服务 - 修复Puppeteer兼容性:卸载现有Puppeteer后重新安装,确保版本与whatsapp-web.js适配,执行命令:
npm uninstall puppeteer && npm install puppeteer - 启用可视化调试:暂时关闭无头模式,查看网页端是否有异常提示,修改Client初始化代码:
启动后观察浏览器窗口内的WhatsApp Web页面,根据加载错误或验证提示进一步处理const { Client } = require('whatsapp-web.js'); const client = new Client({ puppeteer: { headless: false } });
内容的提问来源于stack exchange,提问作者Emmanuel Salvo
相关产品推荐
相关产品推荐

