Skip to content
Client
Server

Reference / @open-music-sdk/browser / createConnect

Function: createConnect() ​

ts
function createConnect(music, options): tConnect;

Defined in: integrations/browser/src/connect.ts:235

The sign-in helper for a page: makes it where the connect button is shown, so that Apple's script is loaded and configured before the click, and the window opens inside it. music is the client from createBrowserClient, or anything with a developerToken provider. Apple's script is one per page, so a second helper on a page already configured for another app is a TypeError, and a second helper for the same app shares the first's load and configuration. A page that makes no helper never fetches the script. A global named MusicKit that cannot configure, such as an element with that id in content the page shows, is passed over and the script loaded. While the helper lives it keeps the developer token fresh, at the token's half-life and when the tab comes back, so that connect() waits on no network inside the click. What loading and configuring the script fails with is nobody's unhandled rejection: it waits for whoever awaits ready or connect().

The helper stores nothing, but Apple's script keeps its own copy of the listener's token in browser storage, where any script on your origin can read it: a cross-site scripting hole exposes the token on later visits too. In Firefox on 18 October 2026 that was the page's local storage, under music.<your team id in small letters>.media-user-token, beside two short keys of the same prefix, itre and itua; it kept nothing in cookies, the indexed database or the cache storage.

Parameters ​

music ​

The client from createBrowserClient, or anything with a developerToken provider on it.

developerToken ​

tTokenProvider

options ​

tConnectOptions

The app as Apple's script is configured with it, and the page's own MusicKit where it loaded the script itself.

Returns ​

tConnect

The helper, frozen: ready, connect, disconnect and dispose.

Throws ​

TypeError if music has no developerToken, options is not a plain object, app is not an object with a name that has something in it or a build that is not a string, musicKit has no configure, there is no document, or the page's script is configured for another app.

MIT licensed. Not affiliated with, endorsed by, or sponsored by Apple Inc. Apple Music and MusicKit are trademarks of Apple Inc.