I'm trying to validate URLs in JavaScript and according to MDN JavaScript's URL API is compatible with Chromium browsers and Firefox. However the behaviour varies between the two engines. Specifically it seems like Chromium browsers are far more lenient and automatically apply encoding where Firefox doesn't.
I've tried encoding the URL myself first before validating with encodeURI('https://abc.co m'), but Firefox also doesn't accept https://abc.c%20m as a valid URL, so I'm stumped as to how I can have a good way to support both browsers without having to resort to regex.
I'm not sure why they are different, or who is correct. What is a consistent, correct approach with cross browser support for this?
Runnable snippet:
const url = new URL("https://abc.c%20m");
console.log(url.hostname);

%, so no excuse for chromium failwhatwg-url(repo, demo using the input in your question).