Search code examples
javascriptdownloadgreasemonkeyuserscripts

Load a javascript resource from an external source, when it's blocked with a 403 status


For some reason my ISP is blocking the following URL:

http://assets.tumblr.com/javascript/prototype_and_effects.js

Chrome console states:

Failed to load resource: the server responded with a status of 403 (URLBlocked)

The result is I can't use Tumblr properly because many functions depend on this script. I have already contacted my ISP and asked them to stop blocking this URL, but meanwhile I would like to do something about it.

How can I load this resource externally? It could be a bookmarklet solution, userscript/Greasemonkey or any other thing you can think of.


Solution

  • A 403 status means that the server (assets.tumblr.com) blocked the request, not your ISP. The most common reasons a server does this are (a) because you've not logged in with sufficient access, and/or (b) The server didn't receive the referrer header and/or cookies it wanted, and/or (c) the request came from an IP address that the server has blacklisted. Using a proxy server can trigger any or all of these for some sites.

    This means that if you, or your proxy server, are being blocked from that file, then the standard methods of injecting remote javascript, that a userscript would use, will also be blocked.

    To get around this Greasemonkey can backfill the javascript file from a local copy. To do this:

    1. Create the file, Insure Tumbler has prototype.user.js, as shown below. Place it in a directory that is not in a temp folder on your machine.
    2. Download the prototype_and_effects.js file you referenced and place it in the same folder. You may have to use a different (or no proxy), or a different browser profile, or whatever. (It downloads just fine, for me, just by right-clicking the immediately-preceding link.)
    3. Install the script with Greasemonkey. (Firefox: File -> Open (CtrlO) will work.)
    4. The script tests for the Prototype and Effect libraries and loads them locally if one is missing. There may be more required to get Tumblr working again but, if so, that is beyond the scope of this question.
    5. Works in Firefox+Greasemonkey. Should work in Chrome+Tampermonkey (not tested), Will not work where @resource is not supported, such as straight Chrome.


    // ==UserScript==
    // @name     _Backfill Prototype and Effect libraries on Tumblr pages
    // @match    http://tumblr.com/*
    // @match    http://www.tumblr.com/*
    // @match    https://tumblr.com/*
    // @match    https://www.tumblr.com/*
    // @resource PandE_src  prototype_and_effects.js
    // @grant    GM_getResourceText
    // ==/UserScript==
    
    //-- Does this page load prototype_and_effects.js?
    var protoScriptNode = document.querySelector ("script[src*='prototype_and_effects']");
    if (protoScriptNode) {
        //console.log ("Page uses prototype_and_effects.js.");
    
        //-- Are Prototype and Effects loaded?
        var P   = unsafeWindow.Prototype;
        var E   = unsafeWindow.Effect;
        if (P  &&  P.Version  &&  E  &&  E.BlindDown) {
            //console.log ("Everything's loaded, no action needed.");
        }
        else {
            //console.log ("Loading prototype_and_effects.js");
            var PandE_src           = GM_getResourceText ("PandE_src");
            var scriptNode          = document.createElement ('script');
            scriptNode.type         = "text/javascript";
            scriptNode.textContent  = PandE_src;
            var targ                = document.getElementsByTagName ('head')[0];
            targ.appendChild (scriptNode);
        }
    }
    else {
        //-- No action needed
        //console.log ("Page doesn't use prototype_and_effects.js.");
    }