Bookmarklet - Forgotten Web Browsers' Feature
Modern web is a horrible place. “Surfing the web” is more like swimming in the pool full of plastic garbage nowadays. Greater part of new websites is created using many unnecessary JavaScript frameworks, libraries, and other dependencies. I don’t say that is totally bad. There are many cases when they’re useful, but even simple article only websites are fulfilled with unnecessary scripts without any particular reason.
There are also web extensions. They provide many additional features, but they are slowing down the browser and have access to many private data you probably don’t want to share. Sometimes the extension is made only for one task, e.g. do some action on the website I’m currently on.
What if I tell you that you can remove some of them and keep their functionality? In all major browsers, like Firefox, Chrom(e)ium, Safari, and their forks (and even mobile versions) the feature called bookmarklet is supported. This mind-blowing technology was introduced 25 years ago and is supported to Date.now()!
Explanation
Bookmarklet is a bookmark that launches JavaScript instead of a website, that’s it and nothing more. They’re also called favelets sometimes.
Examples
You can select JavaScript lines below and grab them to your browser’s bookmark toolbar1.
Wayback Machine
Access dead website or save the state of it if it’s still (a)live2, without using any extension.
Viewing:
javascript:location.href='https://web.archive.org/web/*/'+document.location.href.replace(/\/$/, '');
Saving:
javascript:void(window.open('https://web.archive.org/save/'+location.href));
Source: Wikipedia
Dictionaries
Send your current selection to online dictionary or translator.
javascript:void(window.open('https://www.diki.pl/?q='+encodeURIComponent(document.getSelection().toString())));
Notes
Some services even offer their own bookmarklets you can use, e.g. Miniflux have a bookmarklet to add new feeds, and Linkding have one for adding bookmarks.
As you can see in my examples I use favelets mainly to call external services, but you can run any other scripts with some exceptions I mention in problems section.
Problems
Maybe you’re wondering why this technology isn’t widely used if it’s so good. It’s caused by Content Security Policy. It was created to mitigate XSS vulnerabilities on some websites, but it also causes that some bookmarklets will not work properly on all websites. The good news is that it doesn’t affect all bookmarklets, and many of them will work everywhere, especially ones I mentioned in examples.
-
Using third-party bookmarklets without verification is a really poor idea. This sentence is also valid if you replace word bookmarklets with extensions, bash scripts or just software at all. ↩︎