diff --git a/lib/internal/url.js b/lib/internal/url.js index 0e69ff52b5edef..f8152e998a9799 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -804,6 +804,16 @@ class URL { this.#updateContext(bindingUrl.parse(input, base)); } + static parse(input, base = undefined) { + try { + const url = new URL(input, base); + return url; + /* eslint-disable-next-line no-unused-vars */ + } catch (_) { + return null; + } + } + [inspect.custom](depth, opts) { if (typeof depth === 'number' && depth < 0) return this; diff --git a/test/fixtures/wpt/interfaces/url.idl b/test/fixtures/wpt/interfaces/url.idl index a5e4d1eb492e82..cd18a66e31b339 100644 --- a/test/fixtures/wpt/interfaces/url.idl +++ b/test/fixtures/wpt/interfaces/url.idl @@ -8,6 +8,7 @@ interface URL { constructor(USVString url, optional USVString base); + static URL? parse(USVString url, optional USVString base); static boolean canParse(USVString url, optional USVString base); stringifier attribute USVString href;