Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript bookmarklet fails on certain sites, creates ghostly new <html> page

I noticed that my Javascript bookmarklet was failing on certain sites like Google Reader and Google search results pages (and randomly on some non-Google sites). Looking at the console, I could see that, for these pages, clicking the bookmarklet did not append elements to the head/body like it normally did, but created a new document that looked like this:

<html>
  <head></head>
  <body></body>
</html>

Even when I reduced my bookmarklet to javascript:alert(window.location.href); it would create this blank page and run the bookmarklet therein, so that the alert showed about:blank. On most sites, this blank page is not created and the correct location is shown.

Can someone explain this? Are these sites sandboxing externally run code as a safety measure?

UPDATE: I currently can't reproduce this on browsers other than Chrome 17.0.932.0 dev. Please let me know if anyone else can reproduce these results on Chrome or otherwise.

like image 922
glortho Avatar asked Oct 24 '22 19:10

glortho


2 Answers

I think this is a bug in Google Chrome, I've filed it to their bug database: https://bugs.webkit.org/show_bug.cgi?id=72606

like image 149
KIR Avatar answered Oct 27 '22 11:10

KIR


You need to ensure that the topmost code, i.e. the one right after javascript: does not return anything.

Usually this is done by wrapping everything in void():

javascript:void(alert(window.location.href));

It's very odd that it breaks with alert() though since the function itself doesn't return anything...

like image 45
ThiefMaster Avatar answered Oct 27 '22 09:10

ThiefMaster