Header Injector

← All AI-created software

This is AI-generated (aka vibe-coded) software. It is specific to my needs and my system and may not work for you or yours. Support is limited, but if you report a bug I'll certainly look into it. The code is provided in the zip file for you to review should you choose.
⬇️ Download Header Injector.zip195.8 KBLast Updated: November 27, 2026Vivaldi

Adds custom HTTP request headers to the sites you choose, and shows which of your rules are actually firing. It’s for hitting a staging API that needs a token, testing a feature flag behind a header, or sending X-Forwarded-For to your own dev server. Chrome’s declarativeNetRequest engine sets the headers before the request leaves the browser, so nothing in the page’s code changes, and nothing the extension does leaves your browser.

The toolbar popup with four rules, two of them showing how many requests they matched
On this page

Install

  1. Open vivaldi://extensions and turn on Developer mode.
  2. Click Load unpacked and pick this folder. Keep the folder where it is, since the browser loads the extension from it.
  3. Pin the extension so the toolbar icon and badge stay visible.

After updating the files, click Reload on the extension card. Rules carry over.

Using it

Adding a rule

Click the toolbar icon, fill in the form and click Add rule. A rule has four parts:

Field Example Notes
Domain or URL pattern api.staging.example.com See “Matching” below
Header name Authorization Case-insensitive
Header value Bearer 3f9ac2e1b7 May be empty
Only from pages on this domain on See below

Tick or untick a rule to turn it on or off, and use the copy button to duplicate one and edit the copy instead of retyping a long token. The switch in the popup header pauses every rule without deleting anything; the toolbar icon greys out and the badge clears while it’s off. The badge otherwise shows how many rules are applied.

Manage all rules opens the full manager, which adds filtering, editing, import and export, the last URL each rule matched, and the backup schedule.

Matching

Domain is the default and covers most cases. It matches the host and any subdomain of it, on any port and any path. So example.com matches https://api.example.com/v1 but not https://other.test/?ref=example.com, and not a look-alike host such as example.com.evil.net.

URL pattern uses Chrome’s urlFilter syntax, for when a domain isn’t precise enough:

Pattern Matches
||localhost:3000^ localhost on port 3000 only
|https://api.example.com/v2 One path prefix
*/graphql That path on any host

|| anchors the host, ^ marks the end of the host or port, * matches anything, and | anchors the start or end of the URL. A * inside the host only matches within the host: api.*.example.com matches api.eu.example.com but not api.evil.net/.example.com. Type a port or a wildcard into the domain field and the rule becomes a URL pattern, with a note saying what it became. A leading *. is dropped, since a domain already covers its subdomains.

A URL pattern is a prefix match, so ||example.com alone would also match example.com.evil.net, and ||localhost:3000 would match port 30001. A bare ||host or ||host:port is saved with a ^ on the end to stop that. Other patterns are saved as typed, with a warning when they could match another site:

  • no || or |https:// at the start, so it matches any URL that contains it;
  • no ^ or / after the host, so it matches look-alike hosts;
  • a wildcard near the end of the host (example.*, api.*.com), which matches sites anyone can register.

These loose patterns are refused for headers that look like a credential (Authorization, Cookie, or a name containing token, key, auth, secret, session or passw), since any site you visit could receive them. Rules saved before 2.6 that break this show as Not applied with the reason.

Rules apply to main frames, frames, XHR and fetch requests, and scripts.

Only from pages on this domain

Without this option, an injected header works like a cookie: any page you visit can load https://api.example.com/... (a script tag or a fetch is enough) and the browser attaches your Authorization header to it. With it on, the header goes only on requests made by pages on the rule’s domain or its subdomains, plus addresses you open yourself (typing, a bookmark, a link) as long as they’re plain GET navigations. That’s the same deal as a SameSite=Lax cookie: a form on another site can’t POST to the API with your token.

It’s on by default for new rules. Turn it off when a page on another domain needs the header, such as app.example.com calling api.example.com. For a URL pattern, the domain is the host the pattern starts with, so the pattern must start with one (||api.example.com^, |https://api.example.com/). For a wildcard host such as api.*.example.com, it’s the part after the last * (example.com).

Two limits come from what Chrome lets an extension express:

  • Subdomains count as the same site. A rule for example.com accepts requests from any *.example.com page and sends the header to any subdomain.
    If some subdomains host other people’s content (user pages, uploads), name the exact host, such as api.example.com.
  • Any site can still open the address for you. The GET navigation exception doesn’t know who started it, so a link or redirect on another site that opens https://api.example.com/... as a page gets the header. Like a Lax cookie, that only matters if a GET on that host changes something.

Rules with a credential-looking header are marked any page while the option is off. In the full manager, any page · fix turns it on for that rule.

Match counts

The count under a rule is how many requests it has changed since the browser started, and when it last did. A typo’d header name or a pattern that matches nothing shows up as “No requests matched yet” instead of failing silently. Counts reset when the browser restarts; Clear counts resets them by hand. They’re buffered and written in batches, so a burst of requests can take a moment to show.

Chrome reports matches only to unpacked extensions.
Packed, the counts stay empty while the rules keep working.

If a rule shows Rejected, Chrome refused it and the message says why. The other rules keep working: when a batch fails, rules are applied one at a time, so one bad rule can’t take the rest down with it.

Import and export

Export in the full manager writes every rule, including disabled ones, plus the master switch and the backup schedule, to a JSON file. Import offers to add the file’s rules to yours or replace everything; Replace all also restores the master switch and backup schedule.

Imported rules get the same checks as the form. A rule with a header name Chrome won’t accept, or won’t let extensions change, is skipped, and the import dialog lists each skipped rule by number with the reason.
Rules from files that don’t say whether they’re same-site (a bare array, or an export from before 1.3) come in with “Only from pages on this domain” on when the header looks like a credential.

{
  "format": "header-injector/rules",
  "version": 1,
  "exportedAt": "2026-09-08T12:00:00.000Z",
  "rules": [
    { "enabled": true, "matchType": "domain", "match": "api.example.com",
      "key": "Authorization", "value": "Bearer …", "sameSite": true }
  ],
  "settings": {
    "enabled": true,
    "backupSchedule": { "enabled": true, "everyDays": 3, "keep": 3,
      "folder": "Header Injector Backups" }
  }
}

Rule ids are left out so an imported file can never collide with rules you have. A bare array of rules is also accepted, as is the old {"domain": …} field name.

Exports hold header values in plain text. They’re usually credentials, so keep the file out of version control and out of shared folders.

Backup and restore

The Scheduled backup panel in the full manager saves the same file Export writes into a folder inside Downloads (default Header Injector Backups, and it can be several levels deep) every N days, as header-injector-backup-YYYY-MM-DD-HHMMSS.json. Turning it on makes the first backup straight away. The schedule is checked every hour, so a backup that fell due while the browser was closed is made within an hour of opening it. Back up now makes one at once. Backups are skipped while there are no rules, so an empty setup never pushes out a good backup.

Only the newest backup from each earlier day is kept, for as many days as Earlier backups to keep allows, and old ones are removed only after a new backup has finished saving. Only backups this extension saved and the browser still lists in its downloads are ever deleted, so files you move or rename are left alone.

Restore reads a backup or export file and, after you confirm, replaces all your rules, the master switch and the backup schedule with what’s in it. The confirmation shows when the file was saved and what it holds. Older exports without settings replace only the rules. A restored file is checked the same way as the form, so a crafted file can’t store anything the form wouldn’t.

Limitations

  • Request headers only. Response headers aren’t supported.
  • Set, not append or remove. Each rule overwrites a header of that name.
  • Some headers are off limits. Chrome won’t let extensions touch Host, Connection and similar; the form refuses those names.
  • CORS preflight. A non-simple header on a cross-origin request triggers a preflight the server has to allow.
  • One flat list. There are no profiles; import and export cover switching between environments.

Troubleshooting

Backups are saved as download.json.
Another extension that renames downloads is overriding the backup’s name. Download Router keeps it; for other extensions, turn them off or check their settings.

A header doesn’t show up. Check DevTools → Network → the request → Headers → Request headers, with a hard reload, since cached requests can show provisional headers. To see what Chrome has registered, open Service worker on the extension card and run chrome.declarativeNetRequest.getDynamicRules().then(console.table).

Files

File Purpose
manifest.json Manifest V3, module service worker
background.js Service worker: applies rules, records match counts, toolbar icon and badge, scheduled backups, and the message handlers
lib/store.js Rule model, validation, matching, storage, import and export, backup file (tested in Node)
lib/dom.js DOM builders, icons, relative times, toasts
lib/ui.css Design tokens and shared components for both pages
popup.html, popup.js Toolbar popup: add a rule, switch rules on and off, live match counts
options.html, options.js Full manager: filter, edit, duplicate, import, export, scheduled backup and restore
shared/backup.js Shared backup helpers and scheduler, on globalThis.SharedBackup. A plain script, so the worker loads it with import and pages with <script>. Do not edit here
shared/sender.js Shared message-sender and host checks. Do not edit here
shared/suite.js Link to the Plugin Suite Backup Manager, on globalThis.SuiteLink. Do not edit here
shared/brand.js The “Made by infolific.com” footer on this plugin’s pages (logo, plugin page and hub links). Do not edit here
shared/infolific.png, shared/infolific-24.png The infolific.com logo, for the footer and (24px) the top of this README
test_store.mjs Node tests for matching, validation, migration, import and backup retention
test_messages.mjs Node tests for who may send which message to the service worker
icons/ Toolbar icons in active and -off sets, plus the icon.svg source (the PNGs add the infolific.com badge from tools/brand/badge-icons.py)
tools/make_icons.py Regenerates every icon PNG (needs Pillow and NumPy)
screenshot.png The screenshot above

tools/make_icons.py draws 16 and 32 px from a simpler two-line mark, since the three-line one blurs at that size. Keep both icon sets: background.js names all eight files and setIcon fails if one is missing.

Permissions

Permission Why
declarativeNetRequest Registers the header rules with the browser’s network engine
declarativeNetRequestFeedback Reports which rules matched, for the counts
storage Rules and the backup schedule locally, match counts for the session
alarms Hourly check for whether a scheduled backup is due
downloads Saving scheduled backups and removing old ones
<all_urls> modifyHeaders rules need host access to the sites they change

The extension has no network code of its own. Rules are kept in chrome.storage.local and don’t sync.

Security notes

  • Every message handler checks the sender with shared/sender.js. Rule syncs are accepted only from the popup and the options page, and Back up now only from the options page. The extension has no content scripts.
  • Rules from the form, an import, a backup and storage all go through validateDraft in lib/store.js. The worker re-checks stored rules on every sync, so a rule saved before a check existed shows as Not applied rather than being applied.
  • A * in a URL pattern’s host is sent to Chrome as an anchored regexFilter, since Chrome’s own * also matches / and could leave the host.
  • Credential-looking headers are refused on loose patterns, and “Only from pages on this domain” is on by default for new rules and for imported credential rules that don’t say.
  • Text is written with textContent and DOM building, never innerHTML.
  • The link to the Plugin Suite Backup Manager (shared/suite.js) answers only the manager’s fixed extension id. It can report the backup schedule and last backup, start a backup, and open the restore page with a backup file. It never writes settings itself, so a file it hands over goes through the same checks and confirmation as one picked on that page.

Tests

node test_store.mjs
node test_messages.mjs

lib/store.js is loaded as a module without a package.json, which needs Node 22.7 or later.

Version history

2.9.0 — infolific.com branding: a “Made by infolific.com” footer on the options and popup pages, linking to this plugin’s page and the infolific.com hub for AI-created software (shared/brand.js); a small infolific.com badge on the icons; and the manifest’s homepage_url points to the plugin’s page, so the extensions page shows a Website link.

2.8.0 — Works with the new Plugin Suite Backup Manager, which shows this plugin’s backup schedule and last backup, can start a backup, and can hand a backup file to the restore page here.
Only the manager’s extension id is answered (shared/suite.js).

2.7.0 — Brought in line with the plugin template.
Message senders are checked with the shared shared/sender.js: rule syncs only from the popup and the options page, and Back up now only from the options page. Added test_messages.mjs, a screenshot, and a README in the template’s layout. Requires Chromium 116 or later.

2.6.1 — Scheduled backups run on the suite’s shared backup code (shared/backup.js). Backup files, and restoring old ones, are unchanged.

2.6.0 — Security fixes. Wildcard hosts stay inside the host: api.*.example.com used to also match https://api.evil.net/.example.com, so these rules now go to Chrome as a regexFilter and can use “Only from pages on this domain”. Credential-looking headers on a loose pattern are refused, and existing ones show Not applied. Imports default to same-site for credentials when the file doesn’t say.

1.3.0 — Security fixes. Patterns saved as ||host or ||host:port gain a ^ the first time 1.3 reads them. *.example.com rules, which Chrome used to reject, become ||example.com^. New rules start with “Only from pages on this domain” on; existing rules keep sending from any page until edited. Stored 1.2 rules migrate on first read: each gains an id and an on switch, plain domains become domain matches and anything with a wildcard becomes a URL pattern. Matching is stricter than 1.2’s substring match, so a “domain” that was really a path fragment needs to become a URL pattern.

⬇️ Download Header Injector.zip195.8 KBLast Updated: November 27, 2026Vivaldi

← All AI-created software