Clean URL Parameters with Bookmarklet

What I Learned

When sharing URLs with others, query parameters and fragments can make URLs long and include unnecessary information. I used to manually delete them, but by combining a bookmarklet with Chrome’s search engine feature, I can now clean URLs using only keyboard shortcuts.

Details

Background

While browsing the web, URLs often have parameters like ?utm_source=... or #section. There are many situations where you want to remove these and have a simple URL, but manually deleting them is tedious. By registering a bookmarklet in Chrome’s search engine feature, you can instantly convert to a clean URL using only keyboard operations.

1. Bookmarklet Code

Use the following JavaScript code:

1javascript:void(location.href=location.href.split('?')[0].split('#')[0]);

This code removes everything after ? and # from the current URL and reloads the page.

2. Chrome Setup Steps

2-1. Open Search Engine Settings

Enter the following in Chrome’s address bar:

chrome://settings/searchEngines

2-2. Add Custom Search Engine

  1. Click the “Add” button next to the “Site search” section
  2. Enter as follows:
    • Search engine: URL Clean (any name is OK)
    • Shortcut: c (easy to type characters like z or del are also OK)
    • URL: Paste the bookmarklet code above
  3. Click “Add”

3. Usage

When you want to remove URL parameters while browsing:

  1. Cmd + L (Mac) / Ctrl + L (Windows) to select the address bar
  2. Enter the shortcut key you set (e.g., c)
  3. Press Enter

The page will reload with a clean URL.

Example

Before

https://example.com/article?utm_source=twitter&utm_campaign=promo#section1

After

https://example.com/article

Benefits

  • Fast: Completed with only keyboard operations
  • Simple: No extensions required
  • Customizable: Shortcut keys can be freely configured

References