Bug 215375 - Inserting image with srcset into dynamically created iframe results in invisible image
Summary: Inserting image with srcset into dynamically created iframe results in invisi...
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: Images (show other bugs)
Version: Safari 13
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: BrowserCompat, InRadar
Depends on:
Blocks:
 
Reported: 2020-08-11 08:44 PDT by Comandeer
Modified: 2023-03-31 22:47 PDT (History)
6 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Comandeer 2020-08-11 08:44:33 PDT
Demo of the bug: https://jsfiddle.net/6Le9nwx7/

Inserting image with [srcset] attribute into dynamically created iframe results in the image that has its natural dimensions set to 0, therefore – it's not visible.

Tested on Safari 13.1.2 (15609.3.5.1.3).
Comment 1 Radar WebKit Bug Importer 2020-08-11 10:53:27 PDT
<rdar://problem/66849050>
Comment 2 Simon Fraser (smfr) 2020-08-11 11:14:30 PDT
Chrome also says 0x0. Firefox gives a size.
Comment 3 Said Abou-Hallawa 2020-08-11 16:44:52 PDT
(In reply to Simon Fraser (smfr) from comment #2)
> Chrome also says 0x0. Firefox gives a size.

This happens because the 'sizes' attribute is missing from the <img> tag. So in HTMLImageElement::selectImageSource(), we end up having sourceSize = 0.

And in pickBestImageCandidate(), we do this calculation:

    candidate.density = static_cast<float>(candidate.resourceWidth) / sourceSize;

but because sourceSize = 0, we calculate candidate.density = +inf.

And in HTMLImageElement::setBestFitURLAndDPRFromImageCandidate(), we do this calculation:

    m_imageDevicePixelRatio = 1 / candidate.density;

So we end up having m_imageDevicePixelRatio = 0. And this is why HTMLImageElement::naturalWidth() returns zero.
Comment 4 Ahmad Saleem 2023-03-31 22:47:04 PDT
(In reply to Comandeer from comment #0)
> Demo of the bug: https://jsfiddle.net/6Le9nwx7/
> 
> Inserting image with [srcset] attribute into dynamically created iframe
> results in the image that has its natural dimensions set to 0, therefore –
> it's not visible.
> 
> Tested on Safari 13.1.2 (15609.3.5.1.3).

Firefox Nightly 113: 300x372

Chrome Canary 113: 300x372 

Safari Technology Preview 166: 0x0