惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The Cloudflare Blog
阮一峰的网络日志
阮一峰的网络日志
Martin Fowler
Martin Fowler
D
DataBreaches.Net
The GitHub Blog
The GitHub Blog
人人都是产品经理
人人都是产品经理
V
V2EX
爱范儿
爱范儿
PCI Perspectives
PCI Perspectives
T
Troy Hunt's Blog
Stack Overflow Blog
Stack Overflow Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
SecWiki News
SecWiki News
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
The Hacker News
The Hacker News
小众软件
小众软件
雷峰网
雷峰网
D
Docker
NISL@THU
NISL@THU
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
腾讯CDC
B
Blog RSS Feed
C
CERT Recently Published Vulnerability Notes
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
U
Unit 42
有赞技术团队
有赞技术团队
P
Palo Alto Networks Blog
G
GRAHAM CLULEY
T
The Exploit Database - CXSecurity.com
T
Tailwind CSS Blog
S
Security @ Cisco Blogs
量子位
I
InfoQ
Application and Cybersecurity Blog
Application and Cybersecurity Blog
大猫的无限游戏
大猫的无限游戏
Schneier on Security
Schneier on Security
Help Net Security
Help Net Security
Latest news
Latest news
The Register - Security
The Register - Security
S
Securelist
W
WeLiveSecurity
A
Arctic Wolf
Security Latest
Security Latest
AWS News Blog
AWS News Blog
L
LINUX DO - 热门话题
S
Secure Thoughts
T
Tenable Blog
Know Your Adversary
Know Your Adversary
月光博客
月光博客
M
MIT News - Artificial intelligence

Steve Hanov's Blog

How this Canadian Startup Bought Millions of Impressions for $8,000 How to Run a Fellowship Program Into the Ground (and get 18M impressions in the process) My Waterloo Intern went back to school. I'll miss him dearly but here's how I replaced him with Hermes I learned Mandarin. Here's what it taught me about B2C SaaS. The VC's Waterloo Coffee Tour: Where to Find Canada's Next Unicorn How I run multiple $10K MRR companies on a $20/month tech stack How to Save a Gemini Canvas as Markdown A Ralph Loop for Reading: Beating GPT 5.2 with a 4k Context Window (and 4 GPUs) I built a Chrome extension that lets an LLM “see” tweets Fighting Blog Comment Spam with Qwen3 and Ollama Automatically remove wordiness from your writing I found Security Vulnerability in your web application How to detect if an object has been garbage collected in Javascript My favourite Google Cardboard Apps O(n) Delta Compression With a Suffix Array Finding Bieber: On removing duplicates from a set of documents Let's read a Truetype font file from scratch A Quick Measure of Sortedness My thoughts on various programming languages A little VIM hacking
Make a web page screenshot service
2024-11-26 · via Steve Hanov's Blog

I'll take you step by step into how to make a service that takes screenshots of webpages and returns them as an image.

First, let's assume you have google-chrome or chromium-browser installed. Both should work the same way. These browsers have command line options that let you capture a screenshot in headless mode.

chromium-browser --headless 
    --disable-gpu 
    --no-sandbox 
    --screenshot=out.png 
    --window-size=1280,900 
    --virtual-time-budget=1000 
    --user-agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36" 
    https://cbc.ca/news

Explanation of parameters

Url of the site to screenshot

--headlessPut it in headless mode
--disable-gpuUsing GPU in the background sometimes gives us problems, so we disable it
--no-sandboxThe sandbox often gives problems with headless execution as well.
--screenshot="<filename>"You can tell it to capture the screenshot to this file.
--window-size=width,heightSet the width and height of the window
--virtual-time-budget=<ms>Wait this many milliseconds before taking the screenshot, to give the site time to execute frontend frameworks.
--useragent="<user agent>"Set a custom user agent, since many sites will not work with the default one used in headless mode.
url

Making a service

Let's make it into a docker image that we can use. I won't go into the details, since I merely asked AI to do it for me. Synchronize the repo it made here:

git clone github.com/smhanov/screenshot-service
cd screenshot-service
make build
make run 

This will build and create your screenshotting service.Then you can get the screenshot of any web site by going to the url:

http://localhost:5000/screenshot?url=https://cbc.ca/news

It also accepts other parameters for the various arguments.