Extension API Callback Parameters, Signatures, and Response Types
How extension API callback parameters work: optional vs required, typed response signatures, nested handlers, and documented limits.
This page summarises how the Chrome extension platform documents the callback parameter on browser.* and chrome.* APIs. Across dozens of reference pages, the same pattern appears: many methods are asynchronous, and completion or data is delivered through a JavaScript function whose parameter types are spelled out in the reference. The cluster material is almost entirely parameter excerpts from those references; the goal here is to explain that pattern once, with the exceptions that actually change how you call an API.
callback on extension APIs: what it is and when you need it
Section titled “callback on extension APIs: what it is and when you need it”A callback on an extension API method is a function the browser invokes when an operation finishes or when event-style APIs deliver payload data. In the reference, it is typed as function, and many entries add optional, meaning you may omit the callback if you do not need the result.
The callback parameter looks like:
(devices: AudioDeviceInfo[]) => void— Google, browser.audio
The plain-language reason people look this up: they are calling something like chrome.management.get() or chrome.cookies.getAll() and need to know what arguments the callback receives and whether the call is valid without a callback. The reference answers that per method under Parameters, not in one global “callbacks” guide—so understanding the shared pattern saves repeated doc hunting.
| Pattern in the reference | Typical meaning |
|---|---|
callback → function (no optional) |
You should supply a callback; the method documents a non-optional completion path |
callback → function optional |
Callback may be omitted |
Callback type ( ) => void |
Success-only notification; no payload |
Callback type (info: SomeType) => void |
Single structured result |
Callback type (items: SomeType[]) => void |
List result |
Examples of required callbacks in this cluster include browser.tabCapture ((stream: LocalMediaStream) => void), browser.declarativeNetRequest debug-style handlers ((info: MatchedRuleInfoDebug) => void), and several event listeners under chrome.serial and socket APIs where the callback is not marked optional.
Callback signatures: how results are typed in the reference
Section titled “Callback signatures: how results are typed in the reference”The reference does not use Promises in these excerpts; it documents callback-last (or callback-only) invocation. The authoritative shape is always the line “The callback parameter looks like:” followed by a typed arrow function.
Single object results (info, result, response)
Section titled “Single object results (info, result, response)”Management, storage, VPN, and similar APIs pass one object (or a typed alias) to the callback:
The callback parameter looks like:
(info: ExtensionInfo) => void— Google, browser.management
The same ExtensionInfo pattern appears on chrome.management for multiple methods—use the specific method page for extra parameters (for example id or options), but expect the callback typing to name the payload type explicitly.
Array results (devices, alarms, printers)
Section titled “Array results (devices, alarms, printers)”List-returning methods document array element types in the callback:
The callback parameter looks like:
(alarms: Alarm[]) => void— Google, chrome.alarms
The callback parameter looks like:
(devices: AudioDeviceInfo[]) => void— Google, chrome.audio
When a method also accepts a filter object, the docs often state that an unset or empty filter returns the full set—for example audio devices when filter is not set or is {}.
Completion-only callbacks with no arguments
Section titled “Completion-only callbacks with no arguments”Many write operations and simple getters use an empty callback signature:
The callback parameter looks like:
() => void— Google, browser.contextMenus
The same () => void pattern appears on chrome.bookmarks, chrome.gcm, and numerous clear / remove / update methods across the cluster.
Optional callback arguments inside the signature
Section titled “Optional callback arguments inside the signature”Some callbacks pass optional values, which matters for branching logic:
The callback parameter looks like:
(launchData?: LaunchData) => void— Google, chrome.app.runtime
The callback parameter looks like:
(wasCleared?: boolean) => void— Google, chrome.alarms
Treat ? in the documented signature as “may be undefined,” not as permission to ignore documented error conditions on the calling side.
Nested callbacks: when one handler passes another
Section titled “Nested callbacks: when one handler passes another”A smaller set of APIs documents two stages: your outer callback runs first and receives a second function you must call to deliver or receive the real payload. browser.printerProvider and chrome.printerProvider are the clearest examples in this cluster.
The callback parameter looks like:
(printerId: string, resultCallback: function) => void— Google, browser.printerProvider
The nested resultCallback is itself typed:
The resultCallback parameter looks like:
(capabilities: object) => void— Google, browser.printerProvider
with capabilities described as device capabilities in CDD format. Another variant passes optional printer info:
The resultCallback parameter looks like:
(printerInfo?: PrinterInfo) => void— Google, browser.printerProvider
For USB-backed discovery, the outer callback receives a usb.Device plus resultCallback. When implementing a provider, read the whole method block on the printer provider page: the outer and inner signatures differ per entry point (onGetCapability, onGetPrinters, onGetUsbPrinterInfo).
Documented limits and special callback semantics
Section titled “Documented limits and special callback semantics”Several APIs attach conditions next to the callback typing. These are easy to miss if you only copy the arrow function.
Permissions: boolean results with an origin caveat
Section titled “Permissions: boolean results with an origin caveat”chrome.permissions documents explicit boolean semantics in the parameter list, not only in prose elsewhere:
True if the extension has the specified permissions. If an origin is specified as both an optional permission and a content script match pattern, this will return false unless both permissions are granted.
— Google, chrome.permissions
The contains callback is (result: boolean) => void; request uses (granted: boolean) => void; remove uses (removed: boolean) => void. The getAll callback returns (permissions: Permissions) => void, with a note that origins aggregates manifest permissions, optional permissions, and content-script match patterns.
Storage: usage and serialization affect what you do in the callback
Section titled “Storage: usage and serialization affect what you do in the callback”On StorageArea, getBytesInUse documents:
Amount of space being used in storage, in bytes.
— Google, StorageArea
with callback (bytesInUse: number) => void. For set, the docs warn that values you store affect what you read back later:
Primitive values such as numbers will serialize as expected. Values with a typeof “object” and “function” will typically serialize to , with the exception of Array (serializes as expected), Date, and Regex (serialize using their String representation).
— Google, StorageArea
Platform and API constraints called out beside callbacks
Section titled “Platform and API constraints called out beside callbacks”chrome.bluetooth states that filtering returned devices is limited:
Some criteria to filter the list of returned bluetooth devices. If the filter is not set or set to , returned device list will contain all bluetooth devices. Right now this is only supported in ChromeOS, for other platforms, a full list is returned.
— Google, chrome.bluetooth
chrome.audio notes that for setActiveDevices, It is an error to pass in a non-existent device ID. The success callback remains () => void, so failures are not represented in the callback signature—you must rely on runtime error reporting and validation before calling.
chrome.networking.onc documents that shared: true for network configuration is only exposed to Chrome’s Web UI; when called by apps, false is the only allowed value—relevant when wiring callbacks that receive a result string or void completion.
Version-gated parameters
Section titled “Version-gated parameters”Some parameter blocks include minimum Chrome versions next to options or callbacks (for example chrome.omnibox setDefaultSuggestion with Chrome 100+, or chrome.declarativeNetRequest update APIs with Chrome 87+ / Chrome 89+). The callback shape may be unchanged while surrounding options are version-gated—always check the method you call, not a sibling method in the same file.
chrome.* (Manifest V2) vs browser.* (extensions reference)
Section titled “chrome.* (Manifest V2) vs browser.* (extensions reference)”This cluster includes parallel surfaces:
browser.*pages under Extensions API reference (for example browser.sidePanel, browser.webAuthenticationProxy).chrome.*pages under MV2 reference and Chrome Apps reference (legacy app APIs such as chrome.bluetoothSocket, chrome.fileSystem).
For the same feature, callback typings are often identical between browser and chrome (compare browser.tabCapture and chrome.tabCapture: both use (stream: LocalMediaStream) => void for capture with CaptureOptions). Your manifest version and namespace (chrome vs browser in MV3 service workers) determine which page applies; the callback documentation style is the same.
Side panel lifecycle callbacks are documented on browser.sidePanel as distinct payload types:
(info: PanelClosedInfo) => void— Google, browser.sidePanel
and
(info: PanelOpenedInfo) => void— Google, browser.sidePanel
Common mistakes when using documented callbacks
Section titled “Common mistakes when using documented callbacks”- Assuming every callback is optional. Event listeners and several capture/provider APIs mark
callbackas requiredfunctionwithoutoptional(browser.tabCapture, chrome.hidonDeviceAdded, chrome.mdns service list callbacks). - Ignoring inner
resultCallbackin provider APIs. Calling only the outer handler without invoking the nested callback can leave the platform waiting (printerProvider). - Treating “filter optional” as “no platform limits.” Bluetooth filtering behaviour differs by platform despite similar callback types (chrome.bluetooth).
- Expecting error objects in the callback type. Many methods only document success paths (
() => voidor a typed info object); separate APIs (for example socketReceiveErrorInfocallbacks on chrome.sockets.tcp) use different events for errors. - Mixing permission models. Relying on
permissions.containswithout accounting for dual optional-origin and content-script patterns yields false negatives (chrome.permissions).
Representative entry points if you are mapping many callbacks at once: chrome.runtime (platform info, update check, background page), chrome.declarativeNetRequest (rule maintenance and matched-rule debug info), chrome.devtools.network (HAR log object callback), and browser.webAuthenticationProxy (CreateRequest / GetRequest request info).
How to check this on your site
Section titled “How to check this on your site”-
Open the API your extension calls (for example chrome.permissions or browser.management) and confirm the method’s
callbackline matches what your code expects. -
Load your extension as an unpacked build and trigger the API path; in the service worker or background context, log the callback arguments and compare them to the documented types on the same reference page (chrome.tabCapture, chrome.storage StorageArea).
-
For provider-style APIs, set a breakpoint in both the outer callback and the nested
resultCallbackand verify both are invoked (browser.printerProvider). -
If behaviour depends on platform notes (Bluetooth filter, ONC
sharedflag), re-read the parameter bullets on chrome.bluetooth or chrome.networking.onc on the OS you target. -
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 does not match the official reference or you need a clarification on a specific method’s callback typing, write to yimasynthetic@gmail.com with the page URL and the exact statement or API link you are asking about.