google-chrome - 使用 Chrome / Chromium 无头模式时如何获取地址栏?
问题描述
当我使用谷歌浏览器或 Chromium 的无头模式截屏时,只需要 HTML Body。
$ chromium --headless --disable-gpu --screenshot --window-size=1280,1080 https://stackoverflow.com/
为了方便,我想用地址栏截图...然后当我看到图片时,我从不混淆“我采取了哪个URL?”。
使用 Chrome/Chromium 无头模式时如何使用地址栏截屏?
解决方案
Chrome headless 没有 UI,它只完成了内存渲染,然后在页面加载到缓冲区后用于提供屏幕截图。所以没有办法让它脱离无头镀铬功能。
但这是其他方式。例如在 linux 上你可以使用类似的命令(ImageMagick 也应该在其他操作系统下工作):
convert screenshot.png -background black -fill white -splice 0x20 -annotate +15+15 'http://test.com' -gravity North -pointsize 30 screenshot2.png
它使用提供的文本为图像添加标题。因此很容易将其包装到单个 shell 脚本中。就像是:
#/bin/bash
url=$1
google-chrome --headless --disable-gpu --screenshot "$url"
current_time=$(date "+%Y.%m.%d-%H.%M.%S")
new_fileName=screenshot_$current_time.png
convert screenshot.png -background black -fill white -splice 0x20 -annotate +15+15 $url -gravity North -pointsize 30 $new_fileName
并将其用作./take_screenshot.sh http://google.com
推荐阅读
- javascript - 这些 ES6 导入语句之间有什么区别?
- c - 我的程序在 ATmega32(8MHz 64presclar Timer1)的 pinb1 上生成 1kHz 方波是否正确?
- javascript - 只匹配一个引号
- python-3.x - 无论我尝试什么都无法在页面上找到元素
- graph-algorithm - 在图中找到 2 个给定城市之间的路径但有条件(需要在 K 步后访问检查站城市)
- kdb - 如何将 kdb 字典转换为表
- node.js - 节点模块的GitlabCI自定义图像问题
- python - 在 Windows 上的虚拟环境中安装包
- kde - 将 Meta 键设置为 KDE 快捷方式
- youtube-api - Youtube API:默认评论设置不适用于通过 API 发布的视频