cloudflare/moltworker
Overview
This skill lets you control headless Chrome through Cloudflare Browser Rendering using the Chrome DevTools Protocol (CDP) over a WebSocket. It integrates with Cloudflare Workers to provide page navigation, screenshots, scraping, and frame capture for video generation. Configuration requires a CDP_SECRET environment variable and a cdpUrl in your browser profile.
How this skill works
The worker creates a page target when a CDP WebSocket connects; the skill listens for Target.targetCreated to obtain the targetId and then sends CDP commands to that target. Common commands include Page.navigate, Page.captureScreenshot, Runtime.evaluate, and Emulation.setDeviceMetricsOverride. Frames captured as PNGs can be stitched into video using ffmpeg.
When to use it
- Take render-accurate screenshots of pages that require JavaScript execution
- Automate navigation and scraping where server-side fetches are insufficient
- Capture sequences of frames for time-lapse or multi-page videos
- Emulate specific viewport sizes or device metrics inside Cloudflare Workers
- Run transient headless browser tasks without managing your own Chromium instances
Best practices
- Set CDP_SECRET in your environment and configure cdpUrl in browser.profiles before connecting
- Wait for Target.targetCreated and handle a reasonable timeout to avoid race conditions
- Increase command timeouts (30–60s) to accommodate worker cold starts
- Capture multiple frames and use ffmpeg locally or in a pipeline to create videos
- Use Emulation.setDeviceMetricsOverride to ensure consistent viewport and pixel ratios
Example use cases
- Generate PNG screenshots of dynamic pages for previews or thumbnails
- Run JavaScript evaluations to extract rendered DOM content for scraping
- Scroll and capture long pages by sending Runtime.evaluate scroll commands and stitching images
- Produce a short MP4 by capturing ordered frames during navigation and running ffmpeg
- Test responsive layouts by programmatically changing viewport dimensions
FAQ
Set CDP_SECRET in the environment and add a browser profile with cdpUrl that points to your worker endpoint including the secret.
How do I detect the page target to send commands to?
Listen for the Target.targetCreated event on the WebSocket and use params.targetInfo.targetId when type === 'page'.
Why do commands sometimes timeout?
Workers can cold-start; increase your command timeout to 30–60 seconds and add retries for reliability.