DevTools Logo

UserScript Header Generator

UserScript Header Generator

Build a valid ==UserScript== metadata block with @match grammar and grant/connect checks.

Runs in your browser
Try an example

Metadata fields

0 checks

Metadata block

0 errors
  • All checks passed.

UserScript Header Generator composes a canonical ==UserScript== metadata block from a small form. Chrome-style @match patterns are validated against the scheme/host/path grammar, @include globs are checked, versions must be semver, and grant/connect consistency rules flag missing @connect entries or illegal @grant none combinations. Manager profiles for Tampermonkey, Violentmonkey and Greasemonkey set sensible API grants. Paste an existing block to hydrate the form, or wrap a script body in a strict-mode IIFE.

Scoped match
// @match        https://example.com/*

The validator accepts exact schemes and hosts with a wildcard path, and rejects malformed host wildcards.

Network grant
// @grant        GM_xmlhttpRequest
// @connect      https://api.example.com

Cross-origin requests need both the grant and a matching @connect domain; missing connect is reported as a warning.

Manager profile
Tampermonkey → GM.setValue, GM.getValue, GM_xmlhttpRequest

Profiles prefill grants appropriate for the selected userscript manager.

Examples

Match pattern

Input
https://*.example.com/*
Output
@match https://*.example.com/*

A leading wildcard host is valid; a wildcard in the middle of a host is rejected.

Connected grant

Input
GM_xmlhttpRequest + https://api.example.com
Output
grant and @connect emitted

Cross-origin calls need both entries; without @connect a warning is shown.

Invalid grant mix

Input
none + GM.setValue
Output
validation error

@grant none disables the sandbox APIs, so it cannot be combined with GM_* grants.

About this tool

UserScript Header Generator writes a canonical ==UserScript== metadata block from form fields. Keys appear in the conventional order — name, namespace, version, description, author, match/include/exclude, connect, require/resource, grant, run-at — so the output is ready to paste into a .user.js file.

Validation covers the Chrome match-pattern grammar, @include globs, semver versions, http(s) URLs and manager consistency rules. A grant of GM_xmlhttpRequest without an @connect domain, or @grant none mixed with GM_* calls, is called out before you copy the block.

Manager profiles prefill grants for Tampermonkey, Violentmonkey and Greasemonkey. You can import an existing header to hydrate the form, optionally wrap a body in a strict-mode IIFE, and download the result. Everything happens in the browser.

What this tool does not do

  • Validation checks grammar and consistency, not runtime support of a specific manager version.
  • Only one script is edited at a time; imports replace the current fields.
  • The optional body wrapper is a plain IIFE, not a build step or module bundler.
  • Non-http(s) @connect URLs are rejected even where a manager might tolerate them.
  • Nothing is uploaded or persisted; copy or download the finished block.

How to use this tool

  1. Fill identity fields

    Set name, namespace, semver version and a description; @name and @version are required.

  2. Define targets

    Enter one @match pattern per line (or @include globs) and any @exclude patterns.

  3. Choose grants

    Pick a manager profile or type GM_* grant names manually; add @connect domains for cross-origin calls.

  4. Review checks

    Errors block the output; warnings and info notes explain narrowing opportunities and manager-specific caveats.

  5. Copy or download

    Copy the generated block, import an existing header to edit it, or wrap a body into a full .user.js file.

Use cases

New userscript

Start from a validated template instead of copying an outdated gist.

Pattern debugging

Check why a script does not run on a site by validating the @match grammar.

Manager migration

Switch grant profiles when moving a script between Tampermonkey and Greasemonkey.

Header cleanup

Import an existing block and re-emit it in canonical order.

Header grammar highlights

TokenRule
@matchscheme://host/path with scheme http/https/ws/wss/ftp/file/*, wildcard host only as * or *.domain, path starting /
@includeGlob pattern; .tld is supported by managers as a top-level-domain suffix
@connectExplicit http(s) host URLs; wildcards are not accepted
@versionSemver such as 1.2.3, with an optional leading v
@grantOne API name per line, or the literal none with no GM_* entries
@run-atdocument-start, document-body, document-end, document-idle or context-menu

Keys are padded to a fixed column width for readability; managers ignore the extra spaces.

Common mistakes

Mistake:Using @include where a @match pattern is required.

Fix:Prefer @match for precise scheme/host/path targeting; @include is a broader glob.

Mistake:Writing https://*/* for all hosts.

Fix:Use *://*/* or *.domain forms; a bare wildcard host triggers a warning outside file://.

Mistake:Forgetting @connect for cross-origin fetch.

Fix:Add the explicit https origin next to the GM_xmlhttpRequest grant.

Mistake:Combining @grant none with GM APIs.

Fix:Choose either the unsandboxed none mode or explicit GM grants, not both.

Mistake:Using a non-semver version such as 1.0.

Fix:Use three numeric components (1.0.0); a leading v is tolerated.

Frequently asked questions

What is the difference between @match and @include?

@match uses Chrome's strict scheme://host/path grammar and is the recommended, faster way to target pages. @include is a looser glob with conveniences such as .tld. The generator validates both, but prefers @match for precise targeting.

Why do I need @connect for fetch?

Userscript managers sandbox cross-origin requests. Granting GM_xmlhttpRequest or a fetch shim is not enough: each external origin must also be listed as an explicit @connect domain. The generator warns when a network grant has no @connect entries.

What does @grant none change?

It runs the script in the page context without GM API access. Because of that, it cannot be combined with GM_* grants; the generator reports that combination as an error.

Which @run-at value should I use?

document-idle is the safe default (after the page is ready). Use document-start when you must patch code before the page scripts run, document-body for early DOM access and context-menu for manager-triggered scripts.

How do I version and distribute the script?

Use a semver version such as 1.2.3 (a leading v is accepted). Optionally set @updateURL and @downloadURL to a stable raw file URL so managers can check for updates; both must be http(s) URLs.

Can I import an existing metadata block?

Yes. Paste the block into the script body field and press Import header. Repeated keys such as @match and @grant are collected, and the form regenerates them in canonical order with validation applied.

References & standards