v157 · url host parsing

Live host parser

Everything here runs through the browser you are reading this in. Type a URL and watch new URL() either take it apart or refuse it — and note that on a build before Chrome 157, the space cases below parse happily.

Parse a URL

Edge case suite

Each row states what the URL Standard requires. The verdict column is what this browser did, so a highlighted row is a build that has not shipped the change. Note the tab row: tab, LF and CR are on the forbidden list, but the parser removes them from the input before it ever looks at the host, so they parse rather than throw. The space is the one that now rejects.

Expected against observed, in this browser
inputper specthis browserhost

code path

function parseHost(input) {
  try {
    const url = new URL(input);
    return { ok: true, host: url.host };
  } catch (error) {
    // TypeError is the only thing the URL constructor throws.
    return { ok: false, reason: error.message };
  }
}

see also