Skip to main content
The ScramjetController class manages Scramjet instances, handles configuration, and provides frame creation. It extends EventTarget to support listening for global Scramjet events.

Constructor

Creates a new ScramjetController instance.
Partial<ScramjetInitConfig>
required
Configuration options for Scramjet. See config types for details.

Example

Methods

init()

Initializes the controller by loading codecs, opening IndexedDB, and setting up message listeners.
You must call init() before using other methods on the controller.

Example

createFrame()

Creates a new ScramjetFrame instance for managing an iframe.
HTMLIFrameElement
Optional existing iframe element. If not provided, a new iframe is created.

Returns

A ScramjetFrame instance for managing the iframe.

Example

encodeUrl()

Encodes a real URL into a Scramjet-proxied URL.
string | URL
required
The real URL to encode

Returns

The encoded URL with the Scramjet prefix.

Example

Only HTTP and HTTPS URLs are encoded. Other protocols are returned unchanged.

decodeUrl()

Decodes a Scramjet-proxied URL back to the real URL.
string | URL
required
The proxied URL to decode

Returns

The decoded real URL.

Example

modifyConfig()

Dynamically updates the Scramjet configuration.
Partial<ScramjetInitConfig>
required
The configuration properties to update

Example

Configuration changes are persisted to IndexedDB and synchronized with the service worker.

addEventListener()

Adds an event listener for Scramjet global events.
'download'
required
The event type to listen for
Function
required
The callback function to execute when the event fires
boolean | AddEventListenerOptions
Event listener options

Example

Events

download

Fired when a download is intercepted by Scramjet.
See event types for the full ScramjetDownload interface.