简体   繁体   English

以无头模式运行 Chrome

[英]running Chrome in headless mode

To run chrome in headless mode , I did为了在无头模式下运行chrome ,我做到了

alias chrome="/Applications/Google\\ Chrome.app/Contents/MacOS/Google\\ Chrome"别名 chrome="/Applications/Google\\ Chrome.app/Contents/MacOS/Google\\ Chrome"

chrome --remote-debugging-port=9222 --disable-gpu --headless铬 --remote-debugging-port=9222 --disable-gpu --headless

in console, But, I got this error,在控制台中,但是,我收到了这个错误,

[0305/140111.481537:ERROR:xattr.cc(64)] setxattr org.chromium.crashpad.database.initialized on file /var/folders/m3/92mmh21n0cx4ppf8c3bcns38hd4_kk/T/: Operation not permitted (1) [0305/140111.484254:ERROR:xattr.cc(64)] setxattr org.chromium.crashpad.database.initialized on file /var/folders/m3/92mmh21n0cx4ppf8c3bcns38hd4_kk/T/: Operation not permitted (1) [0305/140111.484254:INFO:crashpad_client_mac.cc(292)] restarting handler in 0.983s [0305/140111.513641:ERROR:gpu_process_transport_factory.cc(1009)] Lost UI shared context. [0305/140111.481537:ERROR:xattr.cc(64)] setxattr org.chromium.crashpad.database.initialized on file /var/folders/m3/92mmh21n0cx4ppf8c3bcns38hd4_kk/T/: 不允许操作 (ERROR4031041515) (ERROR4031041515) :xattr.cc(64)] setxattr org.chromium.crashpad.database.initialized 文件 /var/folders/m3/92mmh21n0cx4ppf8c3bcns38hd4_kk/T/: 不允许操作 (1) [0305/140111:4849FOMC. )] 在 0.983 秒内重新启动处理程序 [0305/140111.513641:ERROR:gpu_process_transport_factory.cc(1009)] 丢失 UI 共享上下文。 [0305/140111.513709:ERROR:instance.cc(49)] Unable to locate service manifest for metrics [0305/140111.513733:ERROR:service_manager.cc(890)] Failed to resolve service name: metrics [0305/140111.514229:ERROR:socket_posix.cc(142)] bind() returned an error, errno=48: Address already in use (48) [0305/140111.513709:ERROR:instance.cc(49)] 无法定位指标的服务清单 [0305/140111.513733:ERROR:service_manager.cc(890)] 未能解析服务名称:指标 [0305/140111.513733:metrics [0305/140111.513733:ERROR:service_manager.cc(890)] .cc(142)] bind() 返回错误,errno=48:地址已被使用 (48)

DevTools listening on ws://[::1]:9222/devtools/browser/c46563ca-1891-48bd-bdd6-e6122f3f3b5d [0305/140112.484141:ERROR:xattr.cc(64)] setxattr org.chromium.crashpad.database.initialized on file /var/folders/m3/92mmh21n0cx4ppf8c3bcns38hd4_kk/T/: Operation not permitted (1) [0305/140112.484641:INFO:crashpad_client_mac.cc(292)] restarting handler in 0.985s [0305/140113.489618:ERROR:xattr.cc(64)] setxattr org.chromium.crashpad.database.initialized on file /var/folders/m3/92mmh21n0cx4ppf8c3bcns38hd4_kk/T/: Operation not permitted (1) [0305/140113.490274:INFO:crashpad_client_mac.cc(292)] restarting handler in 0.979s [0305/140114.484881:ERROR:xattr.cc(64)] setxattr org.chromium.crashpad.database.initialized on file /var/folders/m3/92mmh21n0cx4ppf8c3bcns38hd4_kk/T/: Operation not permitted (1) [0305/140114.485349:INFO:crashpad_client_mac.cc(292)] restarting handler in 0.985s [0305/140115.489188:ERROR:xattr.cc(64)] setxattr org.chromium.crashpad.database.initialized on file /var/folders/m3/92mmh2 DevTools 监听 ws://[::1]:9222/devtools/browser/c46563ca-1891-48bd-bdd6-e6122f3f3b5d [0305/140112.484141:ERROR:xattr.cc(64)] setxattium.sh .在文件 /var/folders/m3/92mmh21n0cx4ppf8c3bcns38hd4_kk/T/ 上初始化:操作不允许 (1) [0305/140112.484641:INFO:crashpad_client_mac.cc(292)] 在 [0.43901855s.103901855s.10390185s.ERROR] 中重新启动处理程序: cc(64)] setxattr org.chromium.crashpad.database.initialized 在文件 /var/folders/m3/92mmh21n0cx4ppf8c3bcns38hd4_kk/T/ 上:操作不允许 (1) [0305/140113.490274:INFO:ccrestart] 0.979 秒内的处理程序 [0305/140114.484881:ERROR:xattr.cc(64)] setxattr org.chromium.crashpad.database.initialized 在文件 /var/folders/m3/92mmh21n0cx4ppf8c3bcns38/:T5038hd4_0 上初始化(不允许操作) /140114.485349:INFO:crashpad_client_mac.cc(292)] 在 0.985 秒内重新启动处理程序 [0305/140115.489188:ERROR:xattr.cc(64)] setxattr org.chromium.crashpad.database/initializers/filedm 92mmh2 1n0cx4ppf8c3bcns38hd4_kk/T/: Operation not permitted (1) [0305/140115.489638:INFO:crashpad_client_mac.cc(292)] restarting handler in 0.985s 1n0cx4ppf8c3bcns38hd4_kk/T/: 不允许操作 (1) [0305/140115.489638:INFO:crashpad_client_mac.cc(292)] 在 0.985s 内重新启动处理程序

I also tried,我也试过,

/Applications/Google\\ Chrome.app/Contents/MacOS/Google\\ Chrome --remote-debugging-port=9222 --disable-gpu --headless /Applications/Google\\ Chrome.app/Contents/MacOS/Google\\ Chrome --remote-debugging-port=9222 --disable-gpu --headless

but I got same error.但我遇到了同样的错误。

Is there any solution for this?有什么解决办法吗?

I got the answer from Chrome crashpad crashes on xattr我从Chrome crashpad 在 xattr 上崩溃得到了答案

Just provide a different directory for "crash dumps" when starting Chrome, like this:只需在启动 Chrome 时为“崩溃转储”提供一个不同的目录,如下所示:

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222 --disable-gpu --headless --crash-dumps-dir=/tmp

add the following command flags添加以下命令标志

-disk-cache-dir=/tmp --user-data-dir=/tmp --crash-dumps-dir=/tmp

eg.例如。

chrome --headless --disable-gpu --screenshot --disk-cache-dir=/tmp --user-data-dir=/tmp --crash-dumps-dir=/tmp http://m.baidu.com

For more commnad-line flags, see here有关更多命令行标志,请参见此处

UPDATE 3/6更新 3/6
I checked the solution on my own MacBook and it worked.我在自己的 MacBook 上检查了解决方案,它奏效了。


I encounter the same issue today, and after searching some document, I suspect it's due to the SIP(System Integrity Protection) feature in MacOS, with that restrict, you can't modify the files under /var folder even you have the root privilege.我今天遇到了同样的问题,在搜索了一些文档后,我怀疑这是由于 MacOS 中的SIP(系统完整性保护)功能,由于该限制,即使您具有 root 权限,您也无法修改/var文件夹下的文件.

So here is the way to disable that feature:所以这里是禁用该功能的方法:

  1. Turn off your Mac (Apple > Shut Down).关闭 Mac(Apple > 关机)。
  2. Hold down Command-R and press the Power button.按住 Command-R 并按下电源按钮。 Keep holding Command-R until the Apple logo appears.继续按住 Command-R 直到出现 Apple 标志。
  3. Wait for OS X to boot into the OS X Utilities window.等待 OS X 启动进入 OS X 实用程序窗口。
  4. Choose Utilities > Terminal.选择实用程序 > 终端。
  5. Enter csrutil disable.输入 csrutil 禁用。
  6. Enter reboot.进入重启。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 让Chrome以无头模式运行 - Keep Chrome running in headless mode Chrome 在没有无头模式的情况下无法运行(Ubuntu 18.04) - Chrome not running without headless mode (Ubuntu 18.04) 检测从JavaScript无头模式运行的Chrome - Detect Chrome running in headless mode from JavaScript 关于运行Google Chrome 59无头模式的警告 - Warning on running Google Chrome 59 headless mode 在VSTS托管代理上以Chrome(无头模式)运行Selenium测试 - Running Selenium Tests in Chrome (Headless mode) on a VSTS Hosted Agent Chrome 在 Selenium Python 中运行无头模式时卡在移动版本中 - Chrome is stuck in mobile version while running headless mode in Selenium Python 在Chrome中运行无头模式时,将文件下载到路径 - Download a file to a path when running headless mode in Chrome Chrome和Firefox始终通过Gitlab-runner以无头模式运行 - Chrome and Firefox running ALWAYS in headless mode through Gitlab-runner 在Ubuntu上运行无头Chrome - Running headless chrome on Ubuntu 在无头模式下运行 Chrome 如何影响我的 selenium 测试与正常模式? - How can running Chrome in headless mode affect my selenium testing vs normal mode?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM