Scramjet uses a comprehensive configuration system to control behavior, feature flags, and URL encoding.
ScramjetInitConfig
The configuration interface for initializing Scramjet.
interface ScramjetInitConfig {
prefix : string ;
globals : {
wrapfn : string ;
wrappropertybase : string ;
wrappropertyfn : string ;
cleanrestfn : string ;
importfn : string ;
rewritefn : string ;
metafn : string ;
setrealmfn : string ;
pushsourcemapfn : string ;
trysetfn : string ;
templocid : string ;
tempunusedid : string ;
};
files : {
wasm : string ;
all : string ;
sync : string ;
};
flags : Partial < ScramjetFlags >;
siteFlags ?: Record < string , Partial < ScramjetFlags >>;
codec : {
encode : ( url : string ) => string ;
decode : ( url : string ) => string ;
};
}
Properties
The URL prefix for proxied content. Default: /scramjet/
Global variable names used by Scramjet’s runtime. Default: $scramjet$import
Default: $scramjet$rewrite
Default: $scramjet$setrealm
Default: $scramjet$pushsourcemap
Default: $scramjet$tryset
Default: $scramjet$temploc
Default: $scramjet$tempunused
Paths to Scramjet bundle files. Path to WASM file. Default: /scramjet.wasm.wasm
Path to full bundle. Default: /scramjet.all.js
Path to sync bundle. Default: /scramjet.sync.js
flags
Partial<ScramjetFlags>
required
Feature flags to enable or disable Scramjet features. See ScramjetFlags below.
siteFlags
Record<string, Partial<ScramjetFlags>>
Per-site feature flag overrides. Keys are hostnames or URLs. siteFlags : {
"example.com" : {
strictRewrites: false
}
}
URL encoding and decoding functions. Function to encode URLs. Default uses encodeURIComponent.
Function to decode URLs. Default uses decodeURIComponent.
Example
const config : Partial < ScramjetInitConfig > = {
prefix: "/scramjet/" ,
flags: {
serviceworkers: false ,
syncxhr: false ,
strictRewrites: true ,
captureErrors: true ,
sourcemaps: true
},
codec: {
encode : ( url ) => btoa ( url ),
decode : ( url ) => atob ( url )
}
};
ScramjetConfig
The internal configuration interface (extends ScramjetInitConfig with normalized types).
interface ScramjetConfig {
prefix : string ;
globals : { /* ... */ };
files : { /* ... */ };
flags : ScramjetFlags ;
siteFlags : Record < string , Partial < ScramjetFlags >>;
codec : {
encode : string ;
decode : string ;
};
}
ScramjetConfig is the same as ScramjetInitConfig, except the codec functions are serialized as strings and flags is complete (not partial).
ScramjetFlags
Feature flags that control Scramjet’s behavior.
type ScramjetFlags = {
serviceworkers : boolean ;
syncxhr : boolean ;
strictRewrites : boolean ;
rewriterLogs : boolean ;
captureErrors : boolean ;
cleanErrors : boolean ;
scramitize : boolean ;
sourcemaps : boolean ;
destructureRewrites : boolean ;
interceptDownloads : boolean ;
allowInvalidJs : boolean ;
allowFailedIntercepts : boolean ;
};
Properties
Enable service worker support. Default: false Enabling this may cause compatibility issues with some sites.
Enable synchronous XMLHttpRequest support. Default: false
Enable strict URL rewriting. Default: true When enabled, invalid URLs will throw errors instead of being silently ignored.
Enable verbose rewriter logging. Default: false
Capture and handle errors from proxified code. Default: true
Clean Scramjet internals from error stack traces. Default: false
Enable scramitization feature. Default: false
Enable source map support. Default: true
Enable destructuring in rewrites. Default: false
Intercept and emit events for downloads. Default: false
Allow invalid JavaScript to pass through. Default: true
Allow failed intercepts without throwing errors. Default: true
Example
const flags : Partial < ScramjetFlags > = {
strictRewrites: true ,
captureErrors: true ,
sourcemaps: true ,
interceptDownloads: true ,
cleanErrors: false
};
const scramjet = new ScramjetController ({
prefix: "/scramjet/" ,
flags
});
ScramjetVersionInfo
Version information for the current Scramjet build.
interface ScramjetVersionInfo {
/** The git commit hash that this build was created from */
build : string ;
/** The semantic version */
version : string ;
}
Example
console . log ( `Scramjet v ${ $scramjetVersion . version } ` );
console . log ( `Build: ${ $scramjetVersion . build } ` );