在命令行中使用 Firefox 截取整页截图 [英] Take a full page screenshot with Firefox on the command-line
问题描述
我在 VPS 中的 Xvfb 上运行 Firefox.我想要做的是对页面进行整页截图.
I'm running Firefox on a Xvfb in a VPS. What I want to do is to take a full page screenshot of the page.
我可以使用
firefox http://google.com
并使用 ImageMagick 截取屏幕截图(在 X 内)
and take a screenshot (inside X) using ImageMagick
import root -window output.jpg
问题是,大部分页面需要滚动,我无法事先知道高度.
The problem is, most of the page need scrolling and I can't know the height beforehand.
另一种方法是选择一个非常大的高度(例如 4000px),然后处理图像并删除无用部分.但这是不必要的处理.
The other way is to pick a very big height (like 4000px) and then process the image and remove the useless part. But that's unnecessary processing.
我发现了许多 Firefox 附加组件,但我正在寻找一种可以使用 Shell 命令行进行编程的解决方案.
I found many Firefox add-ons, but I'm looking for a solution that can be programmed using the Shell Command line.
我最终为此编写了自己的FireFox 扩展.
I ended up writing my own FireFox extension for doing this.
推荐答案
开发者工具栏 GCLI 和 Shift+F2 快捷方式已在 Firefox 60 版 中删除.要在 60 或更新版本中截取屏幕截图:
The Developer Toolbar GCLI and Shift+F2 shortcut were removed in Firefox version 60. To take a screenshot in 60 or newer:
- 按 Ctrl+Shift+K 打开开发者控制台(⌥ Option+⌘命令+K(macOS)
- 输入
:screenshot
或:screenshot --fullpage
- press Ctrl+Shift+K to open the developer console (⌥ Option+⌘ Command+K on macOS)
- type
:screenshot
or:screenshot --fullpage
对于 Firefox 版本 <60:
For Firefox versions < 60:
按 Shift+F2 或转到 工具 >网络开发人员开发者工具栏以打开命令行.写:
Press Shift+F2 or go to Tools > Web Developer > Developer Toolbar to open a command line. Write:
screenshot
然后按 Enter 以截取屏幕截图.
and press Enter in order to take a screenshot.
要完整回答问题,您甚至可以保存整个页面,而不仅仅是其中的可见部分:
To fully answer the question, you can even save the whole page, not only the visible part of it:
screenshot --fullpage
并且要将屏幕截图复制到剪贴板,请使用 --clipboard
选项:
And to copy the screenshot to clipboard, use --clipboard
option:
screenshot --clipboard --fullpage
Firefox 18 改变了参数传递给命令的方式,你必须添加——"在他们之前.
Firefox 18 changes the way arguments are passed to commands, you have to add "--" before them.
Firefox 88.0 有一种新的截屏方法.如果在about:config中将extensions.screenshots.disabled
设置为false
,您可以右键单击屏幕并选择截屏.还有一个屏幕截图菜单按钮,您可以通过自定义将其添加到菜单中.
Firefox 88.0 has a new method for taking screenshots. If extensions.screenshots.disabled
is set to false
in about:config, you can right-click the screen and select Take Screenshot. There's also a screenshot menu button you can add to your menu via customization.
您可以在此处找到一些文档和完整的命令列表.
附注.截图默认保存在downloads目录下.
这篇关于在命令行中使用 Firefox 截取整页截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!