Reputation: 6583
When opening new tab in Chrome/Firefox (ctrl+t), kind of "workbench" page is opened by default:
I have a very trivial bookarklet with following URL:
javascript:location.href="http://google.com"
While it works perfectly when opened from any "normal" page, there is absolutely no reaction when I click on the bookmark in the "workbench" mode (both in Chrome and FF). The URL in the browser doesn't change at all. (UPDATE: and even simplerjavascript:alert("test")
bookmarklet gives no results in this mode neither)
As workbench is my usual place from which I open bookmarks I would really like to be able open my bookmarklet from there.
Probably the problem is related with that part of bookmarklet definition:
the script is executed within the context of the current page.
And workbench isn't probably anything close to normal HTML page. Anyway I'd be glad to find some workaround.
PS. Of course my goal is to make more sophisticated bookmarklet than this but I wanted to start with anything that works and stucked on this problem :-).
Upvotes: 0
Views: 128
Reputation: 166
You are having an issue in the New Tab page because a security check on chrome:// pages.
We allow JavaScript URLs typed in the omnibox to bypass CSP. This is a separate security check that Cris added to block omnibox JavaScript URLs on chrome pages for security.
[Source]
The fix for this is to have the bookmarklet create a new page and inject the JavaScript into it. Here is an example URL you can save in your bookmarks.
data:text/html,<script>alert('This works');</script>
Upvotes: 0
Reputation: 3517
I think you've analyzed the problem correctly and there is no direct solution that I know of.
The workaround that I use for both Firefox and Chrome is to use about:blank
for my new tab page, which I prefer anyway. In Chrome this requires an extension.
If you want to keep the "workbench" for your new tab page and use bookmarklets from that page, will have to write or find an extension/addon, although even that may not be possible; I've never looked into it.
Upvotes: 1