Many of us come across interesting articles, tools, or resources online and wish to save them for later reference. Over the last couple of years I've tried using an application to keep all of my 'notes' in one place and recently moved to Obsidian.
I wanted a bookmarklet that would help me save interesting web pages to my Obsidian Vault so I can access it at a later date. I could use the browsers native bookmarking tools but I'm often across browsers throughout my working day. I could use available third-party tools - but I want to try to keep 'everything' in markdown, in Obsidian. This article you're reading now started off in Obsidian.
In this post, I’ll walk you through the bookmarklet, how it works, and how you can use it to streamline your bookmarking workflow.
What the Bookmarklet Does
This bookmarklet allows you to:
Capture the current webpage title and URL.
Optionally modify the title.
Add tags for easier categorisation.
Extract metadata like descriptions, images, and publication dates when available.
Save all this information directly into your specified folder in your Obsidian vault.
The full code
Breaking Down the Code
The bookmarklet uses JavaScript to gather data from the current webpage and construct a new note in your Obsidian vault. Let’s break it into steps.
Setting Up the Vault and Folder
These constants define where the captured notes will be stored. Replace everything and bookmarks with the name of your vault and the desired folder path.
Prompting for the Title and Tags
Title: The script captures the webpage’s title (document.title) and gives you the option to modify it via a prompt.
Tags: You can enter tags separated by commas to categorise the bookmark. If you skip this, the tags will remain empty.
Formatting Tags
This function:
Trims whitespace from each tag.
Replaces spaces with hyphens to make tags URL-friendly.
Prepends a # to each tag, turning them into Obsidian-compatible hashtags.
Extracting Metadata
Description
This retrieves the webpage’s description from tags.
Image
The script looks for Open Graph or Twitter image metadata to include a thumbnail.
Published Date
It checks for the publication date in the tags and formats it.
Sanitising the Title
This step ensures the title is valid for file names by removing characters that might cause issues.
Constructing the Note
The script then formats the note with the collected data:
Includes metadata (date, description, and image).
Appends the URL.
Adds any tags you’ve entered.
Sending the Note to Obsidian
Finally, the script redirects you to Obsidian’s URI scheme to create the note. This sends the note to the specified folder in your vault using Obsidian’s obsidian:// protocol.
How to Use the Bookmarklet
Customise It:
Copy the full JavaScript code.
Edit the vault and folder variables to match your Obsidian setup.
Create the Bookmarklet:
Create a new bookmark in Safari and paste the code into the URL field.
Use It:
While browsing, click the bookmarklet.
Enter a title and tags (optional).
The note will appear in your Obsidian vault.
These steps should work in all modern browsers, I've only used this in Safari.
Hot Linking
When you save a url as a bookmark in Obsidian the image that is save d is the url, we are hot-linking to someone else's resource on their server. That's not nice, so I created a node script that would
look into the bookmarks folder
find the image url in a markdown file
download the image to an assets folder in my vault
replace the hot link with the local link
Here's the script:
You will need to update the obsidianVaultPath and bookmarksFolderPath and also install axios (npm install axios).
There's a few issues with this script that I want to address -- sometimes the OG image is not a png, it seems Obisdian doesn't support something like WebP. If the image returned isn't recognised you would get the text of the file (better than hot-linking in my opinion).
In the future, I plan to share this on GitHub to make it easier for others to explore and contribute. I might even refine it further, like converting all images to PNG for consistency.
Initially, I considered adding a ‘to be sorted’ folder to organise bookmarks, but I realised tags provide an equally efficient solution.
I hope this inspires you to craft a bookmarking system that fits your workflow, especially if you’re using Obsidian.