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.
Hyperbeam
function might be rejected. See example below:
hb.destroy()
Tears down network connections and browser events. Always call this before removing the container element from the page.
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.
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.
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.
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.
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.
hb.reconnect(): void
In situations where you need to troubleshoot the browser disconnecting, adding a manual reconnect button may help for debugging.
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.
hb.width
and hb.height
.
hb.sendEvent(event: KeyEvent | MouseEvent | WheelEvent): void
Sends a keyboard, mouse, or mouse wheel event to the Hyperbeam browser.
keydown
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:
delegateKeyboard
option to false
. Input fields inside the embed (e.g. address bar, form fields) will continue to receive input when they are focused.
chrome.tabs.create({ active: true })
, you will would call hb.tabs.create({ active: true })
.
Promise
chrome.tabs.onCreated.addListener((tab) => {})
, you will would call hb.tabs.onCreated.addListener((tab) => {})
.
We support the following events:
getRegionInfo()
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
.
getRegionInfo()
fires off a web request.