1. Minimal Host Permissions
Declare only the exact domains your API and CDN use inside permissions.hosts. Every user sees this list during Permission Review before enabling your extension.
Write one CommonJS script and run it natively on Apple (JavaScriptCore), Android (QuickJS), and Windows (Jint) with zero WebViews (ノ◕ヮ◕)ノ*:・゚✧
Every Musico extension exports a manifest plus async/sync CommonJS hooks on module.exports. Depending on the capabilities you declare, your plugin plugs directly into one or more native workflows:
"playlist", "tree", "stream"): Joins the same CloudSourceProvider pipeline as YouTube, Bilibili, and Google Drive, automatically getting Save to Local Folder, Update from Cloud, Playlists, and custom badgeLabel pills."search"): Unlocks the opt-in Search Source Switcher in Songs (hidden when no search extensions are enabled), ephemeral playback excluded from Library & Stats, and playlist/album preview sheets."lyrics"): Appears inside Lyrics → Search Online… alongside LRCLIB and NetEase, never running automatically during playback.Toggle the capabilities your source needs and immediately copy or download a working API v1 CommonJS starter script plus its CLI test command.
| Format | Structure | Best For |
|---|---|---|
Single-File (.musico.js) |
One JS file exporting { manifest, ...hooks } on module.exports. |
Quick scripts, simple sources, easy sharing. |
Bundle Archive (.musicoext) |
Standard .zip with manifest.json, index.js (or manifest.entry), and optional icon.png. |
Extensions with icons, assets, or multi-file packaging. |
Multi-Plugin Pack (.zip) |
ZIP containing multiple *.musicoext bundles (such as musico-plugins-all.zip). |
One-URL community plugin suites with per-plugin updateUrl. |
Inside Musico, packages extract to <AppData>/Extensions/<id>/ (or .\Data\Extensions\<id>\ in Windows Portable mode). ZIP importers enforce path traversal rejection (no ../ or absolute paths), max 256 entries, and max 16 MB uncompressed size.
| Field | Type | Required | Constraints & Notes |
|---|---|---|---|
apiVersion | integer | Yes | Must be 1. |
id | string | Yes | Reverse-DNS matching ^[a-z0-9._-]{3,64}$. Stored on roots as providerID = "ext.<id>". |
name | string | Yes | Display name in Extension Manager, Cloud Folder picker, and Search/Lyrics switchers. |
version | string | Yes | SemVer (MAJOR.MINOR.PATCH). |
author / description | string | No | Shown in Extension Manager detail sheet. |
badgeLabel | string | No | Short pill badge in Folders, Search chips & Lyrics (defaults to name, max 16 chars). |
entry | string | No | Relative script path inside .musicoext (defaults to "index.js"). |
updateUrl | string | No | HTTPS URL to a .musicoext package for automatic and manual updates (falls back to import URL). |
capabilities | string[] | Yes | Non-empty subset of "playlist", "tree", "stream", "cookie", "proxy", "lyrics", "search", "qr_login". |
urlPatterns | string[] | Conditional | Native regex strings tested before starting a JS VM. Required when "playlist" or "tree" is declared. |
searchKinds | string[] | No | Subset of "track", "playlist", "album" (defaults to all three when "search" is declared). |
permissions.hosts | string[] | Conditional | Exact domain (example.com) or *.sub.domain (≥ 2 labels after *.; bare * & *.tld rejected). May be empty if settings has "server_url". |
qualities | array | No | Up to 16 audio quality objects { id, label, badge?, lossless? }; paired with defaultStreamQuality & defaultDownloadQuality. |
settings | array | No | { key, label, type, default, options? } where type is "boolean", "string", "select", or "server_url" (dynamically allows that user host). |
canHandle(input) (sync, required for "playlist" / "tree"): input { rawText, extractedUrl } → returns { matched, normalizedUrl?, remoteId?, kind?: "playlist" | "folder" | "track" }.fetchCollection(ctx, req) (async, required for "playlist" / "tree" & search previews): input { url, cookie?, cursor? } → returns { remoteId, title, tracks: ExtTrack[], subfolders?: ExtSubfolder[], nextCursor? }.fetchFolder(ctx, req) (async, required for "tree"): input { folderId, pathSegments, depth, cookie?, cursor?, extra? } → returns { folderId, tracks: ExtTrack[], subfolders?: ExtSubfolder[], nextCursor? }.resolveStream(ctx, req) (async, required for "stream"): input { remoteTrackId, relativePath?, cookie?, forceRefresh, quality?, purpose?: "stream" | "download" } → returns { url, headers?, fileExtension, mimeType?, expiresAtMs?, fallbackUrls?, contentLength?, actualQuality?, qualityLabel?, bitrateKbps? }.search(ctx, req) (async, required for "search"): input { query, kind: "all" | "track" | "playlist" | "album", limit, cursor?, cookie? } → returns { items: ExtSearchResult[], nextCursor?: string | null } (or null).searchLyrics(ctx, req) (async, required for "lyrics"): input { title, artist, album?, durationSec? } → returns ExtLyricsCandidate[] | { candidates: [...] } | { results: [...] } | null.startQrLogin(ctx, req) (async, required for "qr_login"): input {} → returns { sessionId, qrContent, expiresAtMs?, pollIntervalMs?, message? } (qrContent ≤ 512 UTF-8 bytes; pollIntervalMs clamped to 1000–10000 ms).pollQrLogin(ctx, req) (async, required for "qr_login"): input { sessionId } → returns { status: "pending" | "scanned" | "confirmed" | "expired" | "error", cookie?, accountName?, message? }.remoteTrackId!
In ExtSearchResult (when kind === "track"), Apple strictly requires string remoteTrackId, whereas Android/Windows also fall back to id. Emitting remoteTrackId: String(item.id) keeps your extension 100% portable across all three clients.
Extension Field (ExtTrack) |
Apple (CloudTrackInfo) |
Android (CloudTrackMetadata) |
Windows (CloudPlaylistItem) |
|---|---|---|---|
remoteTrackId | remoteTrackID | remoteTrackId | RemoteTrackId |
relativePath | relativePath | relativePath | RelativePath |
title / artist / album | title / artist / album | title / artist / album | Title / Artist / Album |
trackNumber / durationSec | trackNumber / duration | trackNumber / durationSec | TrackNumber / DurationSeconds |
artworkUrl | artworkURL | artworkUrl | ArtworkUrl |
ctx), Cookies & Runtime Guardrailsawait ctx.http.request({ method?, url, headers?, body?, followRedirects?, timeoutMs?, returnBytes? }): Routes through native HTTP stacks (honoring Windows HTTP Proxy when "proxy" is declared). Enforces permissions.hosts on the initial URL and every redirect hop (up to 10 hops), strips Cookie and Authorization across host changes, caps responses at 8 MB, and exposes lowercase headers plus raw setCookies array and optional bytesBase64.ctx.crypto: md5, sha1, sha256, hmacSha256(key, msg) (lowercase hex), plus base64Encode / base64Decode.ctx.kv: Persistent per-extension store: get(key), set(key, val, ttlSeconds?), remove(key). Because every hook runs in a fresh isolated JS VM, global variables never persist across calls; always store short-lived tokens in ctx.kv.ctx.settings.get(key) & ctx.env: Read user settings and inspect { platform: "ios" | "macos" | "android" | "windows", appVersion, apiVersion: 1 }.ctx.log (info / warn / error): Writes to the 200-entry ring buffer in Extension Manager. Never pass req.cookie into ctx.log (Android and Windows also auto-redact raw/URL-encoded cookies as defense-in-depth).15s timeout on canHandle, resolveStream, search, and searchLyrics; 60s on fetchCollection/fetchFolder; 32 MB heap limit on QuickJS & Jint. Use ES2020 + CommonJS module.exports + ctx.* only (no Node require/fs/Buffer, no window/document).Attach err.code to thrown errors so Musico displays localized guidance and triggers auth/retry UX appropriately:
| Code | When to Throw |
|---|---|
INVALID_URL | Input URL does not match a valid collection or resource ID. |
AUTH_REQUIRED | Missing, private, or expired session req.cookie. |
EMPTY_COLLECTION | Collection loaded cleanly but contains zero tracks or subfolders. |
NO_PLAYABLE_STREAM | Track has no playable stream or upstream rejected stream lookup. |
RATE_LIMITED | Upstream returned HTTP 429 or rate-limit payload. |
NETWORK_ERROR | Upstream HTTP 4xx/5xx, invalid JSON, or connectivity failure. |
PERMISSION_DENIED | Host or URL scheme blocked by permissions.hosts. |
Declare only the exact domains your API and CDN use inside permissions.hosts. Every user sees this list during Permission Review before enabling your extension.
Fail loudly with AUTH_REQUIRED and a plain-language message (or implement qr_login). Never require cookies for public endpoints, and never log secrets.
Respect req.limit and req.cursor, return nextCursor: null when done (never echo the same cursor), and include sourceUrl on search playlists/albums so users can preview before adding.
Honor req.quality and req.purpose ("stream" vs "download"), set accurate fileExtension/mimeType, use https:// artwork URLs, and keep JSON payloads small for QuickJS/Jint's 32 MB heap.
Verify every hook and strict portability check without rebuilding native apps using Node.js 18+:
# Run built-in conformance suite across all fixtures & starters
node docs/extensions/tools/mock-runner.mjs --self-test
# Test individual hooks locally
node docs/extensions/tools/mock-runner.mjs path/to/ext.musico.js can-handle "https://example.com/playlist/demo_1"
node docs/extensions/tools/mock-runner.mjs path/to/ext.musico.js fetch-collection "https://example.com/playlist/demo_1" --cookie "sid=..."
node docs/extensions/tools/mock-runner.mjs path/to/ext.musico.js search "Yoasobi" --kind track --limit 20
node docs/extensions/tools/mock-runner.mjs path/to/ext.musico.js search-lyrics "Idol" --artist "YOASOBI" --duration 213
node docs/extensions/tools/mock-runner.mjs path/to/ext.musico.js resolve-stream "track_1" --setting preferHighBitrate=true
# In SEANPNEX/musico_plugins: run all offline tests & build .musicoext bundles
npm test
npm run check:release && npm run build:release