Skip to content

Allow URLs to be assigned to src property of HTMLImageElement #6440

@TimvdLippe

Description

@TimvdLippe

Running the following code in Chrome and Firefox will be successful (wasn't able to verify what Safari does):

let image = document.createElement('img');
image.src = new URL("http://google.com");
console.log(image.src);

I initially wanted to report to TypeScript that this doesn't typecheck (it reports Type 'URL' is not assignable to type 'string'.(2322)), until I discovered that the HTML spec itself doesn't allow for URL assignment: https://html.spec.whatwg.org/multipage/embedded-content.html#dom-img-src and it is a USVString (https://heycam.github.io/webidl/#idl-USVString). I am not deeply familiar with these contents, but as I understand the terminology, URL assignment would not be allowed.

Can we update the spec to allow for URLs to be assigned to the src property of an HTMLImageElement?

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