Skip to main content
Scramjet’s behavior is controlled through a comprehensive configuration system. This page explains all configuration options, feature flags, and how to modify settings at runtime.

Configuration structure

The ScramjetConfig interface defines all available options:

Initialization config

When creating a ScramjetController, 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
Default: /scramjet/

files

Paths to Scramjet’s runtime files:
These files are:
  • Injected into HTML documents
  • Served by your web server
  • Generated during the build process
Make sure these files are publicly accessible at the specified paths.

codec

The URL encoding/decoding functions:
Default codec:
Custom codec example:
Use base64 encoding for cleaner-looking URLs, but be aware it can make debugging harder.

globals

Names of global runtime functions injected into proxied pages:
Don’t change these unless you’re modifying Scramjet’s internals. The JS rewriter expects these exact names.

Feature flags

Flags control specific behaviors and features:

Flag details

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.
This is experimental and may not work with all sites.
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.
Type: boolean | Default: trueWhen enabled, enforces strict URL rewriting. Invalid URLs will cause errors instead of being silently ignored.
Disable this for compatibility with sites that have malformed URLs.
Type: boolean | Default: falseLogs timing information for rewriting operations to the console:
Enable this during development to identify performance bottlenecks.
Type: boolean | Default: trueCaptures errors that occur during rewriting and logs them. Prevents errors in Scramjet from breaking the proxied page.
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.
Type: boolean | Default: falseExperimental feature for enhanced obfuscation.
This is experimental and may break compatibility.
Type: boolean | Default: trueGenerates source maps for rewritten JavaScript. Allows browser DevTools to show original code.
Type: boolean | Default: falseUses destructuring assignment in rewritten JavaScript for potential performance improvements.
Type: boolean | Default: falseIntercepts file downloads and dispatches them as events instead of triggering browser downloads:
Type: boolean | Default: trueAllows malformed JavaScript to be served without rewriting. If the JS rewriter fails to parse code, the original code is returned.
Disabling this may break sites with syntax errors in their JavaScript.
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:
The flagEnabled() helper checks site-specific overrides:
Site flags are checked in order, and the first match wins. Be careful with overlapping patterns.

Runtime configuration

Modifying config

You can update configuration at runtime using modifyConfig():
This:
  1. Updates the in-memory config
  2. Saves to IndexedDB
  3. Notifies the Service Worker via postMessage
  4. Reloads codec functions
Config changes only affect new requests. Existing pages won’t be affected until they reload.

Reading config

Access the current config via the global config variable:

Loading config in Service Worker

The Service Worker loads config from IndexedDB:
Manual loading:

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:
This ensures:
  • Config persists across page reloads
  • Service Worker and clients use the same config
  • Runtime changes are preserved

Best practices

Start with default config and only change what you need. Most flags are optimized for compatibility.
Don’t modify globals unless you’re changing Scramjet’s internals. The rewriter depends on specific names.
Use site-specific flags to handle edge cases without affecting all sites:

Debugging config issues

Enable logging to see config-related information:
Check the current config in DevTools:

Next steps

Architecture

Understand how configuration flows through components

API Reference

See the full ScramjetController API