← Back to release summary

URL.parse()

Category
Miscellaneous
Type
Chromium catches up
Status
In development (Chrome In development)
Intent stage
None

WPT details: https://wpt.fyi/results/url?label=master&label=experimental&aligned&q=url-statics-parse

Summary

Parsing url string and returning URL object. If it's invalid url format, returning null instead of throwing Error.

Motivation

Parsing string as URL has been done by `new URL(str)`. It returns an URL object or throws an Error when it's invalid. In some libraries it captures this error and returns `null` instead to make it easy to handle, it's done like below. ```js function URLparse(str) { try { return new URL(str) } catch { return null } } ``` `URL.parse()` is the standard API for covering this use-case. It returns null if the given string is invalid for URL.

Standards & signals

Ecosystem

Docs: https://github.com/whatwg/url/pull/825

View on chromestatus.com