Documentation claims that the WHATWG URL API should behave the same in Node.js and in a Browser, but here is a counterexample:
console.log(new URL('http://exa mple.com').origin)
Run this in the browser (or here on stack overflow) and you get http://exa%20mple.com
Run this in Node.js (or here on RunKit) https://runkit.com/embed/cfo21jyrrvxq and you get TypeError: Invalid URL
The browser's output is incorrect, that is not a valid URL. Is there a way to make the browser behave like Node.js? I would prefer a long-term standards-compliant solution to just installing another package.
This is a problem with Chrome's non-standard implementation of the URL interface. You could attempt to use Node's URL implementation in the browser.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With