设置下载路径时遇TypeError: page._client.send is not a function错误求助
解决TypeError: page._client.send is not a function的方向
改用官方公开API替代私有属性
Puppeteer v19+版本调整了内部API,page._client这个私有属性不再直接暴露,官方推荐使用page.createCDPSession()来获取CDP客户端,这是稳定的公开接口,不会随版本更新失效。修改后的代码:const client = await page.createCDPSession(); await client.send('Page.setDownloadBehavior', { behavior: 'allow', downloadPath: library_path, eventsEnabled: true });检查无头模式配置
如果你使用无头模式运行,Puppeteer v19默认启用的new无头模式在部分CDP命令兼容性上有差异,可以尝试切换到老版无头模式:const browser = await puppeteer.launch({ headless: "old", // 或者设置为false使用有头模式调试 args: ['--no-sandbox', '--disable-setuid-sandbox'] // 按需添加权限参数 });验证下载路径的有效性
确保library_path对应的目录已创建且Node进程有读写权限,可提前用文件系统API创建目录:const fs = require('fs'); if (!fs.existsSync(library_path)) { fs.mkdirSync(library_path, { recursive: true }); }
内容的提问来源于stack exchange,提问作者Jake Yuraszeck
相关产品推荐
相关产品推荐

