demo · v130

custom protocol router

Pre-Chrome 130, Blink's URL parser handled non-special schemes (anything other than http/https/ftp/file/ws/wss) as "opaque paths" — the whole thing past the colon was one string blob. That made it impossible to route by host or pathname for any of the real-world custom schemes we use every day. Chrome 130 follows the URL Standard. Paste any URL below to see the parser's host, pathname, port, and searchParams populate correctly for non-special schemes.

pre-Chrome 130 (opaque path)

Chrome 130+ (URL Standard)

the code

// Router for an Electron-like app — handles git://, ipfs://, web+foo://
const handlers = {
  "git:":     ({ host, pathname, searchParams }) => openGitIssue(host, pathname),
  "ipfs:":    ({ host, pathname }) => fetchFromGateway(host, pathname),
  "web+app:": ({ host, pathname, searchParams }) => mountRoute(host, pathname),
};

handler[link.href.split(":", 1)[0] + ":"](new URL(link.href));

// Pre-130: new URL("git://github.com/foo/bar").host returned "" and
// .pathname returned "//github.com/foo/bar" — useless for routing.
// Chrome 130+: .host === "github.com", .pathname === "/foo/bar".

see also