Description
Use the chrome.documentScan API to discover and retrieve images from attached document scanners.
Permissions
documentScanAvailability
Document Scan API
The Document Scan API is designed to allow apps and extensions to view the content of paper documents on an attached document scanner.
Types
CancelScanResponse
Properties
- 
    jobstring Provides the same job handle that was passed to cancelScan().
- 
    resultThe backend's cancel scan result. If the result is OperationResult.SUCCESSorOperationResult.CANCELLED, the scan has been cancelled and the scanner is ready to start a new scan. If the result isOperationResult.DEVICE_BUSY, the scanner is still processing the requested cancellation; the caller should wait a short time and try the request again. Other result values indicate a permanent error that should not be retried.
CloseScannerResponse
Properties
- 
    resultThe result of closing the scanner. Even if this value is not SUCCESS, the handle will be invalid and should not be used for any further operations.
- 
    scannerHandlestring The same scanner handle as was passed to closeScanner.
Configurability
How an option can be changed.
Enum
"NOT_CONFIGURABLE"  "SOFTWARE_CONFIGURABLE"  "HARDWARE_CONFIGURABLE" 
 The option is read-only.
 The option can be set in software.
 The option can be set by the user toggling or pushing a button on the scanner.
ConnectionType
Indicates how the scanner is connected to the computer.
Enum
"UNSPECIFIED"  "USB"  "NETWORK" 
 
 
 
Enum
"INT_RANGE"  "FIXED_RANGE"  "INT_LIST"  "FIXED_LIST"  "STRING_LIST" 
 The constraint on a range of OptionType.INT values. The min, max, and quant properties of OptionConstraint will be long, and its list propety will be unset.
 The constraint on a range of OptionType.FIXED values. The min, max, and quant properties of OptionConstraint will be double, and its list property will be unset.
 The constraint on a specific list of OptionType.INT values. The OptionConstraint.list property will contain long values, and the other properties will be unset.
 The constraint on a specific list of OptionType.FIXED values. The OptionConstraint.list property will contain double values, and the other properties will be unset.
 The constraint on a specific list of OptionType.STRING values. The OptionConstraint.list property will contain DOMString values, and the other properties will be unset.
DeviceFilter
Properties
- 
    localboolean optional Only return scanners that are directly attached to the computer. 
- 
    secureboolean optional Only return scanners that use a secure transport, such as USB or TLS. 
GetOptionGroupsResponse
Properties
- 
    groupsOptionGroup[] optional If resultisSUCCESS, provides a list of option groups in the order supplied by the scanner driver.
- 
    resultThe result of getting the option groups. If the value of this is SUCCESS, thegroupsproperty will be populated.
- 
    scannerHandlestring The same scanner handle as was passed to getOptionGroups.
GetScannerListResponse
Properties
- 
    resultThe enumeration result. Note that partial results could be returned even if this indicates an error. 
- 
    scannersA possibly-empty list of scanners that match the provided DeviceFilter.
OpenScannerResponse
Properties
- 
    optionsobject optional If resultisSUCCESS, provides a key-value mapping where the key is a device-specific option and the value is an instance ofScannerOption.
- 
    resultThe result of opening the scanner. If the value of this is SUCCESS, thescannerHandleandoptionsproperties will be populated.
- 
    scannerHandlestring optional If resultisSUCCESS, a handle to the scanner that can be used for further operations.
- 
    scannerIdstring The scanner ID passed to openScanner().
OperationResult
An enum that indicates the result of each operation.
Enum
"UNKNOWN"  "SUCCESS"  "UNSUPPORTED"  "CANCELLED"  "DEVICE_BUSY"  "INVALID"  "WRONG_TYPE"  "EOF"  "ADF_JAMMED"  "ADF_EMPTY"  "COVER_OPEN"  "IO_ERROR"  "ACCESS_DENIED"  "NO_MEMORY"  "UNREACHABLE"  "MISSING"  "INTERNAL_ERROR" 
 An unknown or generic failure occurred.
 The operation succeeded.
 The operation is not supported.
 The operation was cancelled.
 The device is busy.
 Either the data or an argument passed to the method is not valid.
 The supplied value is the wrong data type for the underlying option.
 No more data is available.
 The document feeder is jammed.
 The document feeder is empty.
 The flatbed cover is open.
 An error occurred while communicating with the device.
 The device requires authentication.
 Not enough memory is available on the Chromebook to complete the operation.
 The device is not reachable.
 The device is disconnected.
 An error has occurred somewhere other than the calling application.
OptionConstraint
Properties
- 
    liststring[] | number[] optional 
- 
    maxnumber optional 
- 
    minnumber optional 
- 
    quantnumber optional 
- 
    type
OptionGroup
Properties
- 
    membersstring[] An array of option names in driver-provided order. 
- 
    titlestring Provides a printable title, for example "Geometry options". 
OptionSetting
Properties
- 
    namestring Indicates the name of the option to set. 
- 
    typeIndicates the data type of the option. The requested data type must match the real data type of the underlying option. 
- 
    valuestring | number | boolean | number[] optional Indicates the value to set. Leave unset to request automatic setting for options that have autoSettableenabled. The data type supplied forvaluemust matchtype.
OptionType
The data type of an option.
Enum
"UNKNOWN"  "BOOL"  "INT"  "FIXED"  "STRING"  "BUTTON"  "GROUP" 
 The option's data type is unknown. The value property will be unset.
 The value property will be one of truefalse.
 A signed 32-bit integer. The value property will be long or long[], depending on whether the option takes more than one value.
 A double in the range -32768-32767.9999 with a resolution of 1/65535. The value property will be double or double[] depending on whether the option takes more than one value. Double values that can't be exactly represented will be rounded to the available range and precision.
 A sequence of any bytes except NUL ('\0'). The value property will be a DOMString.
 An option of this type has no value. Instead, setting an option of this type causes an option-specific side effect in the scanner driver. For example, a button-typed option could be used by a scanner driver to provide a means to select default values or to tell an automatic document feeder to advance to the next sheet of paper.
 Grouping option. No value. This is included for compatibility, but will not normally be returned in ScannerOption values. Use getOptionGroups() to retrieve the list of groups with their member options.
Enum
"UNITLESS"  "PIXEL"  "BIT"  "MM"  "DPI"  "PERCENT"  "MICROSECOND" 
 The value is a unitless number. For example, it can be a threshold.
 The value is a number of pixels, for example, scan dimensions.
 The value is the number of bits, for example, color depth.
 The value is measured in millimeters, for example, scan dimensions.
 The value is measured in dots per inch, for example, resolution.
 The value is a percent, for example, brightness.
 The value is measured in microseconds, for example, exposure time.
ReadScanDataResponse
Properties
- 
    dataArrayBuffer optional If resultisSUCCESS, contains the next chunk of scanned image data. IfresultisEOF, contains the last chunk of scanned image data.
- 
    estimatedCompletionnumber optional If resultisSUCCESS, an estimate of how much of the total scan data has been delivered so far, in the range 0 to 100.
- 
    jobstring Provides the job handle passed to readScanData().
- 
    resultThe result of reading data. If its value is SUCCESS, thendatacontains the next (possibly zero-length) chunk of image data that is ready for reading. If its value isEOF, thedatacontains the last chunk of image data.
ScannerInfo
Properties
- 
    connectionTypeIndicates how the scanner is connected to the computer. 
- 
    deviceUuidstring For matching against other ScannerInfoentries that point to the same physical device.
- 
    imageFormatsstring[] An array of MIME types that can be requested for returned scans. 
- 
    manufacturerstring The scanner manufacturer. 
- 
    modelstring The scanner model if it is available, or a generic description. 
- 
    namestring A human-readable name for the scanner to display in the UI. 
- 
    protocolTypestring A human-readable description of the protocol or driver used to access the scanner, such as Mopria, WSD, or epsonds. This is primarily useful for allowing a user to choose between protocols if a device supports multiple protocols. 
- 
    scannerIdstring The ID of a specific scanner. 
- 
    secureboolean If true, the scanner connection's transport cannot be intercepted by a passive listener, such as TLS or USB. 
ScannerOption
Properties
- 
    configurabilityIndicates whether and how the option can be changed. 
- 
    constraintOptionConstraint optional Defines OptionConstrainton the current scanner option.
- 
    descriptionstring A longer description of the option. 
- 
    isActiveboolean Indicates the option is active and can be set or retrieved. If false, the valueproperty will not be set.
- 
    isAdvancedboolean Indicates that the UI should not display this option by default. 
- 
    isAutoSettableboolean Can be automatically set by the scanner driver. 
- 
    isDetectableboolean Indicates that this option can be detected from software. 
- 
    isEmulatedboolean Emulated by the scanner driver if true. 
- 
    namestring The option name using lowercase ASCII letters, numbers, and dashes. Diacritics are not allowed. 
- 
    titlestring A printable one-line title. 
- 
    typeThe data type contained in the valueproperty, which is needed for setting this option.
- 
    unitThe unit of measurement for this option. 
- 
    valuestring | number | boolean | number[] optional The current value of the option, if relevant. Note that the data type of this property must match the data type specified in type.
ScanOptions
Properties
- 
    maxImagesnumber optional The number of scanned images allowed. The default is 1. 
- 
    mimeTypesstring[] optional The MIME types that are accepted by the caller. 
ScanResults
Properties
- 
    dataUrlsstring[] An array of data image URLs in a form that can be passed as the "src" value to an image tag. 
- 
    mimeTypestring The MIME type of the dataUrls.
SetOptionResult
Properties
- 
    namestring Indicates the name of the option that was set. 
- 
    resultIndicates the result of setting the option. 
SetOptionsResponse
Properties
- 
    optionsobject optional An updated key-value mapping from option names to ScannerOptionvalues containing the new configuration after attempting to set all supplied options. This has the same structure as theoptionsproperty inOpenScannerResponse.This property will be set even if some options were not set successfully, but will be unset if retrieving the updated configuration fails (for example, if the scanner is disconnected in the middle of scanning). 
- 
    resultsAn array of results, one each for every passed-in OptionSetting.
- 
    scannerHandlestring Provides the scanner handle passed to setOptions().
StartScanOptions
Properties
- 
    formatstring Specifies the MIME type to return scanned data in. 
- 
    maxReadSizenumber optional If a non-zero value is specified, limits the maximum scanned bytes returned in a single readScanDataresponse to that value. The smallest allowed value is 32768 (32 KB). If this property is not specified, the size of a returned chunk may be as large as the entire scanned image.
StartScanResponse
Properties
- 
    jobstring optional If resultisSUCCESS, provides a handle that can be used to read scan data or cancel the job.
- 
    resultThe result of starting a scan. If the value of this is SUCCESS, thejobproperty will be populated.
- 
    scannerHandlestring Provides the same scanner handle that was passed to startScan().
Methods
cancelScan()
chrome.documentScan.cancelScan(
job: string,
callback?: function,
): Promise<CancelScanResponse>
Cancels a started scan and returns a Promise that resolves with a CancelScanResponse object. If a callback is used, the object is passed to it instead.
Parameters
- 
    jobstring The handle of an active scan job previously returned from a call to startScan.
- 
    callbackfunction optional The callbackparameter looks like:(response: CancelScanResponse) => void - 
    response
 
- 
    
Returns
- 
            Promise<CancelScanResponse> Promises are only supported for Manifest V3 and later, other platforms need to use callbacks. 
closeScanner()
chrome.documentScan.closeScanner(
scannerHandle: string,
callback?: function,
): Promise<CloseScannerResponse>
Closes the scanner with the passed in handle and returns a Promise that resolves with a CloseScannerResponse object. If a callback is used, the object is passed to it instead. Even if the response is not a success, the supplied handle becomes invalid and should not be used for further operations.
Parameters
- 
    scannerHandlestring Specifies the handle of an open scanner that was previously returned from a call to openScanner.
- 
    callbackfunction optional The callbackparameter looks like:(response: CloseScannerResponse) => void - 
    response
 
- 
    
Returns
- 
            Promise<CloseScannerResponse> Promises are only supported for Manifest V3 and later, other platforms need to use callbacks. 
getOptionGroups()
chrome.documentScan.getOptionGroups(
scannerHandle: string,
callback?: function,
): Promise<GetOptionGroupsResponse>
Gets the group names and member options from a scanner previously opened by openScanner. This method returns a Promise that resolves with a GetOptionGroupsResponse object. If a callback is passed to this function, returned data is passed to it instead.
Parameters
- 
    scannerHandlestring The handle of an open scanner returned from a call to openScanner.
- 
    callbackfunction optional The callbackparameter looks like:(response: GetOptionGroupsResponse) => void - 
    response
 
- 
    
Returns
- 
            Promise<GetOptionGroupsResponse> Promises are only supported for Manifest V3 and later, other platforms need to use callbacks. 
getScannerList()
chrome.documentScan.getScannerList(
filter: DeviceFilter,
callback?: function,
): Promise<GetScannerListResponse>
Gets the list of available scanners and returns a Promise that resolves with a GetScannerListResponse object. If a callback is passed to this function, returned data is passed to it instead.
Parameters
- 
    filterA DeviceFilterindicating which types of scanners should be returned.
- 
    callbackfunction optional The callbackparameter looks like:(response: GetScannerListResponse) => void - 
    response
 
- 
    
Returns
- 
            Promise<GetScannerListResponse> Promises are only supported for Manifest V3 and later, other platforms need to use callbacks. 
openScanner()
chrome.documentScan.openScanner(
scannerId: string,
callback?: function,
): Promise<OpenScannerResponse>
Opens a scanner for exclusive access and returns a Promise that resolves with an OpenScannerResponse object. If a callback is passed to this function, returned data is passed to it instead.
Parameters
- 
    scannerIdstring The ID of a scanner to be opened. This value is one returned from a previous call to getScannerList.
- 
    callbackfunction optional The callbackparameter looks like:(response: OpenScannerResponse) => void - 
    response
 
- 
    
Returns
- 
            Promise<OpenScannerResponse> Promises are only supported for Manifest V3 and later, other platforms need to use callbacks. 
readScanData()
chrome.documentScan.readScanData(
job: string,
callback?: function,
): Promise<ReadScanDataResponse>
Reads the next chunk of available image data from an active job handle, and returns a Promise that resolves with a ReadScanDataResponse object. If a callback is used, the object is passed to it instead.
**Note:**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.
When the scan job completes, the response will have the result value of EOF. This response may contain a final non-zero data member.
Parameters
- 
    jobstring Active job handle previously returned from startScan.
- 
    callbackfunction optional The callbackparameter looks like:(response: ReadScanDataResponse) => void - 
    response
 
- 
    
Returns
- 
            Promise<ReadScanDataResponse> Promises are only supported for Manifest V3 and later, other platforms need to use callbacks. 
scan()
chrome.documentScan.scan(
options: ScanOptions,
callback?: function,
): Promise<ScanResults>
Performs a document scan and returns a Promise that resolves with a ScanResults object. If a callback is passed to this function, the returned data is passed to it instead.
Parameters
- 
    optionsAn object containing scan parameters. 
- 
    callbackfunction optional The callbackparameter looks like:(result: ScanResults) => void - 
    result
 
- 
    
Returns
- 
            Promise<ScanResults> Chrome 96+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks. 
setOptions()
chrome.documentScan.setOptions(
scannerHandle: string,
options: OptionSetting[],
callback?: function,
): Promise<SetOptionsResponse>
Sets options on the specified scanner and returns a Promise that resolves with a SetOptionsResponse object containing the result of trying to set every value in the order of the passed-in OptionSetting object. If a callback is used, the object is passed to it instead.
Parameters
- 
    scannerHandlestring The handle of the scanner to set options on. This should be a value previously returned from a call to openScanner.
- 
    optionsA list of OptionSettingobjects to be applied to the scanner.
- 
    callbackfunction optional The callbackparameter looks like:(response: SetOptionsResponse) => void - 
    response
 
- 
    
Returns
- 
            Promise<SetOptionsResponse> Promises are only supported for Manifest V3 and later, other platforms need to use callbacks. 
startScan()
chrome.documentScan.startScan(
scannerHandle: string,
options: StartScanOptions,
callback?: function,
): Promise<StartScanResponse>
Starts a scan on the specified scanner and returns a Promise that resolves with a StartScanResponse. If a callback is used, the object is passed to it instead. If the call was successful, the response includes a job handle that can be used in subsequent calls to read scan data or cancel a scan.
Parameters
- 
    scannerHandlestring The handle of an open scanner. This should be a value previously returned from a call to openScanner.
- 
    optionsA StartScanOptionsobject indicating the options to be used for the scan. TheStartScanOptions.formatproperty must match one of the entries returned in the scanner'sScannerInfo.
- 
    callbackfunction optional The callbackparameter looks like:(response: StartScanResponse) => void - 
    response
 
- 
    
Returns
- 
            Promise<StartScanResponse> Promises are only supported for Manifest V3 and later, other platforms need to use callbacks.