Creating a Bookmarklet That Emails the Current URL
Save the current page URL and title to your email when you select one bookmark.
A browser bookmarklet is a browser bookmark that uses JavaScript. This example sends the current page URL and title to an email target when you select the bookmark. Use it to save an article, share a link, or build a reading list.
Purpose#
Use this guide to:
- Build a JavaScript bookmarklet that calls a PayloadRelay endpoint.
- Configure an email target for the saved URLs.
- Add an optional note and tags to a saved link.
- Install the bookmarklet in a browser.
Before you start#
- Create a PayloadRelay endpoint that accepts
POSTwith theJSONpayload format. - Attach a confirmed email target to the endpoint.
- Cross-origin resource sharing (CORS) must permit the current page origin when
the bookmarklet uses
fetch(). The GET and image-pixel alternative in step 7 cannot show if the delivery was successful. A page Content Security Policy (CSP) can also block that alternative.
Procedure#
1. Create the endpoint#
- Open
Endpointsand selectCreate endpoint. - Set the accepted method to
POST. - Set the payload format to
JSON. - In
Outputs, attach your confirmed email target. - Save and copy the endpoint URL.
2. Basic bookmarklet#
This bookmarklet sends the current page URL and title to the endpoint:
javascript:void(fetch('https://api.payloadrelay.com/relay/YOUR_ENDPOINT_ID',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({subject:'Saved Link: '+document.title,url:location.href,title:document.title,saved_at:new Date().toISOString()})}).then(function(r){if(!r.ok){throw new Error('HTTP '+r.status)}alert('Link saved!')}).catch(function(e){alert('Failed to save link: '+e.message)}))Readable version:
javascript:void(
fetch('https://api.payloadrelay.com/relay/YOUR_ENDPOINT_ID', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
subject: 'Saved Link: ' + document.title,
url: location.href,
title: document.title,
saved_at: new Date().toISOString()
})
})
.then((response) => {
if (!response.ok) {
throw new Error(`HTTP ${response.status}`);
}
alert('Link saved!');
})
.catch((error) => alert(`Failed to save link: ${error.message}`))
)3. Bookmarklet with notes#
This version asks for an optional note before it sends the request:
javascript:void((function(){var n=prompt('Add a note (optional):','');if(n!==null){fetch('https://api.payloadrelay.com/relay/YOUR_ENDPOINT_ID',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({subject:'Saved Link: '+document.title,url:location.href,title:document.title,note:n||'(no note)',saved_at:new Date().toISOString()})}).then(function(r){if(!r.ok){throw new Error('HTTP '+r.status)}alert('Link saved!')}).catch(function(e){alert('Failed to save link: '+e.message)})}})())Readable version:
javascript:void((function() {
var note = prompt('Add a note (optional):', '');
if (note !== null) {
fetch('https://api.payloadrelay.com/relay/YOUR_ENDPOINT_ID', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
subject: 'Saved Link: ' + document.title,
url: location.href,
title: document.title,
note: note || '(no note)',
saved_at: new Date().toISOString()
})
})
.then(function(response) {
if (!response.ok) {
throw new Error('HTTP ' + response.status);
}
alert('Link saved!');
})
.catch(function(error) {
alert('Failed to save link: ' + error.message);
});
}
})())If you select Cancel in the prompt, the bookmarklet does not send the request.
4. Bookmarklet with tags#
This version asks for tags and an optional note:
javascript:void((function(){var t=prompt('Tags (comma-separated):','reading');if(t!==null){var n=prompt('Note (optional):','');if(n!==null){fetch('https://api.payloadrelay.com/relay/YOUR_ENDPOINT_ID',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({subject:'['+t+'] '+document.title,url:location.href,title:document.title,tags:t,note:n||'(no note)',saved_at:new Date().toISOString()})}).then(function(r){if(!r.ok){throw new Error('HTTP '+r.status)}alert('Link saved!')}).catch(function(e){alert('Failed to save link: '+e.message)})}}})())The email subject contains the tags, for example: [reading, tech] Article Title.
5. Install the bookmarklet#
Chrome, Edge, Firefox, Brave
- Show the bookmarks bar (
Ctrl+Shift+BorCmd+Shift+B). - Right-click the bookmarks bar. Select
Add pageorAdd bookmark. - Set a name that you recognize, for example,
📧 Save Link. - Paste the bookmarklet code, which starts with
javascript:, into the URL field. - Save.
Safari
- Open
Bookmarksand selectAdd Bookmarkfor a page. - Edit the bookmark. Right-click it and select
Edit Address. - Replace the URL with the bookmarklet code.
- Save.
Mobile (iOS Safari)
- Bookmark a page.
- Edit the bookmark, and replace the URL with the bookmarklet code.
- To use it, type the first characters of the bookmark name in the address bar, and tap the suggestion.
6. Configure the email target#
- Open
Relay targets. SelectAdd target, then selectEmail. - Enter the email address that receives the saved links.
- Use the confirmation link to complete the email target confirmation.
- Attach it to the bookmarklet endpoint.
Each time you select the bookmarklet, it sends an email with:
- Subject:
Saved Link: <page title>, or with the tags if you configure them - Body fields: URL, title, note, tags, timestamp
7. Handling CORS restrictions#
Some websites have a Content Security Policy that blocks a fetch() request to an external URL. A GET and image-pixel request does not read the response, and it thus does not need CORS. The page img-src CSP can still block the request:
javascript:void((function(){var d=encodeURIComponent(JSON.stringify({subject:'Saved: '+document.title,url:location.href,title:document.title,saved_at:new Date().toISOString()}));new Image().src='https://api.payloadrelay.com/relay/YOUR_ENDPOINT_ID?data='+d;alert('Save requested — check PayloadRelay Activity to confirm')})())The endpoint must accept a GET request with query parameters. A GET query string has a length limit, so use this method for a short payload. JavaScript cannot read the image response. The alert shows only that the browser tried the request. Look for Completed (ACCEPTED) in PayloadRelay Activity.
Expected result#
- A fetch bookmarklet shows a success message only after a 2xx response. The image fallback shows an alert for the request attempt. For the result, read Activity.
- The email arrives in seconds with the page URL, the title, and the optional note and tags.
- A request appears in PayloadRelay
Request activityasCompleted(ACCEPTED).
Common issues#
- The bookmarklet does nothing: make sure that the URL field starts with
javascript:and has no line breaks. - The
Failed to save linkalert: read the browser console. A Content Security Policy often blocks the fetch request. - No email: make sure that the email target is
Confirmedand that it is attached to the endpoint. - A CORS error: permit the current page origin, or use the GET and image-pixel version. If the CSP blocks
connect-srcandimg-src, the page cannot use either version. - The prompt does not appear: some browsers block a prompt from a bookmarklet on some pages. Use the basic version with no prompt.