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.
Extends
Section titled “Extends”EventTarget
Properties
Section titled “Properties”client
Section titled “client”client:
BareClient
Defined in: typedoc-repos/scramjet/src/worker/index.ts:21
BareClient
instance to fetch requests under a chosen proxy transport.
config
Section titled “config”config:
ScramjetConfig
Defined in: typedoc-repos/scramjet/src/worker/index.ts:25
Current ScramjetConfig saved in memory.
cookieStore
Section titled “cookieStore”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
Section titled “serviceWorkers”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
Section titled “syncPool”syncPool:
Record
<number
, (val?
) =>void
> ={}
Defined in: typedoc-repos/scramjet/src/worker/index.ts:30
Recorded sync messages in the message queue.
synctoken
Section titled “synctoken”synctoken:
number
=0
Defined in: typedoc-repos/scramjet/src/worker/index.ts:34
Current sync token for collected messages in the queue.
Methods
Section titled “Methods”addEventListener()
Section titled “addEventListener()”Call Signature
Section titled “Call Signature”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.
Parameters
Section titled “Parameters”string
callback
Section titled “callback”EventListenerOrEventListenerObject
options?
Section titled “options?”boolean
| AddEventListenerOptions
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”EventTarget.addEventListener
Call Signature
Section titled “Call Signature”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.
Parameters
Section titled “Parameters”string
callback
Section titled “callback”EventListenerOrEventListenerObject
options?
Section titled “options?”boolean
| AddEventListenerOptions
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”EventTarget.addEventListener
dispatch()
Section titled “dispatch()”dispatch(
client
,data
):Promise
<MessageC2W
>
Defined in: typedoc-repos/scramjet/src/worker/index.ts:104
Dispatches a message in the message queues.
Parameters
Section titled “Parameters”client
Section titled “client”Client
MessageW2C
Returns
Section titled “Returns”Promise
<MessageC2W
>
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
fetch()
Section titled “fetch()”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.
Parameters
Section titled “Parameters”__namedParameters
Section titled “__namedParameters”FetchEvent
Returns
Section titled “Returns”Promise
<any
>
Example
Section titled “Example”self.addEventListener("fetch", async (ev) => {
...
if (scramjet.route(ev)) {
ev.respondWith(scramjet.fetch(ev));
}
});
loadConfig()
Section titled “loadConfig()”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.
Returns
Section titled “Returns”Promise
<void
>
Example
Section titled “Example”self.addEventListener("fetch", async (ev) => {
await scramjet.loadConfig();
...
});
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
route()
Section titled “route()”route(
__namedParameters
):boolean
Defined in: typedoc-repos/scramjet/src/worker/index.ts:167
Whether to route a request from a FetchEvent
in Scramjet.
Parameters
Section titled “Parameters”__namedParameters
Section titled “__namedParameters”FetchEvent
Returns
Section titled “Returns”boolean
Example
Section titled “Example”self.addEventListener("fetch", async (ev) => {
...
if (scramjet.route(ev)) {
...
}
});