feat(transport): add sidepanel runtime context support#14
feat(transport): add sidepanel runtime context support#14StyleT merged 3 commits intoStyleT:mainfrom
Conversation
Add sidepanel as a first-class runtime context alongside popup, options, devtools, etc. This enables Chrome's Side Panel API to be used with Pegasus transport without workarounds. Changes: - Add 'sidepanel' to RuntimeContext type union - Add 'sidepanel' to ENDPOINT_RE regex for endpoint deserialization - Add 'sidepanel' to serializeEndpoint's non-tabId context list - Add sidepanel.ts entrypoint (same pattern as popup.ts) - Add ./sidepanel export and typesVersions to package.json - Add sidepanel.ts to tsup-build script - Update README docs to reflect sidepanel support
There was a problem hiding this comment.
Pull request overview
Adds sidepanel as a supported runtime context in @webext-pegasus/transport, including a dedicated entrypoint and updated package exports/docs, so extensions can initialize transport in a semantically correct Side Panel context.
Changes:
- Extend runtime-context typing and endpoint parsing/serialization to recognize
sidepanel. - Add a new
@webext-pegasus/transport/sidepanelentrypoint and wire it into build + exports. - Update READMEs to list sidepanel as supported and document the new entrypoint.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/transport/src/utils/endpoint-utils.ts | Adds sidepanel to endpoint regex and singleton-context serialization list. |
| packages/transport/src/types.ts | Extends RuntimeContext union with 'sidepanel'. |
| packages/transport/src/isInternalEndpoint.ts | Treats sidepanel as an internal endpoint context. |
| packages/transport/sidepanel.ts | New transport initializer entrypoint for sidepanel context. |
| packages/transport/package.json | Adds sidepanel to tsup build inputs, export map, and typesVersions. |
| packages/transport/README.md | Updates supported contexts, entrypoints list, and security note to include sidepanel. |
| packages/rpc/src/types.ts | Extends RPC RuntimeContext union with 'sidepanel'. |
| README.md | Updates root supported contexts list to include sidepanel (no longer “planned”). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const ENDPOINT_RE = | ||
| /^((?:background$)|devtools|popup|options|content-script|window)(?:@(\d+)(?:\.(\d+))?)?$/; | ||
| /^((?:background$)|devtools|popup|sidepanel|options|content-script|window)(?:@(\d+)(?:\.(\d+))?)?$/; | ||
|
|
There was a problem hiding this comment.
ENDPOINT_RE allows endpoints without an @tabId suffix (e.g. sidepanel, popup, background). In deserializeEndpoint, those cases currently produce tabId: NaN (because +tabId where tabId is undefined), which violates Endpoint.tabId: number | null and can leak into routing logic (e.g. deserializeEndpoint(connArgs.endpointName) in background.ts). Consider setting tabId to null when the capture group is missing (and optionally rejecting missing tabId for contexts that require it).
| | 'devtools' | ||
| | 'background' | ||
| | 'popup' | ||
| | 'sidepanel' |
There was a problem hiding this comment.
RuntimeContext now includes 'sidepanel', but packages/rpc/README.md still lists sidepanel as "planned". Either update the RPC README to reflect current support, or (if RPC isn’t intended to support sidepanel yet) avoid advertising it via the public RuntimeContext type until the rest of the RPC surface is ready.
| | 'sidepanel' |
Summary
Adds
sidepanelas a first-class runtime context for@webext-pegasus/transport, implementing the planned sidepanel support noted in the README.Chrome's Side Panel API is now widely adopted, and extensions using Pegasus currently have to work around the missing context by importing from
@webext-pegasus/transport/popup— which works but is semantically incorrect and could cause issues if context-specific routing is ever added.Changes
src/types.ts— Add'sidepanel'to theRuntimeContextunion typesrc/utils/endpoint-utils.ts— AddsidepaneltoENDPOINT_REregex andserializeEndpoint's non-tabId context list (sidepanel, like popup, is a singleton context without tab association)sidepanel.ts— New entrypoint following the same pattern aspopup.ts, using'sidepanel'as the context identifierpackage.json— Addsidepanel.tsto tsup-build, add./sidepanelexport map entry, addtypesVersionsentryREADME.md(root + transport) — Update supported contexts, available entrypoints list, and security notesUsage