‘Target closed‘ error in Puppeteer解决

背景

业务应用需要将系统从centos切换ubuntu,其中A应用在准备好相应的ubuntu镜像后,在mac本机启容器,执行测试脚本报错

复制代码
"Error: Protocol error (Target.setDiscoverTargets): Target closed."

排查

1.看Chromium 错误日志

添加dumpio: true,这会把 Chromium 启动过程的 stderr 输出都打到控制台

复制代码
const browser = await puppeteer.launch({
  headless: true,
  args: [...],
  dumpio: true
});

2.执行后,关键报错如下

复制代码
[0612/162451.208800:FATAL:zygote_main_linux.cc(163)] Check failed: sandbox::ThreadHelpers::IsSingleThreaded().
[0612/162451.595965:ERROR:file_path_watcher_linux.cc(318)] inotify_init() failed: Function not implemented (38)
qemu: unknown option 'type=gpu-process'

DevTools listening on ws://127.0.0.1:33643/devtools/browser/cab2bfec-926e-4e7b-b53e-46157b3a6032
[0612/162451.770694:WARNING:gpu_process_host.cc(1206)] The GPU process has crashed 1 time(s)
qemu: unknown option 'type=gpu-process'
[0612/162451.831737:WARNING:gpu_process_host.cc(1206)] The GPU process has crashed 2 time(s)
qemu: unknown option 'type=gpu-process'
[0612/162451.861199:WARNING:gpu_process_host.cc(1206)] The GPU process has crashed 3 time(s)
qemu: unknown option 'type=gpu-process'
[0612/162451.874366:WARNING:gpu_process_host.cc(1206)] The GPU process has crashed 4 time(s)
qemu: unknown option 'type=gpu-process'
[0612/162451.884288:WARNING:gpu_process_host.cc(1206)] The GPU process has crashed 5 time(s)
qemu: unknown option 'type=gpu-process'
[0612/162451.893254:WARNING:gpu_process_host.cc(1206)] The GPU process has crashed 6 time(s)
qemu: unknown option 'type=gpu-process'
[0612/162451.908820:WARNING:gpu_process_host.cc(1206)] The GPU process has crashed 7 time(s)
qemu: unknown option 'type=gpu-process'
[0612/162451.936704:WARNING:gpu_process_host.cc(1206)] The GPU process has crashed 8 time(s)
qemu: unknown option 'type=gpu-process'
[0612/162451.995340:WARNING:gpu_process_host.cc(1206)] The GPU process has crashed 9 time(s)
[0612/162451.995588:FATAL:gpu_data_manager_impl_private.cc(918)] The display compositor is frequently crashing. Goodbye.

(node:499) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Protocol error (Target.setDiscoverTargets): Target closed.
(node:499) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

3.根据报错关键字搜索查到类似issue(https://github.com/puppeteer/puppeteer/issues/7746),提供的解决方案有两种

|---|-------------------------------------------------------------------------------|---------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| | 方案 | 测试结果 | 引申 |
| 1 | Docker desktop启用beta功能:'Use Rosetta for x86/amd64 emulation on Apple Silicon' | mac机系统版本不满足,无法测试 | 1.Rosetta 2介绍 2.ARM 和 x86_64是什么关系 |
| 2 | chromium args参数增加--single-process | 1.经测试,该方案可行 2.--no-sandbox参数也必须 | |

相关推荐
Dovis(誓平步青云)几秒前
《剖析 Linux 文件系统:架构、原理与实战操作指南》
linux·运维·服务器
千百元几秒前
centos查线程数
linux·运维·centos
---学无止境---1 分钟前
Linux中基数树标签相关操作函数的实现
linux
or77iu_N35 分钟前
Linux 解压安装(安装tomcat)
linux·运维·tomcat
海棠蚀omo1 小时前
Linux操作系统-父进程的等待:一个关于回收与终结的故事
linux·操作系统
乌萨奇也要立志学C++1 小时前
【Linux】Ext系列文件系统 从磁盘结构到文件存储的原理剖析
android·linux·缓存·1024程序员节
软安科技2 小时前
专有软件使用Linux内核的用户头文件违反GPL吗?| 开源合规场景
linux·开源软件·开源协议
A-刘晨阳2 小时前
K8S 二进制集群搭建(一主两从)
linux·运维·云原生·容器·kubernetes
egoist20232 小时前
[linux仓库]信号处理[进程信号·伍]
linux·信号处理·写时拷贝·软中断·硬件中断·缺页中断·时钟中断
HIT_Weston2 小时前
15、【Ubuntu】【VSCode】VSCode 断联问题分析:UID 补充
linux·vscode·ubuntu