Skip to content

Web API Modules

These modules are aligned to browser APIs where possible.

Push (push)

MethodReturns
subscribe()Promise<{ token: string; endpoint: string }>
getSubscription()Promise<PushSubscription | null>
requestPermission()Promise<'granted' | 'denied' | 'prompt'>
permissionState()Promise<'granted' | 'denied' | 'prompt'>

subscribe() does not take browser-style options (for example applicationServerKey).

ts
import { push } from "@pwa-kit/sdk";

const state = await push.permissionState();
if (state === "prompt") {
  await push.requestPermission();
}

const sub = await push.subscribe();
console.log(sub.token, sub.endpoint);

Badging (badging)

MethodReturns
setAppBadge(count?)Promise<void>
clearAppBadge()Promise<void>

Vibration (vibration)

MethodReturns
vibrate(pattern?)boolean

pattern can be number or number[].

ts
import { vibration } from "@pwa-kit/sdk";

vibration.vibrate(100);
vibration.vibrate([100, 50, 100]);

Clipboard (clipboard)

MethodReturns
writeText(text)Promise<void>
readText()Promise<string | null>

Share (share)

MethodReturns
share(options)Promise<{ completed: boolean; activityType?: string }>
canShare()Promise<boolean>

options.files uses { name, type, data } where data is base64.

Permissions (permissions)

Supported names: camera, microphone, geolocation.

MethodReturns
query({ name })Promise<{ name; state }>
request({ name })Promise<{ name; state }>

state maps to: granted, denied, prompt.

Alignment and intentional deviations

Alignment matrix

SDK moduleWeb standardAlignment
pushPushManagersubscribe(), getSubscription(), permissionState() model
badgingBadging APIsetAppBadge(), clearAppBadge()
vibrationVibration APIvibrate(pattern) signature and boolean return
clipboardClipboard APIwriteText(), readText() text-only subset
shareWeb Share APIshare(), canShare() style
permissionsPermissions APIquery() model with native permission mapping

Intentional deviations

AreaBehavior in PWAKit SDKWhy
push.subscribe(options)No options argumentAPNs-native flow does not use VAPID/app server key input
permissions.request()Exists as a first-class methodNative pre-prompt flow before web API use
share.canShare(data)No data argument; async Promise<boolean>Bridge checks native capability, not per-payload sync validation
share.share()Returns { completed, activityType? }Exposes native share-sheet result detail
clipboard.readText()Returns string | nullEmpty clipboard maps to null
Push endpointReturns apns://<token>Keeps PushSubscription-like shape from APNs token
badging.setAppBadge()Omitted count maps to 0iOS native bridge uses badge count semantics
Vibration implementationTriggers haptics under the hoodiOS Safari does not support Web Vibration API
vibration.vibrate() returnAlways returns trueImplemented as fire-and-forget haptic polyfill
vibration.vibrate(0) stop behaviorNo active vibration state to stopiOS implementation treats stop as successful no-op

Push and permissions states are normalized to granted, denied, and prompt.

Released under the MIT License.