简体   繁体   English

使用 Google Chrome Headless 模式强制执行屏幕截图分辨率

[英]Enforce screenshot resolution with Google Chrome Headless mode

I'm having an issue with Nightwatch and Chrome when it launches in headless mode.当 Nightwatch 和 Chrome 在无头模式下启动时,我遇到了问题。 I've setup a script to take screenshots of my page which I later compare against in order to figure out what the difference is between them.我已经设置了一个脚本来截取我的页面的屏幕截图,稍后我会与这些屏幕截图进行比较,以找出它们之间的区别。 The problem I'm running into is that depending on the machine that runs my script the screenshots are always different as they are not the same resolution.我遇到的问题是,根据运行我的脚本的机器,屏幕截图总是不同的,因为它们的分辨率不同。

Here is a screenshot that Nightwatch captured on my Mac with a retina display.这是 Nightwatch 在我的带有视网膜显示屏的 Mac 上捕获的屏幕截图。

大截图

And here is the one which was captured in CircleCI when it ran the same script:这是在 CircleCI 运行相同脚本时捕获的一个:

小截图

Is there a way to enforce a screen resolution when launching Chrome in headless mode?在无头模式下启动 Chrome 时,有没有办法强制执行屏幕分辨率? I've worked with other libraries such as Puppeteer and it seems to be consistent across the board.我曾与其他库(如 Puppeteer)合作过,它似乎全面一致。 The window width/height is always respected, but the size of the actual images is what's causing issues here.窗口宽度/高度总是受到尊重,但实际图像的大小是导致问题的原因。

Here is what my launch settings look like from my Nightwatch config file:以下是我的 Nightwatch 配置文件中的启动设置:

"chrome_launch" : {
  "launch_url" : "https://localhost:8000",
  "globals" : {
    "abortOnAssertionFailure": false,
    "env" : "local"
  },
  "desiredCapabilities": {
    "chromeOptions" : {
      "args" : ["window-size=1280,2480", "headless", "disable-gpu", "hide-scrollbars"]
    },
    "resolution": "1440x900"
  }
}

Any help would be greatly appreciated.任何帮助将不胜感激。

我遇到了同样的问题,在 chrome 中传递这个参数--force-device-scale-factor=1对我有用:

google-chrome --headless --force-device-scale-factor=1 --window-size=1200,800

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

相关问题 通过无头模式截图Chrome SSL错误页面 - Screenshot Chrome SSL error page via headless mode 在新标签页中切换时无法在 Chrome Headless 模式下捕获屏幕截图 - Unable to capture screenshot in Chrome Headless mode while switched in new tab 有无法以无头模式启动Google Chrome的方法吗? - Any way to start Google Chrome in headless mode? 是否可以使用扩展程序以无头模式运行 Google Chrome? - Is it possible to run Google Chrome in headless mode with extensions? 关于运行Google Chrome 59无头模式的警告 - Warning on running Google Chrome 59 headless mode 以无头模式通过谷歌浏览器下载文件 - Download file through Google Chrome in headless mode Chrome在本地计算机上的无头截图 - Chrome headless screenshot on local machine 以无头模式运行 Chrome - running Chrome in headless mode 在 WSL Ubuntu 上运行“google-chrome”作为 --headless --no 沙箱会出现多个错误 - 如何在 WSL 中使用无头截屏? - Running “google-chrome” on WSL Ubuntu as --headless --no sandbox gives multiple errors - how do I take screenshot using headless in WSL? google-chrome --headless --screenshot在Centos 7上崩溃了“无法获取下载目录”的消息 - google-chrome --headless --screenshot is crashing with message “Could not get download directory” on Centos 7
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM