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.
Example
Section titled “Example”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");
Extends
Section titled “Extends”EventTarget
Methods
Section titled “Methods”addEventListener()
Section titled “addEventListener()”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.
Type Parameters
Section titled “Type Parameters”K
extends "download"
Parameters
Section titled “Parameters”K
Type of event to listen for.
listener
Section titled “listener”(event
) => void
Event listener to dispatch.
options?
Section titled “options?”Options for the event listener.
boolean
| AddEventListenerOptions
Returns
Section titled “Returns”void
Overrides
Section titled “Overrides”EventTarget.addEventListener
createFrame()
Section titled “createFrame()”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.
Parameters
Section titled “Parameters”frame?
Section titled “frame?”HTMLIFrameElement
Existing iframe element to use.
Returns
Section titled “Returns”A ScramjetFrame instance.
Example
Section titled “Example”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()
Section titled “decodeUrl()”decodeUrl(
url
):string
Defined in: typedoc-repos/scramjet/src/controller/index.ts:240
Decodes a real URL into its proxy URL.
Parameters
Section titled “Parameters”Real URL
string
| URL
Returns
Section titled “Returns”string
Its proxy URL
dispatchEvent()
Section titled “dispatchEvent()”Call Signature
Section titled “Call Signature”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.
Parameters
Section titled “Parameters”Event
Returns
Section titled “Returns”boolean
Inherited from
Section titled “Inherited from”EventTarget.dispatchEvent
Call Signature
Section titled “Call Signature”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.
Parameters
Section titled “Parameters”Event
Returns
Section titled “Returns”boolean
Inherited from
Section titled “Inherited from”EventTarget.dispatchEvent
encodeUrl()
Section titled “encodeUrl()”encodeUrl(
url
):string
Defined in: typedoc-repos/scramjet/src/controller/index.ts:220
Encodes a proxy URL into a real URL.
Parameters
Section titled “Parameters”A fully complete URL.
string
| URL
Returns
Section titled “Returns”string
The encoded URL.
init()
Section titled “init()”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.
Returns
Section titled “Returns”Promise
<void
>
Example
Section titled “Example”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()
Section titled “modifyConfig()”modifyConfig(
newconfig
):Promise
<void
>
Defined in: typedoc-repos/scramjet/src/controller/index.ts:309
Dynamically updates the Scramjet config on the Service Worker.
Parameters
Section titled “Parameters”newconfig
Section titled “newconfig”Partial
<ScramjetInitConfig
>
Returns
Section titled “Returns”Promise
<void
>
openIDB()
Section titled “openIDB()”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.
Returns
Section titled “Returns”Promise
<IDBDatabase
>
A Promise to either return the initialized IndexedDB or to handle IndexedDB rejections.
removeEventListener()
Section titled “removeEventListener()”Call Signature
Section titled “Call Signature”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.
Parameters
Section titled “Parameters”string
callback
Section titled “callback”EventListenerOrEventListenerObject
options?
Section titled “options?”boolean
| EventListenerOptions
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”EventTarget.removeEventListener
Call Signature
Section titled “Call Signature”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.
Parameters
Section titled “Parameters”string
callback
Section titled “callback”EventListenerOrEventListenerObject
options?
Section titled “options?”boolean
| EventListenerOptions
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”EventTarget.removeEventListener