Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bookmarklet on https page

I'm trying to make a bookmarklet to use on youtube and other video sites in order to easily get information from the video and store it elsewhere.

From today, apparently I can't do that anymore since youtube force itself on a https connection and from what I've read on chrome's console window, the bookmarklet doesn't run on a https page. Is there a workaround?

Here is the edited code:

javascript:(function(){var jsCode=document.createElement('script');jsCode.setAttribute('src','http://[mysite]/b/enter.php?i=userid&r='+Math.random());document.body.appendChild(jsCode);}());
like image 387
maugch Avatar asked Jan 16 '13 20:01

maugch


People also ask

How do I use bookmarklet URL?

This can be inconvenient, so it's common to link bookmarklets when sharing. This is as simple as putting it in the href attribute of your link anchor. Now users can right-click and "Bookmark Link", or drag it to the bookmarks bar for easy access. Clicking the link on the web page will execute the script immediately.

How do I add a bookmarklet to my browser?

Install Bookmarklet In most browsers, you can add the bookmarklet to your favorites by dragging it to the toolbar/bookmark bar. Internet Explorer users: right-click the button and Add to favorites.

Do bookmarklets still work?

The bookmarklet concept appeared in Netscape's JavaScript guide in 1998, explaining how to use JavaScript code snippets to do things that the browser did not offer from the different menus. In 2021, current browsers and extensions already implement most of those functions, but they are still helpful.

How do I open a bookmarklet in Chrome?

Press Ctrl+Shift+B to show your bookmarks toolbar if you're using Chrome or Internet Explorer. In Firefox, right-click the toolbar and click Bookmarks Toolbar. Just drag and drop this link to your bookmark toolbar. The bookmarklet is now installed.


2 Answers

Google Chrome (and possibly other browsers?) blocks HTTP resources from being accessed from an HTTPS document. This is to prevent "mixed content" attacks, in which insecure HTTP scripts could be intercepted by an attacker in transit over the network and altered to perform any kind of malicious activity (e.g., leak cookies or sensitive page information to a third party). Such a violation would undo any protection granted by HTTPS.

Chrome used to provide a prominent warning that an insecure resource was blocked, but now it no longer does so, and all insecure loads silently fail. The only solution available to you at this time is to use HTTPS yourself when you serve the script.

like image 118
apsillers Avatar answered Sep 30 '22 07:09

apsillers


In Firefox, if you want to run a bookmarklet that references http on an https page, the way to get around this is to temporarily disable security.mixed_content.block_active_content. There are two ways to do this.

  1. go to about:config in a new tab, search for security.mixed_content.block_active_content and then toggle the value to false. Run your bookmarklet and then toggle it back to true (since you probably want it turned on most of the time).

  2. use an add-on / extension to toggle the block. A quick search turned up Toggle Mixed Active Content, and a quick test seemed to work well. There may be others.

Have fun and be careful. Here be dragons!

like image 42
caponica Avatar answered Sep 30 '22 08:09

caponica