On this page
- Key Takeaways
- How a bookmarklet URL works
- Create a harmless local test
- Troubleshoot a bookmarklet not working in a browser
- 1. Check the saved bookmark, not just the copied code
- 2. Compare the same page and action
- 3. Look for syntax and runtime errors
- 4. Check the browser's current guidance
- Safer alternatives
- Common Mistakes
- Best Practices
- Conclusion
When a bookmarklet works in one browser but not another, the problem may be the saved URL, the page where you run it, or a browser restriction—not necessarily the JavaScript itself. This guide uses a local test page to separate those possibilities without modifying a third-party site.
Key Takeaways
- A bookmarklet is a bookmark whose URL starts with
javascript:and contains JavaScript to run in the current page. - Test the same saved code on the same local page in both browsers before drawing conclusions about compatibility.
- A syntax error, a missing page element, and a browser security restriction can all look like a bookmarklet that does nothing.
- Browser-specific behavior and support instructions change. Check current official documentation for the browsers you use before relying on a particular workaround.
How a bookmarklet URL works
A bookmarklet stores code in the URL field of a bookmark. When the browser allows it to run, the code acts in the context of the current page. For example, it can look for an element in that page and change its text.
The javascript: prefix identifies the URL as JavaScript rather than an ordinary web address. A small function wrapper keeps temporary variables local. The example below returns no page content from the function, rather than deliberately returning a string that could be treated as a replacement document.
Execution is not guaranteed on every page. Browsers can restrict script execution in sensitive contexts, and page security policies or browser settings can affect what is allowed. Browser-internal pages, extension pages, local files, and ordinary websites may be treated differently. A bookmarklet does not acquire extension privileges just because it is saved as a bookmark.
Advertisement
Create a harmless local test
This demonstration only changes text in a local file. It does not collect data or contact a server. The code has not been executed for this article; use the steps below to check it in your own browsers.
- Save the following as
bookmarklet-test.htmlon your computer:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Bookmarklet test</title>
</head>
<body>
<p id="bookmarklet-demo">Bookmarklet has not run.</p>
</body>
</html>
- Open that file in the browser you want to test. Its address should use the
file:scheme. - Create an ordinary bookmark, then edit its URL field. Replace the entire URL with this single line:
javascript:(()=>{if(location.protocol!=="file:")return;const el=document.getElementById("bookmarklet-demo");if(el)el.textContent="Bookmarklet ran.";})();
- Save the bookmark, return to the test page, and activate the bookmark from your bookmarks menu or toolbar.
If the browser permits the bookmarklet to execute on the file, the paragraph should change to “Bookmarklet ran.” The file: check makes this particular example return without changing an ordinary website; the element check prevents an error if the test element is absent. It is a demonstration guard, not a general security boundary for arbitrary bookmarklets.
If nothing changes, reload the page before each retry. A browser may treat local files differently from normal web pages, so failure here does not by itself prove that bookmarklets are disabled everywhere.
Troubleshoot a bookmarklet not working in a browser
1. Check the saved bookmark, not just the copied code
Open the bookmark editor and inspect the complete URL field. It should begin with javascript: and contain the full example on one line. Check for missing punctuation, extra characters, typographic quotation marks, or a URL field that was saved as an ordinary address instead.
Pasting a javascript: URL into an address bar is not necessarily equivalent to activating a saved bookmark: browsers may process pasted text differently. Use the saved bookmark for this test. Bookmark editing and synchronization interfaces also differ, so confirm the actual saved value separately in each browser.
Characters such as #, percent signs, and non-ASCII text can complicate more elaborate bookmarklet URLs because the browser must interpret a URL as well as JavaScript. Keep the minimal example unchanged until it works.
2. Compare the same page and action
Open the same local test file in each browser, verify the initial paragraph, and activate the corresponding saved bookmark. Check that you are not accidentally testing a browser settings page, a new-tab page, or a different tab.
If the local test works in both browsers but another bookmarklet fails, inspect what that bookmarklet expects from its page. An element may have a different ID, may not exist yet, or may be inside a frame rather than the top-level document. A script written for one page layout can fail after the layout changes, even when the browser permits it to run. Wait for the page to load and check the target element and frame before changing the code.
If the minimal test works in one browser but not the other, compare the saved URLs, the page address, settings, and any messages in developer tools. That result narrows the investigation; it does not identify a specific browser restriction by itself.
Advertisement
3. Look for syntax and runtime errors
Open the browser's developer tools on the local test page, select its console, clear old messages, and activate the bookmarklet again. A syntax error can indicate damaged JavaScript; an error about a missing element or unavailable property points toward an assumption in the script. A security or policy message may point toward a restriction, although the wording and visibility of messages vary.
No console message does not prove the code ran: the bookmark may not have been activated as expected, or the browser may not have reported the failure there. Equally, a warning elsewhere in the console is not necessarily caused by your bookmarklet.
For more complex code, inspect it as readable JavaScript separately from the bookmark URL. Fix parse errors and verify that the page contains the expected elements before investigating browser policy. Do not use developer tools to bypass an access control or a restriction imposed by a site.
4. Check the browser's current guidance
Consult the official support documentation for each browser and version you use, especially for bookmark editing, JavaScript settings, local files, and restricted pages. Also check whether an extension or an organization-managed setting affects the workflow. Follow your organization's policy rather than attempting to override managed controls.
No browser documentation or support pages were available for verification in preparing this article, so it does not assert a current browser-specific cause or fix. Verify any version-specific instructions before publication or before changing settings.
Safer alternatives
- Use a manual workflow. For occasional tasks, use the page's own controls or copy information you are authorized to use into a local document. This avoids relying on a page's internal markup.
- Use a properly permissioned extension. For a repeat task, an extension can provide a clearer interface and explicit permissions. Request only the site access and capabilities it needs, review its source or publisher, and follow your browser's extension guidance. An extension does not automatically bypass page or organizational restrictions.
- Keep bookmarklets small and reviewable. A bookmarklet runs code in the page context when allowed. Only save code you understand and trust; do not run an unknown bookmarklet on a sensitive page.
Common Mistakes
- Treating every silent failure as a browser security block instead of checking the saved URL, page, and console.
- Assuming code that works on one site will find the same elements on another.
- Testing through the address bar and assuming the result matches clicking a bookmark.
- Using a third-party page as a test target when a local file is sufficient.
- Installing a broadly permissioned extension simply to avoid diagnosing a small script.
Best Practices
Keep a readable source copy of each bookmarklet as well as the saved URL. Test changes on a page you control, record which page and browser you tested, and review permissions before using any alternative. When a restriction is encountered, choose a permitted workflow rather than trying to circumvent it.
Conclusion
Start with a known local page and inspect the exact saved bookmark in each browser. Once syntax, page context, and activation are accounted for, use current official browser guidance to investigate any remaining restrictions.
What would your domain sell for?
A free TidyURLs account unlocks the Domain Estimator. It prices a name from 191,011 real domain sales.