Something went wrong. Try again.
Browser extension: detect and subscribe to standard.site publications on ATProto substandard.blog
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839// Invisible host for the OAuth client during sign-in. BrowserOAuthClient// needs window/localStorage, which the MV3 worker lacks, so the worker opens// this document and asks it to build the authorization URL and, later, to// exchange the callback redirect for a session (see src/signin.ts).
import { completeAuthorization, restoreSession, revokeSession, startAuthorization,} from '../lib/oauth'import type { OffscreenMsg } from '../lib/types'import { ext } from '../lib/platform'
ext.runtime.onMessage.addListener( (msg: OffscreenMsg | { target?: undefined }, _sender, sendResponse) => { if (msg.target !== 'offscreen') return false dispatch(msg) .then(sendResponse) .catch((err: unknown) => { sendResponse({ __error: err instanceof Error ? err.message : String(err) }) }) return true },)
async function dispatch(msg: OffscreenMsg): Promise<unknown> { switch (msg.type) { case 'oauth-authorize': return startAuthorization(msg.handle) case 'oauth-callback': return completeAuthorization(msg.url) case 'oauth-revoke': return revokeSession(msg.sub) case 'oauth-restore': return restoreSession(msg.sub, msg.refresh) }}