β‘ Loading a virtual browser
Hyperbeam(container: HTMLDivElement | HTMLIFrameElement, embedURL: string, opts?: HyperbeamOptions): Promise<HyperbeamClient>
Creates a new Hyperbeam client. The container can be either a div or an iframe element, though it is highly advised to use a div. The embedURL is retrieved from the REST API.
JavaScript
Hyperbeam function might be rejected. See example below:
JavaScript
π£ Destroying the embed
hb.destroy()
Tears down network connections and browser events. Always call this before removing the container element from the page.
JavaScript
π Setting video volume
hb.volume = 0.5
Sets the volume for the virtual browser locally. Volume changes only apply to the local user. This setting is not persisted on refreshing the page.
JavaScript
π Getting user ID
hb.userId: string
Gets the clientβs user ID. A βuserβ is defined as a single connection to the virtual browser. If a person has multiple tabs connected to the virtual browser, each tab with an active connection will be assigned a different user ID.
JavaScript
βΈοΈ Pausing video stream
hb.videoPaused = true
Pauses/resumes the video stream for the virtual browser locally. Useful if only the audio component is of interest and you want to minimize CPU usage.
JavaScript
π Setting admin token
hb.adminToken = "adminToken"
Sets the clientβs admin token. The client must have an admin token set to manage user permissions and control the tabs programmatically.
JavaScript
π Setting permissions
hb.setPermission(userId: string, permissionData: PermissionData): Promise<void>
Sets the permission of a user by their ID. The client must have an admin token set to manage user permissions.
JavaScript
π Manual reconnection
hb.reconnect(): void
In situations where you need to troubleshoot the browser disconnecting, adding a manual reconnect button may help for debugging.
JavaScript
π Resizing the browser
hb.resize(width: number, height: number): Promise
Resizes the virtual browser to the specified width and height, in pixels.
The arguments must meet the following conditions, otherwise the function will throw a RangeError: width * height cannot be greater than hb.maxArea.
hb.maxArea is the maximum area that can be allocated in pixels.
JavaScript
hb.width and hb.height.
π‘ Send events programmatically
hb.sendEvent(event: KeyEvent | MouseEvent | WheelEvent): void
Sends a keyboard, mouse, or mouse wheel event to the Hyperbeam browser.
JavaScript
β¨οΈ Tighter control over keyboard events
By default, the Hyperbeam client forwards globalkeydown and keyup events into the embed when an input element is not in focus outside the embed. In some cases, you may want to customize this functionality:
- Your app has key bindings which conflict with Hyperbeam
- You have UI flows such as overlays and tabs which hide the Hyperbeam embed from view
delegateKeyboard option to false. Input fields inside the embed (e.g. address bar, form fields) will continue to receive input when they are focused.
JavaScript
JavaScript
ποΈ Control tabs programmatically
Hyperbeamβs tab API mirrors Chrome extension tab API, found here. Rather than callingchrome.tabs.create({ active: true }), you will would call hb.tabs.create({ active: true }).
We support the following methods:
- tabs.create
- tabs.detectLanguage
- tabs.discard
- tabs.duplicate
- tabs.get
- tabs.getZoom
- tabs.getZoomSettings
- tabs.goBack
- tabs.goForward
- tabs.group
- tabs.highlight
- tabs.move
- tabs.query
- tabs.reload
- tabs.remove
- tabs.setZoom
- tabs.setZoomSettings
- tabs.ungroup
- tabs.update
HTML
π Listen to tab events
Hyperbeamβs tab event listener API mirrors Chrome extension tab API, found here. Rather than callingchrome.tabs.onCreated.addListener((tab) => {}), you will would call hb.tabs.onCreated.addListener((tab) => {}).
We support the following events:
- tabs.onActivated
- tabs.onCreated
- tabs.onHighlighted
- tabs.onMoved
- tabs.onRemoved
- tabs.onReplaced
- tabs.onUpdated
- tabs.onZoomChange
JavaScript
πΊοΈ Optimize server location
To create a session with the optimal server location, you first need to usegetRegionInfo() on the client to retrieve the optimal region information.
From there, you need to send the HyperbeamRegionInfo objectβs region value to your backend, and use it as the argument for the region parameter when creating a session and generating an embed_url.
Example
JavaScript