Configuration structure
TheScramjetConfig interface defines all available options:
Initialization config
When creating aScramjetController, you provide a ScramjetInitConfig which has slightly different types:
The codec functions are serialized to strings when stored in config. This allows the Service Worker (which runs in a separate context) to deserialize and execute them.
Core options
prefix
The URL path prefix that identifies proxied requests.- Must start and end with
/ - Should be unique to avoid conflicts
- Used by the Service Worker to route requests
/scramjet/
files
Paths to Scramjet’s runtime files:- Injected into HTML documents
- Served by your web server
- Generated during the build process
codec
The URL encoding/decoding functions:globals
Names of global runtime functions injected into proxied pages:Feature flags
Flags control specific behaviors and features:Flag details
serviceworkers
serviceworkers
Type:
boolean | Default: falseEnables support for nested Service Workers within proxied pages. When enabled, sites can register their own Service Workers that will be emulated.syncxhr
syncxhr
Type:
boolean | Default: falseEnables synchronous XMLHttpRequest rewriting. When enabled, synchronous XHR calls are intercepted and proxied.Synchronous XHR is deprecated in browsers but some legacy sites still use it.
strictRewrites
strictRewrites
Type:
boolean | Default: trueWhen enabled, enforces strict URL rewriting. Invalid URLs will cause errors instead of being silently ignored.rewriterLogs
rewriterLogs
Type:
boolean | Default: falseLogs timing information for rewriting operations to the console:captureErrors
captureErrors
Type:
boolean | Default: trueCaptures errors that occur during rewriting and logs them. Prevents errors in Scramjet from breaking the proxied page.cleanErrors
cleanErrors
Type:
boolean | Default: falseRemoves Scramjet internals from error stack traces shown to the proxied page. Makes debugging easier for end users but harder for Scramjet developers.scramitize
scramitize
Type:
boolean | Default: falseExperimental feature for enhanced obfuscation.sourcemaps
sourcemaps
Type:
boolean | Default: trueGenerates source maps for rewritten JavaScript. Allows browser DevTools to show original code.destructureRewrites
destructureRewrites
Type:
boolean | Default: falseUses destructuring assignment in rewritten JavaScript for potential performance improvements.interceptDownloads
interceptDownloads
Type:
boolean | Default: falseIntercepts file downloads and dispatches them as events instead of triggering browser downloads:allowInvalidJs
allowInvalidJs
Type:
boolean | Default: trueAllows malformed JavaScript to be served without rewriting. If the JS rewriter fails to parse code, the original code is returned.allowFailedIntercepts
allowFailedIntercepts
Type:
boolean | Default: trueIf API interception fails (e.g., due to browser quirks), continue instead of throwing an error.Site-specific flags
You can override flags for specific sites using regular expressions:flagEnabled() helper checks site-specific overrides:
Runtime configuration
Modifying config
You can update configuration at runtime usingmodifyConfig():
- Updates the in-memory config
- Saves to IndexedDB
- Notifies the Service Worker via
postMessage - Reloads codec functions
Reading config
Access the current config via the globalconfig variable:
Loading config in Service Worker
The Service Worker loads config from IndexedDB:Codec configuration
Loading codecs
Codec functions are serialized to strings in config and deserialized at runtime:This allows the codec to work in the Service Worker context, which doesn’t have access to the original function objects.
Using codecs
Use the global codec functions for encoding/decoding:Default configuration
Here’s the complete default config:Configuration persistence
Configuration is stored in IndexedDB under the$scramjet database:
- Config persists across page reloads
- Service Worker and clients use the same config
- Runtime changes are preserved
Best practices
Debugging config issues
Enable logging to see config-related information:Next steps
Architecture
Understand how configuration flows through components
API Reference
See the full ScramjetController API