Patch matched JavaScript files with sandboxed user-defined rules.
Script Patcher is a Manifest V3 browser extension project for Chrome and Firefox. It lets you define host-based patch rules, optionally narrow them to a JavaScript file URL pattern, and transform the response body before the script continues running in the page.
- Match rules by page host such as
example.comor*.example.com - Optionally filter only specific JavaScript request URLs with a regular expression
- Run user-defined patch functions in a sandboxed environment
- Toggle an alert banner before a patched script continues
- Optionally inject an in-page notification banner for all patched script of the page
- Import and export extension config as JSON
- Build Chrome and Firefox distributions from one repository
.
|-- Chrome/ # Chrome extension source
|-- FireFox/ # Firefox extension source
|-- dist/ # Build output
|-- scripts/ # Build scripts
|-- docs/ # ReadMe resources
|-- package.json # Project metadata and dependencies
- The extension watches tabs whose URL matches one of your configured hosts.
- When a matching
.jsresponse is detected, the extension checks your optional URL pattern. - Your patch function receives the original script body as a string.
- If your function returns a different string, the extension serves that patched body instead of the original response.
Chrome uses the debugger API plus an offscreen document to intercept and rewrite script responses. Firefox uses webRequest, webRequestBlocking, and webRequestFilterResponse for the same goal.
Each rule contains:
name: Friendly label shown in the UIhost: Hostname pattern to match against the current page URLpattern: Optional regular expression matched against the requested JavaScript URLalertOnScriptPatched: Whether to show a browser alert when the rule patches a scriptwebpageNotificationOnScriptPatched: Whether to inject the webpage notification helper when the rule patches a scriptscript: A function that receives the original script body and returns the patched body
Example rule:
/**
* @param {string} scriptBody Original script body content
* @returns {string} Modified script body content
*/
(scriptBody) => {
if (scriptBody.includes('search-string')) {
return scriptBody.replaceAll('search-string', 'replace-string');
}
return scriptBody;
}Example config export:
{
"rules": [
{
"name": "Replace feature flag",
"host": "*.example.com",
"pattern": "/assets/.*\\.js$",
"alertOnScriptPatched": false,
"webpageNotificationOnScriptPatched": true,
"script": "(scriptBody) => scriptBody.replaceAll('__FLAG__', 'enabled')"
}
]
}- VS Code
- Node.js 18+
- A Chromium-based browser for Chrome testing
- Firefox 140+ for Firefox testing
- VS Code Extension Run on Save (For automatically running tasks on save for minifying and copying assets)
npm installBuild both extensions:
npm run buildThe build script builds and copies the browser-specific source folders into dist/chrome and dist/firefox, and writes a dist/build-manifest.json summary file.
- Open
chrome://extensions - Enable Developer mode
- Choose
Load unpacked - Select
dist/Chromeor theChromefolder
- Open
about:debugging - Choose
This Firefox - Click
Load Temporary Add-on - Select the
manifest.jsonfile fromdist/FireFoxorFireFox
- Open the extension options page
- Toggle
Alert On Script Patchedif you want a visible notice before patched code runs - Add a new rule
- Enter a host such as
example.comor*.example.com - Optionally enter a JavaScript URL pattern regular expression
- Paste a patch function that returns a modified script string
- Save happens automatically while editing
- Use
Export JSONandImport JSONto move configurations between browsers or machines
debugger: intercept and fulfill script responsestabs: detect matching tabs and URLsstorage: persist rules and settingsoffscreen: run patch code in an offscreen sandbox host*://*/*: inspect requests on pages you choose to target
webRequest,webRequestBlocking,webRequestFilterResponse: intercept and rewrite script responsestabs: detect active tab URLsstorage: persist rules and settings*://*/*: inspect requests on pages you choose to target
- Only JavaScript files whose pathname ends with
.jsare patched - Invalid regular expressions or patch functions can cause a rule to fail
- Chrome can conflict with other tools already attached through the DevTools debugger
- Rewriting third-party scripts can break page behavior if the patch is unsafe
- Firefox support depends on APIs available in modern Firefox releases
No license file is currently included in this repository.






