Skip to main content
The ScramjetServiceWorker class handles request interception in the service worker context. It routes proxy requests, manages configuration, and handles the core logic for proxying.

Constructor

Creates a new ScramjetServiceWorker instance.

Example

Properties

client

BareClient instance to fetch requests under a chosen proxy transport.

config

Current ScramjetConfig saved in memory.

cookieStore

Scramjet’s cookie jar for cookie emulation through other storage means.

serviceWorkers

Fake service worker registrations for sites that require service worker support.
This will eventually be replaced with a NestedSW feature under a flag, but will remain for stability.

syncPool

Recorded sync messages in the message queue.

synctoken

Current sync token for collected messages in the queue.

Methods

loadConfig()

Persists the current Scramjet config from IndexedDB into memory.
You must call loadConfig() before using route() or fetch() to ensure the configuration is loaded.

Example

The Scramjet config can be dynamically updated via the ScramjetController APIs, which is why it needs to be loaded from IndexedDB.

route()

Determines whether to route a request from a FetchEvent in Scramjet.
Request
required
The fetch request from the FetchEvent

Returns

true if the request should be handled by Scramjet, false otherwise.

Example

fetch()

Handles a FetchEvent to be routed in Scramjet. This is the heart of adding Scramjet support to your web proxy.
Request
required
The fetch request from the FetchEvent
string
required
The client ID from the FetchEvent

Returns

A Promise that resolves to the proxied Response.

Example

dispatch()

Dispatches a message in the message queues.
Client
required
The client to send the message to
MessageW2C
required
The message data to send

Returns

A Promise that resolves to the response message from the client.
This method is used internally for communication between the service worker and clients.

Message types

The service worker communicates with clients using typed messages.

MessageC2W

Message types sent from the client to the service worker.

MessageW2C

Message types sent from the service worker to the client.

RegisterServiceWorkerMessage

CookieMessage

ConfigMessage

DownloadMessage

Complete example