question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Image element src property does not allow URL assignment

See original GitHub issue

Bug Report

🔎 Search Terms

image src dom

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about 4.3.0

⏯ Playground Link

Playground link with relevant code

💻 Code

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

🙁 Actual behavior

Type 'URL' is not assignable to type 'string'.(2322)

🙂 Expected behavior

Compiles cleanly (confirmed supported per https://github.com/whatwg/html/issues/6440)

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
DanielRosenwassercommented, Mar 4, 2021

So hard-coding URL doesn’t make sense to me.

We’d want to be more permissive to a degree; letting anything in with a toString() seems undesirable, whereas unblocking a scenario like assigning URL instances to ~a property called url~ the src property seems reasonable.

1reaction
domeniccommented, Mar 3, 2021

It’s more subtle than that. Every DOMString or USVString will convert any input to a string. Technically, everything in JavaScript is convertible to a string, at the very least through Object.prototype.toString(). So hard-coding URL doesn’t make sense to me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

<img>: The Image Embed element - HTML - MDN Web Docs
The src attribute is required, and contains the path to the image you want to embed. The alt attribute holds a text description...
Read more >
HTML DOM Image src Property - W3Schools
The src property sets or returns the value of the src attribute of an image. The required src attribute specifies the URL of...
Read more >
Overriding HTML img src assignments - Stack Overflow
I am trying to dynamically override all IMG url assigments by redefining property of Image/HTMLImage object. It correctly intercepts assignments ...
Read more >
Create Image Elements in JavaScript - SoftAuthor
Create a static image tag with a src attribute with an image URL in the HTML file. ... output: As you can see,...
Read more >
A 4-Minute Guide to the Img src Attribute in HTML
That reference is found in the source attribute. The source attribute contains the path to the image file or its URL. That explains...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found