Skip to content

ScramjetController

Defined in: typedoc-repos/scramjet/src/controller/index.ts:48

Controller class for managing behavior in the Scramjet Service Worker. You should create this class from the factory $scramjetLoadController This handles proxified Scramjet iframe creations and let’s you configure how Scramjet intercepts things. A lot of these are lower level, and some of these APIs can be avoided by using ScramjetController.createFrame.

const { ScramjetController } = $scramjetLoadController();

const scramjet = new ScramjetController({
  prefix: "/scramjet/",
  files: {
    wasm: "/scram/scramjet.wasm.wasm",
    all: "/scram/scramjet.all.js",
    sync: "/scram/scramjet.sync.js",
  }
});

await scramjet.init();

const frame = scramjet.createFrame();
document.body.appendChild(frame.frame);
frame.go("https://example.com");
  • EventTarget

addEventListener<K>(type, listener, options?): void

Defined in: typedoc-repos/scramjet/src/controller/index.ts:328

Adds an event listener for Scramjet’s lower level events. Binds event listeners to listen for proxified navigation events in Scramjet.

K extends "download"

K

Type of event to listen for.

(event) => void

Event listener to dispatch.

Options for the event listener.

boolean | AddEventListenerOptions

void

EventTarget.addEventListener


createFrame(frame?): ScramjetFrame

Defined in: typedoc-repos/scramjet/src/controller/index.ts:206

Factory method that creates a ScramjetFrame to be integrated into your application.

HTMLIFrameElement

Existing iframe element to use.

ScramjetFrame

A ScramjetFrame instance.

const frame = scramjet.createFrame();
document.body.appendChild(frame.frame);

const iframe = document.createElement("iframe");
const frame = scramjet.createFrame(iframe);
document.body.appendChild(frame.frame);

// Navigate to a proxified URL
frame.go("https://example.com");

// Listen for proxified URL changes
frame.addEventListener("urlchange", (e) => {
  console.log("New URL:", e.url);
});

decodeUrl(url): string

Defined in: typedoc-repos/scramjet/src/controller/index.ts:240

Decodes a real URL into its proxy URL.

Real URL

string | URL

string

Its proxy URL


dispatchEvent(event): boolean

Defined in: node_modules/.pnpm/[email protected]/node_modules/typescript/lib/lib.dom.d.ts:11575

The dispatchEvent() method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order.

MDN Reference

Event

boolean

EventTarget.dispatchEvent

dispatchEvent(event): boolean

Defined in: node_modules/.pnpm/[email protected]/node_modules/typescript/lib/lib.webworker.d.ts:4019

The dispatchEvent() method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order.

MDN Reference

Event

boolean

EventTarget.dispatchEvent


encodeUrl(url): string

Defined in: typedoc-repos/scramjet/src/controller/index.ts:220

Encodes a proxy URL into a real URL.

A fully complete URL.

string | URL

string

The encoded URL.


init(): Promise<void>

Defined in: typedoc-repos/scramjet/src/controller/index.ts:162

Initializes Scramjet. This sends the current config to the service worker and initializes the IndexedDB tables. Must be called after creating the controller and before using Scramjet Frames.

Promise<void>

const { ScramjetController } = $scramjetLoadController();
const scramjet = new ScramjetController({
  prefix: "/scramjet/",
  files: {
    all: "/scram/scramjet.all.js"
  }
});

await scramjet.init();

// Initialize a Scramjet Frame and goes to a site
const frame = scramjet.createFrame();
frame.go("https://example.com");

modifyConfig(newconfig): Promise<void>

Defined in: typedoc-repos/scramjet/src/controller/index.ts:309

Dynamically updates the Scramjet config on the Service Worker.

Partial<ScramjetInitConfig>

Promise<void>


openIDB(): Promise<IDBDatabase>

Defined in: typedoc-repos/scramjet/src/controller/index.ts:254

Opens Scramjet’s IndexedDB database and initializes its required object stores if they don’t yet exist. This is only to be used internally by the ScramjetController.constructor | constructor. As a proxy site developer, you do not need to interact with this directly.

Promise<IDBDatabase>

A Promise to either return the initialized IndexedDB or to handle IndexedDB rejections.


removeEventListener(type, callback, options?): void

Defined in: node_modules/.pnpm/[email protected]/node_modules/typescript/lib/lib.dom.d.ts:11581

The removeEventListener() method of the EventTarget interface removes an event listener previously registered with EventTarget.addEventListener() from the target.

MDN Reference

string

EventListenerOrEventListenerObject

boolean | EventListenerOptions

void

EventTarget.removeEventListener

removeEventListener(type, callback, options?): void

Defined in: node_modules/.pnpm/[email protected]/node_modules/typescript/lib/lib.webworker.d.ts:4025

The removeEventListener() method of the EventTarget interface removes an event listener previously registered with EventTarget.addEventListener() from the target.

MDN Reference

string

EventListenerOrEventListenerObject

boolean | EventListenerOptions

void

EventTarget.removeEventListener