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 newScramjetServiceWorker instance.
Example
Properties
client
BareClient instance to fetch requests under a chosen proxy transport.
config
CurrentScramjetConfig 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.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 aFetchEvent 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 aFetchEvent 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
APromise 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
APromise that resolves to the response message from the client.
This method is used internally for communication between the service worker and clients.