1

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?

Community
  • 1
  • 1
Patrick
  • 93
  • 8
  • 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 Mar 03 '17 at 06:25
  • @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 Mar 03 '17 at 07:47
  • So your 'my URL' should be the same protocol and server name with the current page. – Than Ngo Hoai Mar 03 '17 at 11:00
  • Yes, I reckon that they are the same, otherwise it can't runs in my macOS without this error. – Patrick Mar 03 '17 at 12:10
  • 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 Mar 03 '17 at 12:12

1 Answers1

0

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

razvanco13
  • 121
  • 1
  • 3