1001Ferramentas
🔖Utilities

Bookmarklet Builder

Wraps a JavaScript snippet as a bookmarklet (javascript: link) ready to drag to the bookmarks bar.


  

Turning a JS snippet into a browser button

There is that little piece of JavaScript you paste into the console every week: highlight broken links, copy the page title, kill an annoying overlay. Opening devtools every single time gets old fast. The classic answer is a bookmarklet, a bookmark whose URL starts with javascript: and runs against whatever page is open. This builder wraps your snippet in the right shape.

What it does is collapse all whitespace to single spaces, wrap the code in (function(){ ... })(); and prefix it with javascript:. That wrapper is not decoration: because the function returns undefined, the browser stays on the page instead of replacing it with your code's return value. The collapsing has a real cost though. Everything becomes one line, so any double-slash comment swallows the rest of the code. Use block comments, or none at all.

The output here is plain text: a sample link and a URL line. Despite what the name suggests, there is no draggable link on the page, so create a bookmark by hand and paste the URL into its address field. Keep in mind that a bookmarklet runs with the open page's privileges, cookies and session included, so never paste code from a source you do not trust. Some sites with strict CSP still break bookmarklets, and behaviour varies by browser. Packaging happens locally.

Frequently asked questions

How do I install it if there is nothing to drag?
Create any bookmark, open its edit dialog, clear the address and paste the line starting with javascript:. Some browsers only let you edit the URL after the bookmark has been saved once.
Why does my bookmarklet do nothing?
The usual suspects are a double-slash comment that ate the rest of the now single-line code, a silent syntax error, or the site's security policy. Run the same snippet in the console first to rule out the code itself.
Can I use multi-line code?
You can write several statements separated by semicolons, but the input is a single line and the builder collapses whitespace anyway. For anything larger, a bookmarklet usually just injects an external script.

Related Tools