Search code examples
javascriptrequestxmlhttprequestsame-origin-policy

Anyway to bypass same origin policy?


I just wanted to know if their was a way to get the page source of a domain which has the same origin policy? I have tried anyorigin, but my problem is that I am not authenticated into twitter by default. I would really appreciate the help! My code is below:

var request = new XMLHttpRequest();
request.open("GET", "https://twitter.com/", false);
request.send();
var sc = request.response;

Solution

  • No, there is not. It would not be much of a security measure if it could be circumvented. If you want to access Twitter data, use their API.

    Actually, there is a workaround that is possible: since same origin policy only affects clients, you can ask your server to fetch it for you. However, most sites that provide API frown on unauthenticated scraping, and might blacklist your site. Specifically, by Twitter ToS:

    however, scraping the Services without the prior consent of Twitter is expressly prohibited

    EDIT: The link by Skizo is excellent. But while it lists many ways to deal with the policy, none except serverside proxying will help you circumvent the policy on a non-cooperating third-party site.