代码之家  ›  专栏  ›  技术社区  ›  James Ives

使用googlechrome无头模式强制屏幕截图解析

  •  1
  • James Ives  · 技术社区  · 6 年前

    这是在我的Mac电脑上拍到的带有视网膜显示屏的屏幕截图。

    Large screenshot

    Small screenshot

    当Chrome在无头模式下启动时,有没有一种方法可以提高屏幕分辨率?我曾与其他库合作过,比如puppeter,它似乎在所有方面都是一致的。窗口的宽度/高度总是被考虑的,但是实际图像的大小是导致问题的原因。

    "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"
      }
    }
    

    任何帮助都将不胜感激。

    0 回复  |  直到 6 年前
        1
  •  0
  •   Thormod    4 年前

    我也有同样的问题,通过这个论点 --force-device-scale-factor=1 在chrome works for me中:

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