Bookmarklet maker: turn JavaScript into a bookmarklet

Paste your JavaScript, press Create bookmarklet, and drag the button to your bookmarks bar — or copy the javascript: URL into a bookmark on your phone. The code is wrapped and encoded in your browser and never uploaded.

How to use this bookmarklet maker

  1. Give the bookmark a name and paste your JavaScript into the code box — or press Load page-title sample to see a finished example. A leading javascript: is optional; the generator removes it and adds its own.
  2. Press Create bookmarklet. The generated URL appears below, with its length in characters.
  3. Drag the dark button onto your bookmarks bar. If the bar is hidden, turn it on from your browser's View menu or settings first.
  4. Open any page and click the bookmark. The script runs once, against that page.

Clicking the button on this page does nothing on purpose — a bookmarklet is meant to run on the page you are reading, not on the generator.

What a bookmarklet actually is

A bookmarklet is an ordinary browser bookmark whose address starts with javascript:instead of https:. Open a page, click the bookmark, and the browser runs your script against that page instead of navigating anywhere. Bookmarklets are useful for page-specific actions — copying a formatted citation, toggling a reading view, extracting selected text, or opening the current URL in another service. They require no extension installation, request no permissions, and live in the bookmarks bar like any other link.

How to convert JavaScript to a bookmarklet

Converting a script by hand takes three steps, and the generator does each of them for you. Here is a two-line script and the bookmarklet it becomes:

const n = document.links.length;
alert(n + ' links on this page');
javascript:(()%3D%3E%7B%0Aconst%20n%20%3D%20document.links.length%3B%0Aalert(n%20%2B%20'%20links%20on%20this%20page')%3B%0A%7D)()

1. Wrap the code in a function

The tool puts your code inside an immediately-invoked arrow function,(() => { … })(). That keeps your variables from colliding with whatever the page already defines, and it matters for a second reason: when the code in a javascript:URL finishes with a string value, the browser replaces the page with a new document showing that string. A function with a block body returns nothing, so the page stays put. Writing by hand, the classic alternative is to start the code with void.

2. Percent-encode it

Browsers strip raw tab and newline characters out of any URL before using it, so a multi-line script pasted straight into a bookmark gets squashed onto one line. A single //comment then swallows everything after it, and statements that relied on line breaks run together. Encoding turns each line break into %0A, which survives; the browser percent-decodes the code again just before running it. Encoding also protects spaces, double quotes,%, and #.

3. Add the javascript: prefix

The javascript: scheme is what tells the browser to run the rest of the address as script. The finished string is what you drag to the bar or paste into a bookmark.

How to install a bookmarklet

On desktop

Drag the dark button to the bookmarks bar in Chrome, Edge, Firefox, Safari, or any other desktop browser. If dragging isn't convenient, press Copy bookmark URL, create a new bookmark, and paste the URL into its address field.

On iPhone, iPad, and Android

Mobile browsers have no bookmarks bar to drag to, so use the edit method:

  1. Press Copy bookmark URL.
  2. Bookmark any page — this page works.
  3. Open your bookmarks, edit the new bookmark, and replace its address with the copied javascript: URL. Rename it while you're there.
  4. Go to the page you want to run it on. In Safari on iPhone or iPad, open the bookmark from your bookmarks. In Chrome on Android, type the bookmarklet's name into the address bar and tap the bookmark suggestion; opening it from the bookmarks screen leaves the page, so it has nothing to run on.

Don't paste it into the address bar

It looks like a shortcut, but Chrome deliberately removes a leading javascript: from text pasted into the address bar — a defense against scams that trick people into pasting malicious code. What's left is treated as a search. Saving the code as a bookmark is the reliable route.

Bookmarklet examples you can paste

Each of these uses only standard browser APIs. Paste one into the code box above, pressCreate bookmarklet, and install it.

Copy the page as a Markdown link

Opens a prompt with the link selected, ready to copy.

prompt('Markdown link:', '[' + document.title + '](' + location.href + ')');

Count the words you selected

Select text first, then click the bookmarklet.

const words = String(getSelection()).trim().split(/\s+/).filter(Boolean).length;
alert(words + ' words selected');

Make the page editable

Click again to switch editing off. Reloading restores the original.

document.designMode = document.designMode === 'on' ? 'off' : 'on';

Open the page in the Wayback Machine

Lists archived copies of the page you are on.

location.href = 'https://web.archive.org/web/*/' + location.href;

Common bookmarklet uses

GoalWhat the script does
Copy a citationWrites the page title to the clipboard — the sample built into this page.
Extract selected textReads the current selection and copies or reformats it.
Reveal hidden contentOverrides CSS that clips overflowing text so collapsed sections become visible.
Preview a style changeTemporarily recolors or restyles the page; a reload undoes it.
Send the page elsewhereOpens the current URL in a search, translation, or archive service.
Audit the pageCounts elements — images, links, scripts — and reports the totals.

Why a bookmarklet doesn't work

The site's security policy blocks it

If a bookmarklet works on most sites but does nothing on one, look at that site's Content-Security-Policy. The CSP specification says a page's policy should not interfere with bookmarklets, but browsers can still block javascript: URLs on pages whosescript-src rules are strict. A bookmarklet that injects a script from another domain is affected twice: even if it runs, the page's policy decides whether that outside script may load. Nothing in the bookmarklet can override this. If you need the script on such a site, a browser extension or userscript is the way around it.

The page turned into a blank page with text

Your code ended with a string value, so the browser displayed it as a new page. Remove anyreturn that hands back text. If you wrote the bookmarklet by hand, regenerating it here wraps it in a function, so a trailing string expression no longer replaces the page.

Nothing happens and there's no error

Open your browser's developer console, then click the bookmarklet again. Syntax errors, missing elements, and blocked scripts are reported there. A frequent cause in hand-made bookmarklets is a// comment that ended up on the same line as the rest of the code — regenerating from the original source fixes it.

How to edit an existing bookmarklet

Copy the bookmark's address, remove the leading javascript:, and decode the rest with the URL encoder and decoder to get readable code back. Make your change, paste the code into this bookmarklet maker, and replace the old bookmark's address with the new URL. Keeping the original source in a text file saves this round trip.

Security matters

A bookmarklet runs with the same access the page's own scripts have: it can read and change anything the page exposes. Review code before installing it, avoid snippets that load remote scripts — a URL someone else controls can change after you install — and never run an unknown bookmarklet on a page containing sensitive information. If a website, message, or video asks you to paste code into a bookmark or your address bar, treat it as a scam.

Bookmarklet vs userscript vs extension

The three look similar but answer different needs. A bookmarklet is one script that runs once, on one page, when you click it — zero installation, and it travels with your bookmarks. A userscript (managed by a userscript manager) attaches to matching sites and can run automatically on every visit, keeping its own settings between pages. Abrowser extension can do both of those and more — background work, network interception, toolbar icons — at the cost of an install step and broad permissions that the browser surfaces to you up front. Extensions are also treated differently by page security policies: the CSP specification notes that Chrome works to keep extension-driven injections working regardless of a page's policy. Start with the bookmarklet; upgrade only when you hit its limits.

Limits: when not to use a bookmarklet

A bookmarklet only runs when you click it, on one page at a time. It cannot keep state between visits, act in the background, or modify every page automatically. Length is rarely the problem — Chrome documents a maximum URL length of 2 MB — but a long script becomes an unreadable bookmark URL, and at that size a userscript manager or extension is easier to maintain. Changes a bookmarklet makes also vanish on reload: if you want highlights that are still there next time, see how to highlight text on any website and keep it. And if the job is "save this page with one click" rather than "run a snippet," a purpose-built browser extension does it without maintaining code.

Privacy: where your code goes

Nowhere. The name, the snippet, and the generated URL never leave the page — there is no network request involved in building a bookmarklet. One honest caveat: the finished bookmarklet is stored as a normal bookmark, so if you sync bookmarks across devices, the script travels with your other bookmarks and is visible to anything that can read that synced profile.

Related tools and guides

The Markdown-link bookmarklet above copies one link at a time; to turn a whole page's HTML into Markdown, use the HTML to Markdown converter. If the links you copy are full of tracking parameters, the URL cleaner strips them. For saving and working with pages without writing script at all, see Marqly'sweb highlighter, the bookmark manager for Chrome, and the second-brain workflow — or read the guide on how to organize bookmarks.

Frequently asked questions

What is a bookmarklet?

A bookmarklet is a browser bookmark whose URL starts with javascript:. Clicking it runs a small script on the page you are viewing instead of opening another website.

How do I convert JavaScript to a bookmarklet?

Wrap the code in a function so it runs in its own scope and does not return a value, percent-encode it, and put javascript: in front. This bookmarklet maker does all three steps: paste the code, press Create bookmarklet, and drag the result to your bookmarks bar.

How do I install the generated bookmarklet?

Drag the generated button to your bookmarks bar. If drag-and-drop is unavailable, copy the bookmarklet URL and paste it into the URL field of a manually created bookmark.

How do I add a bookmarklet on iPhone, iPad, or Android?

Mobile browsers have no bookmarks bar to drag to. Copy the generated URL, bookmark any page, then edit that bookmark and replace its address with the copied javascript: URL. In Safari on iPhone or iPad, open the bookmark from your bookmarks while viewing the page. In Chrome on Android, opening the bookmarks screen leaves the page, so give the bookmarklet a short name, then on the target page type that name into the address bar and tap the bookmark suggestion.

Why does my bookmarklet not work on some websites?

A likely cause is the site’s Content Security Policy. The CSP specification says page policies should not interfere with bookmarklets, but browsers can still block javascript: URLs on pages with a strict script-src policy. Other causes are a script error, code that depends on something the page does not have, or a bookmarklet that loads a script from another domain the page does not allow.

Why did the page turn into a blank page with text after I clicked a bookmarklet?

If the code in a javascript: URL finishes with a string value, the browser replaces the page with a new document showing that string. This generator wraps your code in a function so it returns nothing; avoid adding a return statement that returns text.

Can I paste a bookmarklet into the address bar instead?

Usually not. Chrome removes a leading javascript: from text pasted into the address bar, so the code is treated as a search or a web address. Save it as a bookmark instead.

Is there a length limit for bookmarklets?

Chrome documents a maximum URL length of 2 MB, so size is rarely what stops a desktop bookmarklet. Long bookmarklets are mainly hard to read and edit. If your script runs to hundreds of lines, a userscript or extension is easier to maintain.

Is the code executed by this generator?

No. This page only packages and displays the code. The generated button is prevented from running here; it executes only when you save it as a bookmark and click it on another page.

Are bookmarklets safe?

A bookmarklet can read and change the current page, so only use code you understand and trust. Some websites block bookmarklets with strict security policies.

Does this generator send my script anywhere?

No. The page reads what you type, wraps it in a function, URL-encodes it, and displays the result — there is no server call in the generator, and the snippet is transformed entirely on your device.

When should I use a userscript or an extension instead of a bookmarklet?

A bookmarklet runs once, on one page, only when you click it. If you need code that runs automatically on every visit, stores its own data, or works across sites in the background, a userscript manager or a browser extension fits better.

← All free tools