ToolingProjects

Book Screenshot — book captures → one PDF

A personal Chrome extension (Manifest V3) that turns three hundred manual captures, one page at a time, into set it up and leave it. It writes the PDF itself without a library, leaves no images on disk, sends nothing off the machine, and is for DRM-free content only.

12 min read

A Chrome extension that turns the pages on its own, captures only what is actually visible on screen, checks for duplicate pages at two levels, then assembles a PDF in memory. It works with any kind of reader, from epub.js inside an iframe to Google Docs drawn onto a canvas.

Manifest V3Service WorkerOffscreen DocumentcaptureVisibleTabHand-written PDF writerOKLCHadb (Android)
Empathize · Define

The problem

Books read through a web viewer usually have no download button. Capturing them by hand, page by page, is not just tiring. It produces files you can't use.

A person reading a book on a web page on a laptop
Many books can only be read through an on-screen web viewer, with no download button · Photo: Annie Spratt / Unsplash

I tried capturing by hand first. I ended up with 300-plus images piled on the desktop, with duplicate pages and missing pages, because pressing the right arrow didn't always make the reader turn the page. Then I still had to sort them and merge them into a PDF myself. A ten-minute job took the whole evening.

— The starting brief, before building Book Screenshot

The reader lives in an iframe, so the DOM is out of reach

Readers like epub.js put the content in a blob: / srcdoc iframe that an extension can't read directly. Tools that work by pulling text out of the DOM simply don't work here.

Pressing next doesn't always turn the page

In some readers the right arrow scrolls down one screen instead of moving to the next section. Sometimes the page hasn't finished loading. The result is the same page captured twice, or content skipped without noticing.

Hundreds of images to merge by hand

Capturing is only half the job. The images still need sorting, cropping, compressing and merging into a PDF, and meanwhile the originals are scattered all over the disk.

A document hundreds of screens long kills the tab

For documents captured one screen at a time, holding every image in memory until the end means RAM grows until the tab crashes before you get a file.

Some books are off-limits

Library apps with DRM capture as black images, and some viewers embed a forensic watermark with the account owner's email on every page. These two cases aren't technical problems. They are a line to stop at.


Ideate

The solution

Stop trying to understand each reader's structure. Work at the one layer every reader shares: "the image on screen".

The Book Screenshot area-selection overlay framing a book page in a reader, with four corner handles and a save-area button
The real area-selection overlay: drag a frame around the content only, with the actual size shown, then save the area (sample reader page, public domain text)

Capture what the eye sees, not the DOM

captureVisibleTab takes a screenshot of the visible tab, just like pressing the screenshot key. Whether the reader is an iframe, a canvas, epub.js or anything else, it can be captured the same way, because they all end up as pixels on the same screen.

Check "did the page really change?" with two-level signatures

A screen-level signature (scroll position + text) is used when the reader scrolls on its own. A section-level signature (text only) is used when we do the scrolling. Different modes need different levels, or you get a whole section of duplicate pages.

4 capture modes for every page shape

Single page · long scroll as one continuous image · long scroll split into equal pages · one long document with no next button (Google Docs / single-page web novels)

PDF assembled in memory, no leftover files

Every page is kept as jpeg bytes in an offscreen document, and the PDF is written by hand with DCTDecode (the jpeg is embedded as-is, with no decode and re-encode). The result is a single file, with no images left on disk.

Select the area, then confirm by eye

Drag a frame on the actual page, adjust it with four corner handles, hold Shift to lock a square or an axis, and the popup comes back with a preview card showing the real size. You can see whether the crop is right before starting.


Prototype

How it works — 4 steps

The popup is a vertical wizard. Follow steps 1 → 2 → 3, then let it capture on its own.

Chrome with a reader page on the left and the Book Screenshot side panel on the right, capturing page 12 with a crop-area preview
The side panel stays open beside the page for the whole run, showing a preview of the selected area and the status "Page 12…" while it turns the pages itself
1

Set up the book

Choose a capture mode, enter the title, the page count (leave blank to capture until the end) and the resolution

2

Select the area

Drag a frame around the content only, cut out the reader's toolbars, and check the preview

3

Let it capture

Capture → check the page really changed → press next → repeat, with randomized page-turn timing like a human reader

4

Get the PDF

All pages are bound into one file with the title and downloaded automatically. Stopping midway still gives you a file.


Prototype

Tech Stack & Architecture

Pure Manifest V3: no backend, no build step, no PDF library

The Book Screenshot manifest.json showing permissions, the service worker and the side panel
The real manifest.json — pure MV3: service worker + side panel + offscreen, no backend
Popup — 3-step wizard + crop-selection overlay
Anuphan Lucide OKLCH tokens base-select crop preview
↕
Service Worker (background.js) — runs the capture loop
captureVisibleTab goNext() duplicate-page detector chrome.scripting badge
↕
Offscreen Document — crop + bind + write PDF
OffscreenCanvas createImageBitmap DCTDecode /Title UTF-16BE
↕
Scripts injected into the web page
bsPageSig bsDocProbe bsDocGoPage bsDocPageBand walks contentDocument
Why an Offscreen Document?

A service worker in MV3 has no DOM, so it can't use canvas at all. But all the work here is cropping, resizing and binding images into pages, which needs a canvas. An Offscreen Document is an invisible HTML page the extension keeps open as a dedicated image workroom, so it can crop images and assemble the PDF without opening a visible tab.


Prototype

What I built — 8 core capabilities

The full loop, from selecting the area to a PDF that's ready to read

The capture-mode dropdown in the side panel showing 5 options
The capture-mode dropdown (custom-drawn with base-select so it uses the Anuphan font). Pick the one that matches the page shape.

4 capture modes

Single page / continuous long scroll / long scroll split into equal pages / one long document with no next button

Two-layer duplicate-page detector

The first layer compares the top of the image byte for byte (no false positives). The second compares text signatures, in case the image shifts slightly but the content is the same.

goNext — press until the page really changes

It doesn't press once and trust it. It keeps pressing until the content signature changes, which means a new section. If nothing changes at all, the book is finished.

Hand-written PDF writer

No library. It writes the PDF objects directly, embeds jpeg with DCTDecode, and stores Thai titles in /Title as UTF-16BE.

Bind as it goes, free up RAM

Long documents are bound into PDF pages every 8 screens, then the bitmaps are released. The number on the badge is the real PDF page count, not the screen count.

Google Docs mode

Reads the real paper edges from the DOM, scrolls so the top of each page meets the top edge, and captures a full page in one shot. No grey gaps, no crop to select.

Crop overlay + preview

Four corner handles, drag the middle to move, Shift to lock a square or an axis, then it comes back with a thumbnail and the real size

phone-capture.sh

A script does the same job on Android through adb: swipe the page, capture, compress, and merge into a titled PDF


Prototype

The popup

A paper theme in OKLCH purple. Everything happens on one screen, with no hidden settings page.

The Book Screenshot side panel after setup, before an area is selected
Setup done. No area selected = capture the full screen
The Book Screenshot side panel during a capture, with a preview card of a 1040 × 1436 crop area
Capturing: preview card + real size, and the start button locks to "Capturing…"

Test & Iterate

Hacks and problems

7 problems that came up with real books. Almost all of them showed up as "some books work, some don't".

The clickNext function in background.js dispatching keyboard events into an iframe
The real clickNext(): it fires the right arrow both outside and, by walking contentDocument, inside the iframe. This was the real cause of the duplicate pages.

Pressing the right arrow does nothing

Readers like epub.js put the content in an iframe and listen for keyboard events inside it, so keys fired at the outer document have no effect. This was the real cause of the duplicate pages.

Fix: the key has to reach inside the iframe too, but chrome.scripting can't enter blob:/srcdoc iframes → walk contentDocument from the parent page manually and dispatch the event directly.

1 unit of scrollTop is not 1 pixel on screen

Readers that zoom with CSS transform make a box look bigger or smaller than its real layout size. Scrolling by the layout numbers alone overshoots (missing content) or undershoots (duplicate content), depending on each book's zoom level.

Fix: compute the ratio between on-screen size and layout size every time, then convert the scroll distance accordingly — this explained the most annoying symptom of all, "some books work, some don't".

The page quietly moves its own scroll while waiting

Scroll to 1200 and wait for the delay. Meanwhile the reader lazy-loads more content and shifts the scroll itself, so the capture isn't at the position requested, and every overlap trim is wrong.

Fix: measure the real position before every capture and compute the overlap from the measured value, not the requested one · and if the position hasn't moved since the last round, the site is pulling the scroll back (scroll-snap / virtual list), so give up instead of capturing the same spot over and over.

Image-only pages have zero characters of text

At first I found the content box by counting characters. With scanned-image books the content box has zero characters, so it wasn't found, and the fallback guessed the biggest box = the wrong box every time.

Fix: measure mainly by on-screen size, not by amount of text · and the duplicate-page signature no longer looks only at "scrollable boxes", because a page too short to scroll gives an empty signature = the detector is silently switched off entirely.

A hundred-screen document kills the tab before the file is ready

Keeping every screen's bitmap until binding at the end meant that on a really long document RAM grew until the tab was killed, leaving nothing.

Fix: bind into PDF pages every 8 screens, then release the bitmaps · but lock the page height from the first screen of the book only, because re-measuring each batch measures screens whose overlap has already been trimmed, giving pages 906 and 899 tall mixed in one book.

Blank pages appear in the middle of reading

Binding midway every 8 screens closed off the leftover tail that didn't fill a page as a page of its own, so a nearly blank page appeared at every bind, like a misprinted book.

Fix: separate final=false (bind only to free RAM) from final=true (actually close the book). The leftover tail of a batch must always carry over to the start of the next batch, never be closed off as a page.

Google Docs is "settled" but hasn't finished drawing

The settle check watched scrollTop/scrollHeight, which had stopped changing. But Docs renders virtualized and hadn't finished drawing the text yet, so a capture at that moment gave a white page.

Fix: allow extra drawing time only in the modes that need it, then measure the position again after waiting, because if the document moves on its own in the meantime the earlier measurement is off and the overlap trim is wrong · plus a minimum 700ms delay so it doesn't hit the captureVisibleTab quota of about 2 calls per second.

Define

Scope I chose not to cover

The hardest decision in this project wasn't code. It was the line I chose not to cross.

An aisle between bookshelves in a library
Content its owners deliberately protect is not what this tool is for · Photo: Zetong Li / Unsplash

Along the way I hit two cases where I stopped and went no further. A library app that sets FLAG_SECURE captures only as black images, which is the content owner saying clearly that capture isn't allowed. Another web viewer layered its content against capture and embedded a forensic watermark with the account owner's email on every page. Both had technical workarounds, but working around them means bypassing measures someone put there on purpose. So the tool states plainly that it is for DRM-free content only.


No DRM bypass

Hit a protection measure = stop, no workaround


Only what is visible

No decryption, no pulling source files from the server


No leftover files

Images stay in memory until they become a PDF, then they're gone


Always a minimum delay

700ms + random timing, easy on both the quota and the server


Level Up · Reflect

Knowledge domains that got stronger

5 areas where my level actually went up through this project

The buildPdf function in offscreen.js writing the PDF structure by hand
The real buildPdf(): Catalog / Pages / Page / XObject DCTDecode and a UTF-16BE /Title, every object written by hand
1. Chrome Extension MV3 — all three contexts talking to each other:

I learned how the popup, the service worker and the offscreen document differ: which ones have a DOM, when each one dies, and why canvas work has to move to offscreen. Plus the limits of chrome.scripting, which can't enter some kinds of iframe. Lesson: MV3 forces you to be clear about where each piece of code runs.

2. Real-world web rendering — virtualized, lazy-load, transform zoom:

I ran into all of it: modern sites don't draw everything up front. They draw only what's near the viewport, move the scroll on their own, and zoom with transforms until the coordinates you read don't match what you see. Lesson: don't trust the value you requested; trust the value you measure at the moment you use it.

3. PDF file structure — writable by hand without a library:

I learned which objects a minimal PDF needs (Catalog / Pages / Page / Contents / XObject), that embedding jpeg with DCTDecode avoids decoding and re-encoding images, and that Thai metadata has to be a UTF-16BE hex string. Lesson: formats that look scary often have a much smaller core than you think.

4. Work under limited memory — stream it, don't pile it up:

I practiced designing a streaming pipeline: collect in batches, bind and release, carry the leftover tail to the next round. It's the same pattern as ordinary batch processing. Lesson: the "tab crashed" problem is solved by the order of work, not by compressing harder.

5. Setting a tool's scope — saying what it won't do as clearly as what it does:

Choosing to stop at DRM meant writing the scope plainly in the README: what kind of content it works with. That turned out to be what makes the tool easy to explain and comfortable to use. Lesson: a tool with no limits isn't more powerful. It's a tool nobody dares to use.

4
capture modes covering every page shape
2
layers of duplicate-page detection
0
PDF libraries
0
image files left on disk

Tan · Natpakan Sirirat

Product Designer & AI Builder — designing user experiences and building AI tools that actually work.

0%