@fkn/lib
Namespaces
Section titled “Namespaces”Type Aliases
Section titled “Type Aliases”RelayUnavailableError
Section titled “RelayUnavailableError”type RelayUnavailableError = Error & object;What a call carrying a RelayChoice rejects with when no relay can serve the choice: none matches
it, the ones that match cannot be reached, or the FKN page is too old to choose. Nothing was sent.
Type Declaration
Section titled “Type Declaration”name: typeof RELAY_UNAVAILABLE;Variables
Section titled “Variables”attachFrame
Section titled “attachFrame”const attachFrame: AttachFrameFunction;Attaches FKN to an iframe the app mounted, or with { window } opens the attachment in a window
of its own. cookies picks the jar and with it the backend (AttachCookies): 'persistent', the
default, and 'ephemeral' run on the cloud render proxy whatever is installed, and never wait for
the extension; 'native' runs on the extension, waiting up to 2000 ms from the call for it to
announce itself, however long after the page’s load that is (waitForExtensionExposure), and
showing the install prompt when it does not. A blank attach is the cloud render proxy’s alone, so
beside 'native' it is a TypeError. frame.backend() says which backend serves an attachment.
A window opens before the first await, so call this directly in the click or key handler whose
activation opens it. On 'persistent' or 'ephemeral' it opens on the cloud, extension or not. On
'native' it opens as a real browser window on the extension, with no exposure wait; an extension
that does not announce attachWindow, or none at all, is refused at once with
ExtensionOperationUnsupportedError (operation 'attachWindow'), before anything opens or is
waited for, so the same click can still open one on another value.
Functions
Section titled “Functions”connect()
Section titled “connect()”function connect(): Promise<boolean>;Returns
Section titled “Returns”Promise<boolean>
fetch()
Section titled “fetch()”function fetch(input, init?): Promise<Response>;Parameters
Section titled “Parameters”URL | RequestInfo
RequestInit & object
Returns
Section titled “Returns”Promise<Response>
isRelayUnavailable()
Section titled “isRelayUnavailable()”function isRelayUnavailable(error): error is RelayUnavailableError;Whether error is a RelayUnavailableError, matched on name so it holds across a worker hop.
Parameters
Section titled “Parameters”unknown
Returns
Section titled “Returns”error is RelayUnavailableError
promptRelay()
Section titled “promptRelay()”function promptRelay(): Promise<string | null>;Returns
Section titled “Returns”Promise<string | null>
relayOf()
Section titled “relayOf()”function relayOf(served): string | undefined;The relay that served a cloud answer, socket, server, UDP socket or frame, as an id to pass back in
a RelayChoice. Undefined when no relay did (the extension, the desktop, a 'native' frame), before
a socket is connected or bound, and on an FKN page too old to say, so a loop that retries on another
relay stops there. A frame attached without a choice answers the default relay of its attach once
the broker has named it, normally before the attach resolves.
Parameters
Section titled “Parameters”served
Section titled “served”Socket | Server | Socket | Response | Frame
Returns
Section titled “Returns”string | undefined
relayWorker()
Section titled “relayWorker()”function relayWorker(worker, options?): Promise<void>;Bridges a worker into the FKN API: once called, the worker can import @fkn/lib and use net /
dgram exactly like the main thread. Main thread only.
originA and originB are kept for compatibility and change nothing: the page reaches fkn.app’s
broker frame on fkn.app’s origin both ways, and a page nested under fkn.app reaches it over a port.
The page hands its fkn-api channel to the worker for good, and its own calls move to
fkn-api-window. Against a cached FKN page from before that channel, the page’s own calls refuse
with OwnChannelUnavailableError and FKN’s UI and account changes stay off here until a reload.
A socket the page opened through FKN before its first relayWorker rides the channel it hands
over, so it closes then.
The bridge ends when unregisterSignal aborts or the worker is gone (terminate(), a crash), the
latter seen only for a worker running this version of @fkn/lib or a later one. Every socket the
worker opened through FKN’s relay is then closed there, one still opening included, and a worker
that lives on has its FKN calls refused. A page relays one worker at a time: with two bridges open,
every answer goes to both workers, and one carrying a stream, a promise or a port reaches only the
worker relayed first.
Parameters
Section titled “Parameters”worker
Section titled “worker”Worker
options?
Section titled “options?”originA?
Section titled “originA?”string
originB?
Section titled “originB?”string
unregisterSignal?
Section titled “unregisterSignal?”AbortSignal
Returns
Section titled “Returns”Promise<void>
References
Section titled “References”account
Section titled “account”Re-exports account
AddScriptTagOptions
Section titled “AddScriptTagOptions”Re-exports AddScriptTagOptions
assertAttachableFrameUrl
Section titled “assertAttachableFrameUrl”Re-exports assertAttachableFrameUrl
assertFetchableUrl
Section titled “assertFetchableUrl”Re-exports assertFetchableUrl
AttachCookies
Section titled “AttachCookies”Re-exports AttachCookies
AttachFrameOptions
Section titled “AttachFrameOptions”Re-exports AttachFrameOptions
AttachWindowOptions
Section titled “AttachWindowOptions”Re-exports AttachWindowOptions
BACKGROUND_STOPPED
Section titled “BACKGROUND_STOPPED”Re-exports BACKGROUND_STOPPED
BackgroundStoppedError
Section titled “BackgroundStoppedError”Re-exports BackgroundStoppedError
BlankPage
Section titled “BlankPage”Re-exports BlankPage
ClearCookiesOptions
Section titled “ClearCookiesOptions”Re-exports ClearCookiesOptions
Re-exports cloud
connectButtonUrl
Section titled “connectButtonUrl”Re-exports connectButtonUrl
CookieDetails
Section titled “CookieDetails”Re-exports CookieDetails
cookies
Section titled “cookies”Re-exports cookies
desktop
Section titled “desktop”Re-exports desktop
Re-exports dgram
Re-exports dns
extension
Section titled “extension”Re-exports extension
EXTENSION_ABI
Section titled “EXTENSION_ABI”Re-exports EXTENSION_ABI
ExtensionHandshake
Section titled “ExtensionHandshake”Re-exports ExtensionHandshake
ExtensionOperationUnsupportedError
Section titled “ExtensionOperationUnsupportedError”Re-exports ExtensionOperationUnsupportedError
ExtensionOutdatedError
Section titled “ExtensionOutdatedError”Re-exports ExtensionOutdatedError
FetchInit
Section titled “FetchInit”Re-exports FetchInit
FORGEABLE_HEADERS
Section titled “FORGEABLE_HEADERS”Re-exports FORGEABLE_HEADERS
Re-exports Frame
FrameLocator
Section titled “FrameLocator”Re-exports FrameLocator
FrameWindowBlockedError
Section titled “FrameWindowBlockedError”Re-exports FrameWindowBlockedError
FrameWindowOptions
Section titled “FrameWindowOptions”Re-exports FrameWindowOptions
FrameWindowRefusal
Section titled “FrameWindowRefusal”Re-exports FrameWindowRefusal
FrameWindowRefusedError
Section titled “FrameWindowRefusedError”Re-exports FrameWindowRefusedError
Re-exports fs
GotoOptions
Section titled “GotoOptions”Re-exports GotoOptions
HeaderOperation
Section titled “HeaderOperation”Re-exports HeaderOperation
Re-exports http
isBackgroundStopped
Section titled “isBackgroundStopped”Re-exports isBackgroundStopped
isExtensionExposed
Section titled “isExtensionExposed”Re-exports isExtensionExposed
isLocalNetworkUrl
Section titled “isLocalNetworkUrl”Re-exports isLocalNetworkUrl
isLocatorInvalid
Section titled “isLocatorInvalid”Re-exports isLocatorInvalid
LOCATOR_INVALID
Section titled “LOCATOR_INVALID”Re-exports LOCATOR_INVALID
Re-exports net
Re-exports opfs
packages
Section titled “packages”Re-exports packages
PermissionGrant
Section titled “PermissionGrant”Re-exports PermissionGrant
PermissionRequest
Section titled “PermissionRequest”Re-exports PermissionRequest
permissions
Section titled “permissions”Re-exports permissions
promptInstall
Section titled “promptInstall”Re-exports promptInstall
readExtensionHandshake
Section titled “readExtensionHandshake”Re-exports readExtensionHandshake
RELAY_UNAVAILABLE
Section titled “RELAY_UNAVAILABLE”Re-exports RELAY_UNAVAILABLE
RemoteVideoElement
Section titled “RemoteVideoElement”Re-exports RemoteVideoElement
removeRequestHeaderRule
Section titled “removeRequestHeaderRule”Re-exports removeRequestHeaderRule
RequestHeaderRule
Section titled “RequestHeaderRule”Re-exports RequestHeaderRule
REQUIRED_EXTENSION_ABI
Section titled “REQUIRED_EXTENSION_ABI”Re-exports REQUIRED_EXTENSION_ABI
Re-exports rooms
setMissingExtensionHandler
Section titled “setMissingExtensionHandler”Re-exports setMissingExtensionHandler
setRequestHeaderRule
Section titled “setRequestHeaderRule”Re-exports setRequestHeaderRule
SiteCookie
Section titled “SiteCookie”Re-exports SiteCookie
storage
Section titled “storage”Re-exports storage
StorageState
Section titled “StorageState”Re-exports StorageState
StorageStateCookie
Section titled “StorageStateCookie”Re-exports StorageStateCookie
supportsOperation
Section titled “supportsOperation”Re-exports supportsOperation
TimeoutError
Section titled “TimeoutError”Re-exports TimeoutError
waitForExtensionExposure
Section titled “waitForExtensionExposure”Re-exports waitForExtensionExposure
WindowFrame
Section titled “WindowFrame”Re-exports WindowFrame