Safari Extension - "Safari can't use javascript for this action"

Discussion in 'Mac Programming' started by hollerz, Mar 15, 2013.

  1. macrumors 6502a



    I don't know much about coding, so sorry if this is something stupid!

    I currently have a Pinterest bookmarklet in my bookmarks bar which runs this code when clicked:


    I want to move it to the toolbar, so I have made an extension with the code:

    <!DOCTYPE html>
    	<title>Pin It!</title>
    	<script type="text/javascript" charset="utf-8">
    function performCommand(event)
        if (event.command === "pinit") {
        var rUrl = "javascript:void((function(d)%7Bvar%20e=d.createElement('script');e.setAttribute('type','text/javascript');e.setAttribute('charset','UTF-8');e.setAttribute('src','//'+Math.random()*99999999);d.body.appendChild(e)%7D)(document));";
        safari.application.activeBrowserWindow.activeTab.url = rUrl;       
    safari.application.addEventListener("command", performCommand, true);

    The bookmarklet works fine when clicked, but the extension gives the error "Safari can't use javascript for this action". Anyone know what's wrong?

Share This Page