Skip to content

FIELD NOTES / A DECISION GUIDE

URL Encoder/Decoder Bookmarklet: Encode and Decode URLs on the Fly

Contents
AI-generated illustration; not taken on location · Comparison of component, whole-URL, and form-style URL encoding.
AI-generated illustration; not taken on location · Pick the mode before encoding: separators are data in one mode and structure in another.AI-generated illustration

When you are debugging an API request or inspecting a link on a live webpage, switching to a separate URL codec tab is a disruption. A URL encoder/decoder bookmarklet solves that problem by bringing encode and decode functionality directly into the page you are already viewing. FormatBits offers such a bookmarklet as part of its browser-based developer workbench, which also includes JSON formatting, timestamp conversion, and other data utilities. This article explains the design decisions behind the bookmarklet, how it avoids common pitfalls like double encoding, and how to install it safely. Whether you need to percent-encode parameter values, decode a messy query string, or break a URL into its parts, the bookmarklet keeps your workflow uninterrupted. All processing happens locally in your browser; no data is uploaded or saved.

Search intent and page promise

Who needs an on-page URL encode/decode bookmarklet?

Developers and technical users who frequently work with URLs in their daily browsing. Common scenarios include:

  • Inspecting a URL that contains percent-encoded characters and wanting to see the human-readable form without leaving the page.
  • Encoding a parameter value before manually constructing a query string.
  • Checking whether a URL has been double encoded (for example, finding %2520 where spaces were expected).
  • Quickly stripping tracking parameters (like UTM tags) from a URL before sharing it.

What the page must deliver

The page should provide a single clear call to action: a "drag to bookmarks bar" link (or a long-press alternative for mobile) that installs the bookmarklet. Once installed, the bookmarklet must allow the user to encode or decode a selected piece of text, the current page URL, or a value entered in a small dialog. The entire operation must happen without navigating away, without a server request, and without manipulating the host page’s normal behavior.

The page must also educate the user about the choices they need to make: component versus whole-URL encoding, how spaces are handled, and what to do when a decoding attempt reveals invalid percent sequences. By meeting this search intent, the page becomes a trusted reference that is also a practical tool.

URL encoding decisions users must make

Before using any URL encoder or decoder, the user should understand three key distinctions. These decisions directly affect the result and can prevent common errors.

Component versus whole-URL encoding

encodeURIComponent is designed for individual parameter values. It escapes structural characters such as &, =, ?, and / because those are reserved in a URL and should not appear as literal characters in a parameter value. encodeURI, on the other hand, is for whole URLs and preserves those delimiters so that the URL remains structurally valid. The bookmarklet should offer a selection between these two modes, possibly with a third option for form-style encoding (see below).

%20 versus + for spaces

In standard percent-encoding, a space becomes %20. In form-urlencoded data (the encoding used by HTML forms with application/x-www-form-urlencoded), a space becomes +. However, a literal plus sign in a value must be encoded as %2B. This distinction matters when decoding a query string that came from a browser form submission versus one that came from a manually constructed URL. The bookmarklet should handle both conventions and optionally let the user choose which decoding rule to follow.

Unicode and multi-byte sequences

Non-ASCII characters are encoded as multi-byte UTF-8 sequences. For example, a single Korean character uses three bytes and appears as three %XX pairs. The bookmarklet must decode such sequences correctly and re-encode them from Unicode input. A common mistake is to assume that one character becomes one percent-encoded pair; the tool should illustrate this with an example, perhaps using a character from a non-Latin script.

Double-encoding risks

Double encoding occurs when the percent sign itself is encoded, turning %20 into %2520 (because %25 is the encoding for the percent character). This often happens when a user or an automated system encodes an already encoded value. The bookmarklet should detect when the input appears to be double encoded and warn the user, allowing them to decode twice sequentially.

Image slot: image-1 (Comparison of component, whole-URL, and form-style encoding)

Bookmarklet mechanics and installation

How a bookmarklet works

A bookmarklet is a browser bookmark that contains JavaScript code instead of a URL. When the user clicks (or taps) the bookmark, the browser executes that JavaScript in the context of the currently open page. The code can read the page content, interact with the DOM, and perform any operation that the page’s JavaScript could normally do.

Construction of the bookmarklet code

To create the bookmarklet from readable source code:

  1. Write the JavaScript function that implements the encoder/decoder UI and logic.
  2. Optionally wrap the source in an immediately invoked function expression (IIFE) to avoid variable name collisions.
  3. Minify the code (for example, using Terser) to reduce its size.
  4. Percent-encode the minified code so that it can safely appear in a javascript: URL.
  5. Prepend javascript: to the percent-encoded string.

The result is a single line that the user saves as a bookmark.

Installation steps

On desktop browsers, the user can drag a link (provided on the FormatBits page) to the bookmarks bar. A link can have the form:

<a href="javascript:..." onclick="alert('Drag this to your bookmarks bar, then click it on any page.'); return false;">URL Encoder/Decoder Bookmarklet</a>

On mobile browsers, bookmarklet support varies. Many mobile browsers (including Safari on iOS and Chrome on Android) support bookmarklets, but adding them often requires a workaround:

  • Create a regular bookmark to any page.
  • Edit the bookmark’s URL and paste the bookmarklet code.

Some modern mobile browsers (like Kiwi Browser on Android) allow adding a bookmark directly from the context menu. The page should include instructions for the most common mobile browsers.

Invoking the bookmarklet

Once installed, the user can:

  • Work on selected text: Select a piece of text on the page, then click the bookmarklet. The tool reads the selection via window.getSelection(), encodes or decodes it, and shows the result in a small overlay or dialog.
  • Work on the current page URL: The bookmarklet can read window.location.href, parse it, and present the parts.
  • Accept typed input: A small input dialog allows pasting or typing a value manually.

Which input mode to use can be decided by the user via a simple toggle in the UI.

Security and trust boundaries

What a bookmarklet can and cannot do

A bookmarklet executes with the same permissions as the page’s own JavaScript. This means:

  • It can read and modify the DOM of the host page.
  • It cannot access data from other tabs or origins, except via CORS-allowed requests.
  • It is subject to the same Content Security Policy (CSP) that the page enforces. If the page’s CSP blocks inline scripts or eval(), the bookmarklet may fail.
  • It cannot access the user’s file system or other browser internals beyond what the page itself can do.

Honest safety language

Because the bookmarklet runs in the context of any page the user visits, it can theoretically change that page. The source code of the bookmarklet should be fully inspectable. The FormatBits page should publish the complete, unminified source code and explain how to verify that the installed bookmarklet matches it. Users are advised to:

  • Review the code, especially if the bookmarklet is used on sensitive pages (banking, email, admin panels).
  • Do not install bookmarklets from untrusted sources.
  • Understand that static inspection does not guarantee safety if the code makes external requests or manipulates the page.

The FormatBits bookmarklet does not make any network requests. All processing is local. The documentation should state this clearly.

CSP and cross-origin considerations

Some pages impose strict CSP headers that prevent the bookmarklet from running. In such cases, the user should see a clear error message, not a silent failure. The tool can catch CSP errors and display a message like "This page’s security policy blocked the bookmarklet." The user can then decide to copy the code to the browser console and run it there.

Mobile-first tool UX

Responsive layout

The bookmarklet’s UI overlay must work on small screens. Key design decisions:

  • Use a single-column layout with a maximum width that fits most mobile viewports.
  • The source and result panes should be stacked vertically, each with its own clear label.
  • Buttons (Encode, Decode, Copy) should be large enough to tap without zooming.
  • Avoid hover-only interactions.

Mode controls

The user must be able to switch between:

  • Component encoding (encodeURIComponent style)
  • Whole-URL encoding (encodeURI style)
  • Form-style encoding (where spaces become +)
  • Decode (auto-detect style or user-selected)

These controls should be visible at the top of the overlay as a segmented control or a set of radio buttons.

Copy actions and feedback

After encoding or decoding, the result should be easily copyable. The Copy button should use the Clipboard API (navigator.clipboard.writeText()) with a fallback for older browsers. After copying, a brief confirmation (e.g., "Copied!") should appear, then fade.

Length and status feedback

The overlay should show the number of characters in the input and output, especially when the input is the current page URL. If the output is very long, a scrollable area is needed. If the input is empty, the tool should indicate that in the UI.

Accessible error messaging

Errors should be displayed in plain text, not hidden in console logs. Use a red-tinted banner for errors (e.g., "Invalid percent sequence: %zz") and a yellow banner for warnings (e.g., "Appears double-encoded; try decoding again"). The error messages should be readable by screen readers (using role="alert").

Query-string workflows

Parsing the query string

When the user invokes the bookmarklet on the current page URL, the tool should break the URL into parts: protocol, host, port, path, and query string. The query string should be further parsed into an ordered list of key-value pairs, preserving duplicates and the original order. The user can then:

  • Edit individual parameter values.
  • Delete a parameter.
  • Add a new parameter.
  • Copy the modified query string.

Editable query tables

The parsed query parameters should be displayed in a table with three columns: Key, Value, and Delete button. The Value column should be editable inline. Changes propagate to the query string preview at the bottom, which the user can then copy or apply to the current URL (though applying to the current URL is a more advanced feature that may be out of scope for a lightweight bookmarklet).

Query-to-JSON conversion

A button labeled "Export as JSON" should generate a JSON object (or array for duplicate keys) from the parsed query parameters. This is useful for debugging API requests.

Stripping tracking parameters

The bookmarklet can include a predefined list of common tracking parameters (UTM parameters, fbclid, gclid, etc.). A button labeled "Strip trackers" removes all parameters that match. The user should be able to customize this list in a settings pane (stored in localStorage).

Error handling and diagnostics

Malformed percent-sequence detection

A URL decoder should identify exact malformed percent-encoding, such as %zz or a truncated multi-byte character, rather than failing generically. The tool should highlight the problematic part of the input and suggest a fix (e.g., "Invalid hex digit ‘z’ at position 5; expected 0-9, a-f, or A-F").

Double-encoding warnings

If the decoder detects that the result after the first decode still contains percent-encoded characters that look like they could be further decoded (e.g., %25 at the start of a sequence), the tool should show a warning: "Appears double-encoded. Try decoding again." The user can then click a "Decode again" button that re-applies the decoder on the current result.

Copy-disabled states

The Copy button should be disabled when:

  • The output field is empty.
  • An error is present (to avoid copying invalid data).
  • The browser does not support the Clipboard API (and the fallback also fails).

In the disabled state, a tooltip or aria-label should explain why (e.g., "Nothing to copy").

Examples that teach recovery

The page should provide at least two worked examples:

  1. Reserved characters: A URL with & and = in a single parameter value (e.g., ?q=a&b=c vs. ?q=a%26b%3Dc). Show how component encoding escapes the & and =.
  2. Spaces and plus signs: A query string containing + as a literal plus (e.g., ?sum=2%2B2 vs. ?sum=2+2). Explain the difference.
  3. Double encoding: Show the sequence: original ?name=John%20Doe → first decode → second decode → final result ?name=John Doe.

Cross-tool architecture and supporting content

Position within FormatBits

The URL encode/decode bookmarklet is one component of FormatBits, a browser-based developer workbench for JSON formatting, URL encoding/decoding, and Unix timestamp conversion. All tools share a core promise: no data is uploaded, nothing is saved on the server. The bookmarklet extends this by making the URL codec available on any page without leaving that page.

Related tools and articles

  • Main URL codec tool: A standalone page with a full two-pane interface for editing, with history and larger text areas. The bookmarklet complements it by providing quick access.
  • JSON formatter: Often needed when a query parameter contains a JSON string that is URL-encoded.
  • Timestamp converter: Useful when a URL contains a timestamp that needs interpretation.

The bookmarklet should link to these tools from its own UI (as a small icon or link) so that users can graduate to the full tool when needed.

FAQs and field notes

Q: Can I trust the bookmarklet with sensitive page content?
A: The source is fully inspectable and all code runs locally. However, as with any bookmarklet, you should review the code before using it on sensitive pages.

Q: Why does the bookmarklet not work on some pages?
A: Some pages have Content Security Policies that block inline JavaScript or certain functions. The bookmarklet will display an error in those cases.

Q: Can I use the bookmarklet offline?
A: Once installed, the bookmarklet code is stored in the bookmark; no network access is needed. It will work offline as long as the tool does not rely on external resources.

Field note: Developers often use the bookmarklet to quickly check whether a URL they are about to submit in a bug report is readable by others. A one-click decode of the page URL is the most common starting action.