connect.ui
Popup resize, context menus (ui.menus), and the side panel (ui.sidePanel).
Surface-level UI: resize your popup, add context-menu items, and drive the side panel. Each part has its own capability (or none).
- Capabilities: none (
setPopupSize),contextMenus(ui.menus),sidePanel(ui.sidePanel) - Namespace:
connect.ui
Walkthrough
Add a right-click action and a fit-to-content popup.
- For a context-menu item, declare
contextMenus, then create the item at background boot and handle clicks:connect.ui.menus.create({ id: 'save', title: 'Save', contexts: ['link'] }); connect.ui.menus.onClicked(({ menuItemId, linkUrl }) => menuItemId === 'save' && save(linkUrl)); - For a popup that fits its content, call
setPopupSizeon resize (no capability). - For the side panel, declare
sidePanelandopen()/close()it.
ui.setPopupSize(size)
Resize the open action popup. No capability — it's your own surface. The shell clamps
to the manifest bounds (150–800 × 100–600) and animates unless { animate: false }.
How to use it
- In the popup, observe your content's size.
- Call
setPopupSize({ height })(and/orwidth) as it grows.
Signature — connect.ui.setPopupSize({ width?, height?, animate? })
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
width | number | no | New width (clamped to manifest bounds). |
height | number | no | New height (clamped). |
animate | boolean | no | Animate the resize (default true). |
Returns — Promise<void>.
new ResizeObserver(() =>
connect.ui.setPopupSize({ height: document.body.scrollHeight })
).observe(document.body);ui.menus — context menus
Contribute items to the browsing tab's right-click menu. Capability: contextMenus.
Menu items are runtime state — recreate them at background boot.
public/docs-img/extensions/context-menu.pngui.menus.create(item)
How to use it
- Recreate items at background boot (they don't persist).
- Pass a unique
id, atitle, and thecontextsit applies to.
Signature — connect.ui.menus.create({ id, title, contexts?, enabled? })
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
id | string | yes | Unique id. Errors on a duplicate. |
title | string | yes | Menu label. |
contexts | string[] | no | 'page', 'selection', 'link', 'image', 'all'. |
enabled | boolean | no | Start enabled/disabled. |
Returns — Promise<void>.
ui.menus.update(item)
Update an item (Chrome-style, separate from create).
How to use it
- Pass the item
idwith the fields to change.
Signature — connect.ui.menus.update({ id, title?, contexts?, enabled? }) · Returns
Promise<void>.
ui.menus.remove(id) · ui.menus.removeAll()
Remove one item or all of them.
How to use it
remove(id)for one,removeAll()to clear yours.
Returns — Promise<void>.
ui.menus.onClicked(cb)
Fires when one of your items is clicked. Delivered to your extension only; wakes a suspended background.
How to use it
- Subscribe once (at boot).
- Branch on
menuItemId; uselinkUrl/selectionText/pageUrlfrom the payload.
Payload
| Field | Type | Description |
|---|---|---|
menuItemId | string | Which item. |
pageUrl | string | The page. |
linkUrl | string? | If clicked on a link. |
selectionText | string? | If a selection context. |
mediaType | string? | If an image/media context. |
tabId | number | The tab. |
connect.ui.menus.create({ id: 'save', title: 'Save with My Extension', contexts: ['link'] });
connect.ui.menus.onClicked(({ menuItemId, linkUrl }) => {
if (menuItemId === 'save') save(linkUrl);
});ui.sidePanel — the side panel
Own a docked panel surface. Capability: sidePanel.
Declare the surface in the manifest and every extension that has one gets a tab on
the panel rail (the slim strip on the right edge of the window) — so users can open
your panel directly, without you calling anything. Clicking the tab docks your panel as
a drawer; clicking it again hides it. open() / close() are for driving it from code
(e.g. opening it in response to a toolbar click).
"ui": { "sidePanel": { "entry": "panel.html" } },
"capabilities": ["sidePanel"]public/docs-img/extensions/side-panel-rail.pngui.sidePanel.open() · ui.sidePanel.close()
How to use it
- Declare
ui.sidePanel.entryin the manifest and thesidePanelcapability. open()/close()to show or hide the drawer from code — or let the user open it from the panel rail.
Signature — connect.ui.sidePanel.open() / connect.ui.sidePanel.close() ·
Returns Promise<void>.
connect.ui.sidePanel.open();Notes
- Context-menu items don't persist across a background restart — recreate them from
runtime.onInstalled/ at boot. - The side panel's content is a normal extension surface declared in
ui.sidePanel.entry; this namespace only opens/closes it.

