Search code examples
javascriptjsdom

disable CORS checking in jsdom on nodejs


Is it possible to disable the CORS checking functionality in the jsdom node module?

The CORS errors are particularly difficult to debug in my use case (clientside testing) and do not occur in the actual environment I am running the program.

Perhaps some environmental variable we can set when initializing the object? e.g.,

window = new jsdom.JSDOM(``,{
    cors : false,
}).window;

Solution

  • As stated in this issue on JSDOM Github repository, JSDOM acts like a browser and the same-origin policy applies.

    It cannot be disabled from there.

    The solution would be to add headers to the resource server allowing the origin of the client which makes the request.