Urgent.News

What's breaking now, across thousands of outlets.

Tech

What a Browser Extension's Test Suite Cannot Reach

Longshot is a Firefox screenshot extension I wrote to replace FireShot: full page, visible area, drag region and element capture, an editor with eleven annotation tools, export to PNG, JPEG, WebP and PDF, and local OCR that produces a searchable text layer. It has no runtime dependencies. The code is not public, so this is a description rather than an invitation to read it. At one point it had…

Longshot is a Firefox screenshot extension that offers a range of features, including full-page and visible area capturing, drag region capturing, annotation tools, exporting to multiple image formats, and local OCR with searchable text layers. The extension has no runtime dependencies and its code remains private. It has previously achieved 130 passing Node assertions across six suites, with zero failures.

One of the bugs in the extension resides at a boundary between the code and the browser. The printCanvas function encodes each slice of the image as a blob URL and waits for the img.decode() function to resolve. However, this call fails for images inside a display:none subtree, which is created intentionally by the print stylesheet to hide the container on screen.

As a result, the await never returns, and the print dialog never opens. This issue is not detectable by a Node function call and is only reachable by testing the actual browser environment.

Another bug occurs when choosing PDF as the output format. It causes the Open in editor function to fail since deliver() hands the editor a PDF blob, and createImageBitmap cannot decode a PDF. Both the printing and PDF generation stages were separately tested, but the interaction between them was not. This pattern of testing boundaries rather than pure functions is crucial to uncovering such issues.

The author mentions that a complete test suite made of pure functions cannot represent a boundary between the code and the browser. It fails to account for the incorrect shape of what is being covered. The fix for the print issue involved removing the decode step altogether, rather than workarounding it. This removal eliminates the failure class by ensuring there is no loading, decoding, or object URL revoking involved.

The author also highlights the importance of a harness that can detect hangs, such as the timed out after 8 seconds issue reported during testing. Without this verification, the harness becomes as unreliable as the pure-function suites. A test that has never proven to fail is indistinguishable from one that cannot fail, making it impossible to determine which fix was applied.

The OCR harness, which renders known text, recognizes it, and checks the result against ground truth, is an example of a boundary test that can reveal issues inaccessible to unit tests. It assesses not only the correctness of the function's output but also the interaction between the function and the downstream components.

Despite these efforts, the author acknowledges that there is still an unverified boundary in the extension's core component. The capture engines, which handle image conversion and OCR, lack a dedicated browser harness to test their behavior. This blind spot is the largest surface area against the browser that remains unverified in the component with the most browser-coupled code.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

When You Don't Need MCP

The Problem Job postings keep mentioning MCP, as if everyone doing agent development has to know it Some people say MCP is too heavyweight and hardly anyone actually uses it Meanwhile plenty of…

More from Tuesday 8 September →