PHANTOM
🇮🇳 IN
Skip to content

Protocol/scheme-relative URLs should not throw ERR_INVALID_URL errors #62007

@jcgillespie

Description

@jcgillespie

Version

v25.6.1

Platform

Darwin redacted.local 25.3.0 Darwin Kernel Version 25.3.0: Wed Jan 28 20:53:05 PST 2026; root:xnu-12377.81.4~5/RELEASE_ARM64_T6020 arm64

Subsystem

url

What steps will reproduce the bug?

The following script will reproduce the bug. But simply put, any protocol-relative URL causes the error.

try {
    const badUrl = "//nodejs.org/static/images/node-mascot.svg";
    console.log("Attempting to parse protocol-relative URL: " + badUrl);

    const parsed = new URL(badUrl);
    console.log("Success! Parsed URL:", parsed.href);
} catch (error) {
    console.error("\\n❌ Error parsing URL:");
    console.error("Name:", error.name);
    console.error("Code:", error.code);
    console.error("Message:", error.message);
}

try {
    const goodUrl = "https://nodejs.org/static/images/node-mascot.svg";
    console.log("\\nAttempting to parse absolute URL: " + goodUrl);

    const parsed = new URL(goodUrl);
    console.log("✅ Success! Parsed URL:", parsed.href);
} catch (error) {
    console.error("Error:", error.message);
}

How often does it reproduce? Is there a required condition?

Reproduced every time a protocol-relative URL is used.

What is the expected behavior? Why is that the expected behavior?

Should parse successfully

What do you see instead?

TypeError - ERR_INVALID_URL - Invalid URL

Additional information

A protocol-relative URL is a common and valid URL format (WHATWG calls them scheme-relative).
https://url.spec.whatwg.org/#scheme-relative-special-url-string

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions