Error: Cross origin localhost forbidden on Ajax call ScalaJS

Viewed 151

I'm trying to perform a simple "GET" on wikipedia:

Ajax.get("https://en.wikipedia.org/w/index.php?title=Special:Random") map (_.responseText)

I get this error when I try to run:

[error] org.scalajs.jsenv.ExternalJSRun$NonZeroExitException: exited with code 1
[error]         at org.scalajs.jsenv.ExternalJSRun$$anon$1.run(ExternalJSRun.scala:186)
[error] stack trace is suppressed; run 'last Compile / run' for the full output
[error] (Compile / run) org.scalajs.jsenv.ExternalJSRun$NonZeroExitException: exited with code 1
[error] Total time: 3 s, completed Mar 4, 2021, 4:47:42 PM
Error: Cross origin http://localhost forbidden
    at dispatchError (C:\Users\mjwin\IdeaProjects\wiki-brain\node_modules\jsdom\lib\jsdom\living\xhr\xhr-utils.js:62:19)
    at Object.validCORSHeaders (C:\Users\mjwin\IdeaProjects\wiki-brain\node_modules\jsdom\lib\jsdom\living\xhr\xhr-utils.js:74:5)
    at Request.<anonymous> (C:\Users\mjwin\IdeaProjects\wiki-brain\node_modules\jsdom\lib\jsdom\living\xhr\XMLHttpRequest-impl.js:673:25)
    at Request.emit (events.js:315:20)
    at Redirect.onResponse (C:\Users\mjwin\IdeaProjects\wiki-brain\node_modules\request\lib\redirect.js:147:11)
    at Request.onRequestResponse (C:\Users\mjwin\IdeaProjects\wiki-brain\node_modules\request\request.js:986:22)
    at ClientRequest.emit (events.js:315:20)
    at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:641:27)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:126:17)
    at TLSSocket.socketOnData (_http_client.js:509:22) {
  type: 'XMLHttpRequest'
}

I've looked around for info on this error, but I'm still not sure what it means. I think I understand that I'm running into a CORS issue, but I don't understand what to do about it.

1 Answers

You need allowed to read a file into a URL:

Cross-Origin Read Blocking (CORB) blocked cross-origin response

Without allowing your url to access. Your script got an error.

Related