Extension Document Scan API: Scanner Discovery, Options and Scan Jobs
How Chrome's documentScan API lets extensions discover scanners, set device options, and retrieve scanned images with scan() or the full job flow.
This page summarizes Chrome’s documentScan API reference for extensions and apps that need images from attached document scanners. The same API is exposed as chrome.documentScan in Manifest V2 (MV2 reference) and as browser.documentScan in cross-browser extension code; behavior and method names match across those namespaces.
Use the chrome.documentScan API to discover and retrieve images from attached document scanners.
The Document Scan API is designed to allow apps and extensions to view the content of paper documents on an attached document scanner.
— Chrome, documentScan API
documentScan permission: what extensions must declare
Section titled “documentScan permission: what extensions must declare”Extensions need the documentScan permission in the manifest before any API call is allowed.
documentScan
— Chrome, documentScan API — Permissions
Without it, discovery and scan methods are unavailable. Pair this permission with a clear in-product explanation when the user is about to scan, because scanning uses local hardware the user physically controls.
scan() vs multi-step flow: when to use simple vs complex scanning
Section titled “scan() vs multi-step flow: when to use simple vs complex scanning”You choose between two patterns depending on whether you need to control scanner-specific settings.
Simple scan(): one call when any scanner and defaults are enough
Section titled “Simple scan(): one call when any scanner and defaults are enough”For cases that work with any scanner and do not require configuration control, call scan() with a ScanOptions object. It resolves to ScanResults. Capabilities are limited to how many scans you allow and which MIME types the caller accepts; results come back as URLs suitable for a `<img>` tag.
For simple use cases, meaning those that can work with any scanner and don’t require control of configuration, call scan(). This method takes a ScanOptions object and returns a Promise that resolves with a ScanResults object. The capabilities of this option are limited to the number of scans and the MIME types that will be accepted by the caller. Scans are returned as URLs for display in an <img> tag for a user interface.
— Chrome, documentScan API — Simple scanning
Use ScanOptions.maxImages (default 1) and optional mimeTypes to constrain output. ScanResults exposes dataUrls (image src values) and mimeType.
Complex scanning: discovery, open, options, then job-based read
Section titled “Complex scanning: discovery, open, options, then job-based read”When you must pick a device, set resolution, source (flatbed vs ADF), scan area, or other driver-specific options, use the three-phase flow: discovery → scanner configuration → scanning. The reference explicitly warns that calling openScanner(), getScannerList(), or startScan() again cancels operations started by an earlier call to the same method—design UI and retries around that rule.
| Phase | Main methods | Outcome |
|---|---|---|
| Discovery | getScannerList() |
ScannerInfo[], choose scannerId |
| Configuration | openScanner(), setOptions(), optional getOptionGroups() |
scannerHandle, device options applied |
| Scanning | startScan(), readScanData(), closeScanner() or cancelScan() |
Image chunks as ArrayBuffer, then release handle |
getScannerList(): how to discover attached document scanners
Section titled “getScannerList(): how to discover attached document scanners”Call getScannerList() with an optional DeviceFilter. The promise resolves to GetScannerListResponse containing scanners (ScannerInfo[]). The list may be empty even when result indicates an error—always inspect OperationResult and the array together.
Call getScannerList(). Available scanners are returned in a Promise that resolves with a GetScannerListResponse.
The response object contains an array of ScannerInfo objects. The array may contain multiple entries for a single scanner if that scanner supports multiple protocols or connection methods.
Select a scanner from the returned array and save the value of its scannerId property.
— Chrome, documentScan API — Discovery
DeviceFilter: local vs secure scanners only
Section titled “DeviceFilter: local vs secure scanners only”| Property | Effect |
|---|---|
local |
When true, only scanners directly attached to the computer |
secure |
When true, only scanners using secure transport (for example USB or TLS) |
ScannerInfo fields that matter for UI and later calls include scannerId, deviceUuid (same physical device may appear multiple times), imageFormats (MIME types you may pass to startScan), protocolType (for example Mopria, WSD), manufacturer, model, name, and secure.
openScanner() and setOptions(): how to configure scanner before scan
Section titled “openScanner() and setOptions(): how to configure scanner before scan”openScanner(): exclusive handle and option map
Section titled “openScanner(): exclusive handle and option map”Pass the saved scannerId to openScanner(). On OperationResult.SUCCESS, store scannerHandle and read the options object—a device-specific map of ScannerOption instances (keys such as source, resolution).
Call openScanner(), passing in the saved scanner ID. It returns a Promise that resolves with an OpenScannerResponse. The response object contains:
A scannerHandle property, which you’ll need to save.
An options property containing scanner-specific properties, which you’ll need to set.
— Chrome, documentScan API — Scanner configuration
Response fields such as scannerHandle and options are only populated when result is SUCCESS—the same conditional pattern applies across most API responses.
setOptions(): OptionSetting array and interdependent constraints
Section titled “setOptions(): OptionSetting array and interdependent constraints”Build OptionSetting[] entries with name, type (OptionType), and value matching the real option type. Pass them to setOptions(handle, options). SetOptionsResponse returns per-option results and an updated options map.
Since changing one option can alter constraints on another option, you may need to repeat these steps several times.
— Chrome, documentScan API — Scanner configuration
Each ScannerOption exposes metadata (title, description, constraint, configurability, isActive, isAdvanced, isAutoSettable, and others). Option names use lowercase ASCII letters, numbers, and dashes only.
getOptionGroups(): show manufacturer option groups in the UI
Section titled “getOptionGroups(): show manufacturer option groups in the UI”Optional but useful for settings screens: after openScanner(), call getOptionGroups(scannerHandle) and lay out options under driver-defined title / members lists (for example a “Standard” group containing resolution, mode, source).
Some scanners group options in device-specific ways. They don’t affect option behaviors, but since these groups may be mentioned in a scanner’s product documentation, such groups should be shown to the user. You can retrieve these groups by calling getOptionGroups().
After each setOptions(), refresh the UI from SetOptionsResponse.options because constraints may have changed.
startScan() and readScanData(): how to read scan image data in chunks
Section titled “startScan() and readScanData(): how to read scan image data in chunks”startScan(): job handle and output format
Section titled “startScan(): job handle and output format”Call startScan(scannerHandle, startScanOptions). StartScanOptions.format must be one of the MIME types listed on that scanner’s ScannerInfo.imageFormats. Optional maxReadSize caps bytes per readScanData response (minimum 32768 when set).
On success, save job from StartScanResponse for reading or cancellation.
readScanData(): SUCCESS with empty data, EOF, and Blob assembly
Section titled “readScanData(): SUCCESS with empty data, EOF, and Blob assembly”Repeatedly call readScanData(job) until result is EOF or an error. While result is SUCCESS, data may be an ArrayBuffer chunk; estimatedCompletion (0–100) estimates progress. Empty data on SUCCESS means hardware is still working—wait briefly and call again.
Note: If result is SUCCESS, but data is empty, delay briefly before calling readScanData() again.
— Chrome, documentScan API — Scanning
It is valid for a response result to be SUCCESS with a zero-length data member. This means the scanner is still working but does not yet have additional data ready. The caller should wait a short time and try again.
— Chrome, readScanData()
Concatenate chunks into a Blob (see Retrieve a page as a blob on the reference page). When finished, call closeScanner(handle)—the handle becomes invalid even if closeScanner does not return SUCCESS. cancelScan(job) ends an in-flight job; on DEVICE_BUSY, wait and retry cancellation.
OperationResult: how to interpret API response results
Section titled “OperationResult: how to interpret API response results”Most methods return a result field of type OperationResult. Dependent properties (handles, data, options) appear only for specific result values—check the reference for each response type.
For cancelScan, SUCCESS or CANCELLED means the scanner can start a new scan; DEVICE_BUSY is transient; other values are permanent errors and should not be retried.
For readScanData, SUCCESS yields the next chunk (possibly zero-length); EOF yields the final chunk. Anything else should end the read loop and surface an error.
Common mistakes when using documentScan in extensions
Section titled “Common mistakes when using documentScan in extensions”- Using
scan()while needing ADF, crop, or resolution — switch toopenScanner/setOptions/startScan; simplescan()cannot drive per-device configuration. - Ignoring duplicate
ScannerInforows — matchdeviceUuidand let the user pickprotocolTypewhen one device exposes multiple protocols. - Assuming
getScannerListfailure means no hardware — partialscannersmay still be returned whenresultindicates an error. - Treating empty
readScanDataas failure — poll with a short delay onSUCCESSand zero-lengthdata. - Reusing
scannerHandleaftercloseScanner— always treat the handle as invalid after close, regardless ofresult. - Wrong
OptionSetting.typeorvalueshape — must match the underlyingScannerOption.type; useconstraint.list(as in the letter-size example on the reference) for allowed values. - MIME mismatch on
startScan—formatmust appear in that scanner’simageFormats, not only in your extension’s preferred types.
Letter-size page example (geometry and ADF source)
The reference’s Scan one letter-size page shows getScannerList({ secure: true }), opening the first scanner, choosing an ADF source from constraint.list, setting tl-x / br-x / tl-y / br-y in millimeters for 8.5×11”, then pageAsBlob() and closeScanner(). Use it as a template for geometry options naming on your driver.
How to check this on your site
Section titled “How to check this on your site”-
Confirm the extension manifest includes the
documentScanpermission and matches the manifest version your code targets (MV2chrome.documentScanvs MV3 /browser.documentScanpromises as described in the MV2 reference and current API reference). -
On a machine with a supported scanner attached, load the extension unpacked in Chrome and run
getScannerList({ secure: true })(or your production filter); verify at least oneScannerInfoand thatimageFormatslists the MIME type you pass tostartScan. -
Exercise the path you ship: either
scan()returningdataUrls, or the full open →setOptions→startScan→readScanDataloop untilEOF, then confirmcloseScannerinvalidates the handle on a second operation. -
Deliberately call
readScanDatawhile the scanner is busy and confirm your code waits on zero-lengthSUCCESSchunks instead of failing immediately. -
You can check automatically in Answerwell (our tool): https://answerwell.org/workspace
Report an error or ask a question
Section titled “Report an error or ask a question”If something on this page disagrees with the documentScan API reference or your scanner behavior, email yimasynthetic@gmail.com with the page URL and the exact statement you believe is wrong or unclear.