1
votes

I ran my JavaScript file with phantomjs --web-security=no myfile.js successfully in my MacBook (with macOS), but fail to run it on Ubuntu, where it give out this error:

XMLHttpRequest Cannot Load https://[website].com Cross Origin
Requests are not supported

I find my problem is different from questions below

  1. XMLHttpRequest cannot load Cross origin requests are only supported for HTTP
  2. XMLHttpRequest cannot load https://www.[website].com/

For the first one, my error message is simply 'not supported', but not tell my 'only supported for HTTP' (though I send request to a HTTPS url). For the second one, my error message doesn't require the 'Access-Control-Allow-Origin' header.

I tried --debug=true option for PhantomJS, and it turned out that when running within Ubuntu, the PhantomJS silently dropping cookies.

Under my circumstance, could any one tell me how to fix this?

1
What is the actual parent request? The error is for sub request, maybe the protocol of parent and child requests are different. - Than Ngo Hoai
@ThanNgoHoai My request is simply var request = new XMLHttpRequest() and then request.open('GET','my URL',false); request.sent(). I don't know what is a sub request. - Patrick
So your 'my URL' should be the same protocol and server name with the current page. - Than Ngo Hoai
Yes, I reckon that they are the same, otherwise it can't runs in my macOS without this error. - Patrick
I tried --debug=true option in phantomjs. It turned out that when running within Ubuntu, the PhantomJS silently dropping cookies. I am afraid its the trigger of this error? - Patrick

1 Answers

0
votes

phantomjs seems to have an option which allows to make XMLHttpRequests from local files to a http server: --local-to-remote-url-access

For reference: http://phantomjs.org/api/command-line.html