Migrate Bridge To Common Connect WebUSB
This guide helps you migrate the legacy Bridge transport (hd-web-sdk + Bridge) to the native browser WebUSB channel, and switch the SDK entry point to @onekeyfe/hd-common-connect-sdk.
Requirements
Chromium browsers (Chrome/Edge desktop)
Node.js 18+ (LTS recommended)
What Changed (At a Glance)
SDK entry:
@onekeyfe/hd-web-sdk→@onekeyfe/hd-common-connect-sdkInit options: use
env: 'webusb'; no moreconnectSrc(no iframe)Permission flow: call
navigator.usb.requestDevice()(must be triggered by a user gesture) with the official filterONEKEY_WEBUSB_FILTEREvent system: use
@onekeyfe/hd-coreUI_EVENT / DEVICEevents for user interaction (PIN/Passphrase, etc.)Bridge‑specific logic removed: drop
checkBridgeStatus()and all Bridge checks/promptsBusiness APIs mostly unchanged: e.g.,
searchDevices / getFeatures / btcGetAddress
Install
Initialize (hd-common-connect-sdk + WebUSB)
Unlike
hd-web-sdk, you do not needconnectSrchere (no iframe dependency).It is recommended to enable
fetchConfig: trueto fetch device capability and hint configurations.
Bind UI and Device Events (PIN / Passphrase / Plug-Unplug)
Subscribe to
UI_EVENTas early as possible so PIN/Passphrase prompts are handled and flows don’t stall.For details, see: Config Event
Authorization (WebUSB Picker + Official Filter)
Enumerate Devices and First Call
Cleanup and Checklist
Dependency swap: remove
@onekeyfe/hd-web-sdk, use@onekeyfe/hd-common-connect-sdkinsteadInitialization changes:
Old:
env: 'web'+connectSrc: 'https://jssdk.onekey.so/.../'New:
env: 'webusb'(noconnectSrc)
Remove Bridge‑only logic: e.g.,
checkBridgeStatus(), Bridge install/restart promptsBind
UI_EVENT / DEVICE: ensure PIN/Passphrase and device plug/unplug events are handledDon’t auto‑enumerate before permission:
requestDevice()must be called via a user gestureCompatibility tip: if
navigator.usbis missing, ask users to switch to a WebUSB‑capable browser
FAQ
No permission prompt on HTTP? → Serve over HTTPS
UI requests seem stuck? → Subscribe to
UI_EVENTearly and respond viauiResponseStill using
connectSrcorHdWebSdk.HardwareWebSdk? → Migrated tohd-common-connect-sdk; iframe is no longer neededCalled
requestDeviceoutside a user gesture? → Chrome blocks it; must be triggered by a click or similar gesture
Further Reading
WebUSB deep dive and full example: WebUSB Connection Guide
Events and interactions: Config Event
API references and params: Hardware SDK API References, Common Params, Error Codes
Last updated
Was this helpful?