API / session

session

Permissions and session partitions. Cookie/cache/proxy/download operations live in the native session module; this SDK page covers the JavaScript-facing part.

import { session } from '@owear/core'

Permissions

interface PermissionRequest {
  id: number
  permission: string    // 'geolocation' | 'notifications' | 'media' | 'microphone' | 'camera' | 'clipboardRead' | …
  origin: string
}

type PermissionHandler = (req: PermissionRequest) => boolean | Promise<boolean>

session.onPermissionRequest(handler: PermissionHandler): () => void

Registers a handler and tells the kernel to route permission requests. Multiple handlers may be registered; a request is allowed if any handler returns truthy. With no handler, everything is denied.

const off = session.onPermissionRequest(({ permission, origin }) =>
  permission === 'notifications' && origin === 'app://index.html',
)

Partitions

session.fromPartition(partition: string): { partition: string }

Returns a handle whose partition string you pass to a window:

const profile = session.fromPartition('persist:account-2')
new BrowserWindow({ session: profile.partition, url })

Use persist: to make the partition durable. Omitting session uses the app's default profile.

Related

Edit this page on GitHub ↗