HTMLImageElement.currentSrc doesn't work on Playground
tez3998 opened this issue · comments
Summary
HTMLImageElement.currentSrc doesn't work on Playground.
URL
https://developer.mozilla.org/en-US/play
Reproduction steps
- Go to Playground
- Write the following code in the HTML box:
<img src="https://blog.mozilla.org/opendesign/files/2017/06/logo.png">
- Write the following code in the CSS box:
img {
width: 80%;
}
- Write the following code in the JavaScript box:
window.addEventListener("load", () => {
const image = document.querySelector("img");
console.log(image.currentSrc);
});
Expected behavior
The image source is displayed in console box.
Actual behavior
No text is displayed in console box.
Device
Laptop
Browser
Chrome
Browser version
Stable
Operating system
Windows
Screenshot
Anything else?
Replacing "currentSrc" with "src" in JavaScript box, the image source displayed correctly.
Validations
- I have read the Community Participation Guidelines.
- I have verified that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- I have checked that this is a concrete bug. For Q&A open a GitHub Discussion.
Hi @tez3998, 👋
Thanks for flagging this issue. I was able to reproduce it with your example in Chrome, although the example works in Firefox.
However, logging the currentSrc
with setTimeout
seems to work, so my conclusion is that this is not an issue with the Playground, but rather explained by Chrome returning an empty string when the image is not yet fully loaded.
From how I understand the specification for currentSrc, it looks like Chrome should behave like Firefox. So if you like, you could file a bug in the Chromium bug tracker.
Hi @caugner
Thank you for your reply and the valuable info!
As you think, this appears to be a Chromium issue, because my example did not work on Edge too.
Before I report this issue, I'll think about it myself for a minute.