Skip to content

ScramjetServiceWorker

Defined in: typedoc-repos/scramjet/src/worker/index.ts:17

Main ScramjetServiceWorker class created by the $scramjetLoadWorker factory, which handles routing the proxy and contains the core logic for request interception.

  • EventTarget

client: BareClient

Defined in: typedoc-repos/scramjet/src/worker/index.ts:21

BareClient instance to fetch requests under a chosen proxy transport.


config: ScramjetConfig

Defined in: typedoc-repos/scramjet/src/worker/index.ts:25

Current ScramjetConfig saved in memory.


cookieStore: CookieStore

Defined in: typedoc-repos/scramjet/src/worker/index.ts:39

Scramjet’s cookie jar for cookie emulation through other storage means, connected to a client.


serviceWorkers: FakeServiceWorker[] = []

Defined in: typedoc-repos/scramjet/src/worker/index.ts:45

Fake service worker registrations, so that some sites don’t complain. This will eventually be replaced with a NestedSW feature under a flag in the future, but this will remain for stability even then.


syncPool: Record<number, (val?) => void> = {}

Defined in: typedoc-repos/scramjet/src/worker/index.ts:30

Recorded sync messages in the message queue.


synctoken: number = 0

Defined in: typedoc-repos/scramjet/src/worker/index.ts:34

Current sync token for collected messages in the queue.

addEventListener(type, callback, options?): void

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

The addEventListener() method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target.

MDN Reference

string

EventListenerOrEventListenerObject

boolean | AddEventListenerOptions

void

EventTarget.addEventListener

addEventListener(type, callback, options?): void

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

The addEventListener() method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target.

MDN Reference

string

EventListenerOrEventListenerObject

boolean | AddEventListenerOptions

void

EventTarget.addEventListener


dispatch(client, data): Promise<MessageC2W>

Defined in: typedoc-repos/scramjet/src/worker/index.ts:104

Dispatches a message in the message queues.

Client

MessageW2C

Promise<MessageC2W>


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


fetch(__namedParameters): Promise<any>

Defined in: typedoc-repos/scramjet/src/worker/index.ts:188

Handles a FetchEvent to be routed in Scramjet. This is the heart of adding Scramjet support to your web proxy.

FetchEvent

Promise<any>

self.addEventListener("fetch", async (ev) => {
  ...

  if (scramjet.route(ev)) {
    ev.respondWith(scramjet.fetch(ev));
  }
});

loadConfig(): Promise<void>

Defined in: typedoc-repos/scramjet/src/worker/index.ts:127

Persists the current Scramjet config into an IndexedDB store. Remember, this is because the Scramjet config can be dynamically updated via the Scramjet Controller APIs.

Promise<void>

self.addEventListener("fetch", async (ev) => {
  await scramjet.loadConfig();

  ...
});

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


route(__namedParameters): boolean

Defined in: typedoc-repos/scramjet/src/worker/index.ts:167

Whether to route a request from a FetchEvent in Scramjet.

FetchEvent

boolean

self.addEventListener("fetch", async (ev) => {
  ...

  if (scramjet.route(ev)) {
    ...
  }
});