mdn / yari

The platform code behind MDN Web Docs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

  1. Go to Playground
  2. Write the following code in the HTML box:
<img src="https://blog.mozilla.org/opendesign/files/2017/06/logo.png">
  1. Write the following code in the CSS box:
img {
  width: 80%;
}
  1. 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

yari-playground

Anything else?

Replacing "currentSrc" with "src" in JavaScript box, the image source displayed correctly.
yari-playground-src

Validations

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.