Docs

URL.prototype.username

The username component of the URL.

Example

let url = new URL("https://user:[email protected]")
url.username
"user"
let url = new URL("https://example.com")
url.username
""
let url = new URL("https://example.com")
url.username = "admin"
url.href
"https://[email protected]/"