ExtensionsAPI reference
connect.downloads
Start your own downloads and observe only them.
Start your own downloads and observe only them. Deliberately narrower than Chrome: there is no surveillance of the user's downloads — an extension sees its own and nothing else.
- Capability:
downloads - Namespace:
connect.downloads
Walkthrough
Download a file and know when it's done.
- Declare
downloads:{ "capabilities": ["downloads"] } - Start the download and keep its id:
const { id } = await connect.downloads.download({ url, filename: 'report.pdf' }); - Watch for completion with
onChanged(you only hear about your downloads).
Methods
downloads.download(options)
Start a download.
How to use it
- Pass a
url(and optionalfilename— it's basename-sanitised). await{ id }; track completion viaonChanged.
Signature — connect.downloads.download({ url, filename? })
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
url | string | yes | What to download. |
filename | string | no | Suggested name; basename-sanitised (no path traversal). |
Returns — Promise<{ id }>. Saves silently into the OS downloads directory.
const { id } = await connect.downloads.download({
url: 'https://example.com/report.pdf',
filename: 'report.pdf',
});Events
downloads.onChanged(cb)
Fires as your downloads progress to a terminal state.
How to use it
- Subscribe once.
- Match
idto a download you started; onstate: 'completed', usepath.
Payload
| Field | Type | Description |
|---|---|---|
id | number | The download id. |
state | 'completed' | 'interrupted' | Terminal state. |
path | string? | Final path on completion. |
connect.downloads.onChanged(({ id, state, path }) => {
if (state === 'completed') console.log('saved', path);
});Notes
- You only ever hear about downloads you started — never the user's or another extension's.
- The file lands in the OS downloads dir;
filenameis a basename, so you can't write outside it.