1

Context:


Writing a browser based tool that hits a number of 3rd party URLs to see if we can hit that URL or not

Constraints

1. Has to be browser based 
2. I don't own the URL list (read it from a server and is maintained by someone else )
3. Some of the URLs (ie the servers) are not CORs enabled.

Traditionally, I would have used XMLHttpRequest and done something like this to see if there are Network Errors. However, since these are cross domain requests, and hence fail at pre-flight step.

What I have done so far is a hack. Here is the code. Basically dynamically creating a script tag, with src as the url I want to get.

var createScript = function(whitelist){
    var src = whitelist.url;
    var script = document.createElement('script');
    script.setAttribute('src', src);
    script.onload = function () {

        whitelist.success = true;
        $scope.$digest();
        return;
    };
    script.onerror = function (foo) {
            console.error(src,' ',foo);
        return;
    };
    angular.element(document.body).append(script);
};

Ive looked at the object being passed to the onerror but Ive not been able to get anything useful from it , which would help me understand why this failed. Also, both network errors and 403s both hit the onerror handler. For my purposes, success or failure to access a url is determined by network errors as opposed to getting for example a 403.

Question

With the given constraints is there a way I can identify success or failure. Success or failure as far as Im concerned is whether you can access a URL or not.

1 Answer 1

0

I ended up writing an installable chrome-app and a chrome extension for this. Either one can be used depending on your use case. The chromme extension is more if you want to use this same functionality from a 3rd party web page.

https://github.com/sajit/clienthealthcheck <-- chrome app

https://github.com/sajit/healthcheck_api <-- chrome extension

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.