In JavaScript, there seems to be some restrictions when changing the protocol of a given URL when using the URL
object. However, I can't find where this behaviour is documented (URL
, URL.prototype.protocol
) or why it would be intended for it to work like that.
Can anyone shine some light on this?
EDIT: The behaviour seems to be inconsistent across JS runtimes. Firefox, Node and Deno all "refuse" to change the protocol, but Chrome, Safari and Bun all "comply" with the change…
const url1 = new URL('http://example.com')
console.log(url1.protocol) // http:
url1.protocol = 'https:'
console.log(url1.protocol) // https:
const url2 = new URL('webcal://example.com')
console.log(url2.protocol) // webcal:
url2.protocol = 'https:'
console.log(url2.protocol) // webcal:, but should be https:
from Why can't the protocol of an URL object be changed for non-http(s) URLs in JavaScript?
No comments:
Post a Comment