connect.notifications
OS toast notifications β create, clear, and onClicked.
Show OS-level toast notifications. Per instance, up to 10 live at a time; reusing an id replaces the existing toast.
- Capability:
notifications - Namespace:
connect.notifications
public/docs-img/extensions/notification.pngWalkthrough
Notify on completion, and react to a click.
- Declare
notifications:{ "capabilities": ["notifications"] } - Show a toast and keep its id:
const { id } = await connect.notifications.create({ title: 'Done', message: 'Export ready.' }); - Handle a click with
onClicked. - Update progress by reusing the same
id(replaces the toast).
Methods
notifications.create(options)
Show a toast.
How to use it
- Pass at least a
title; addmessage/iconUrlas needed. - Reuse an
idto replace a live toast (e.g. progress); read{ id, shown }.
Signature β connect.notifications.create({ id?, title, message?, iconUrl?, buttons? })
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
id | string | no | Reuse an id to replace that toast; omit for a new one. |
title | string | yes | The heading. |
message | string | no | Body text. |
iconUrl | string | no | An extension-relative icon. |
buttons | { title }[] | no | Up to 2 buttons. Rendered where the OS notifier supports actions (macOS); accepted and validated identically everywhere. Clicks arrive via onButtonClicked. |
Returns β Promise<{ id, shown }> β shown: false on a headless host.
const { id } = await connect.notifications.create({
title: 'Done', message: 'Your export is ready.',
});notifications.clear(id)
Close a toast.
How to use it
- Pass the
idreturned bycreateto dismiss it.
Signature β connect.notifications.clear(id) Β· Returns Promise<void>.
Events
notifications.onClicked(cb)
Fires when the user clicks one of your toasts. Wakes a suspended background.
How to use it
- Subscribe once.
- Match the
{ id }back to what the toast was about, and act.
Payload β { id }.
connect.notifications.onClicked(({ id }) => focusRelated(id));notifications.onButtonClicked(cb)
Fires when the user clicks one of your toast's buttons. Wakes a suspended background.
How to use it
- Create the toast with
buttons: [{ title: 'Open' }, { title: 'Dismiss' }]. - Subscribe once; branch on
buttonIndex(0-based, matching yourbuttonsarray).
Payload β { id, buttonIndex }.
const { id } = await connect.notifications.create({
title: 'Export ready', buttons: [{ title: 'Open' }, { title: 'Dismiss' }],
});
connect.notifications.onButtonClicked(({ id, buttonIndex }) => {
if (buttonIndex === 0) openExport(id);
});Edge cases
- Buttons render where the OS notifier supports actions (macOS today); on other
platforms the toast shows without them and
onButtonClickedsimply never fires β keeponClickedas the universal path.
Notes
- Keep to 10 live toasts; beyond that, older ones are dropped. Replace-by-id is the way to update a running notification (e.g. progress).
