Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
[css-sizing] Auto-resize iframes based on content #1771
Comments
|
I don't understand why “expand to fit element.style.height = 'inherit'
element.style.height = element.scrollHeight + 'px'I've written a little JavaScript function that can help me apply an auto-height or auto-width to elements that match CSS selectors here that uses this same logic: https://github.com/tomhodgins/reprocss/blob/master/mixins/auto-expand.js Mixin Demo: https://tomhodgins.github.io/reprocss/test/auto-expand-mixin.html Another Auto-Height demo: https://codepen.io/tomhodgins/pen/KgazaE Another Auto-Width demo: https://codepen.io/tomhodgins/pen/ZpLxjy As for auto-height |
|
With iOS, this is their default behaviour for iframes... they call it frame flattening. |
|
What happens when <style>
p { font-size: 100px; }
@media (min-height: 50px) { p { font-size: 1px; } }
</style>
<p>hi</p>gets iframed into <style>iframe { height: max-content; }</style>
<iframe src="is-this-a-circular-dependency.html"></iframe>? UPDATE: I see this has already been asked and that there are already some proposed answers. |
|
As a website developer, I'd be happy for the iframe to simply increase in size (so the scroll bars weren't required), and to not bother scaling back again. Which works quite well with the name |
|
This could be a win for accessibility (and monetization/conversion) for inserted adverts, where e.g. the user has specified a larger minimum text size than the default, but at the expense of page reflows as each ad slot gets populated. |
|
The Working Group just discussed
The full IRC log of that discussion<gregwhitworth> Topic: Auto resizing of iframes and textarea based on content size<astearns> github: https://github.com//issues/1771 <gregwhitworth> TabAtkins: there have been many requests for textarea and iframes resize on content <gregwhitworth> TabAtkins: we talked it over and thought, yeah probably ok <gregwhitworth> TabAtkins: we started experimenting with this <gregwhitworth> TabAtkins: figure our some mechanism content based sizing for textarea and iframes <gregwhitworth> TabAtkins: we learned some issues impl seamless with iframes due to COR leaking information <gregwhitworth> TabAtkins: we suspect we'd walk up the frame tree until we hit a fixed size to resolve the mqs <gregwhitworth> TabAtkins: Someone from Moz impl this <gregwhitworth> dbaron: we got the spec to say that's how media queries work, but seamless was removed <gregwhitworth> dbaron: we have code for it - but it's not necessarily something you can write up in a spec <gregwhitworth> dbaron: you need to figure out how to spec it <gregwhitworth> iank_: what type of interesting things <gregwhitworth> dbaron: I'd need to look, like it tries to do layout <fantasai> s/do layout/do layout, and then tries again/ <gregwhitworth> rossen: we used to have a technology that would allow you to do layout based on then content size and we killed it <smfr> q+ <gregwhitworth> Rossen: performance becomes a concern for those <tantek> The iframe use-case for me is known width (set by container), auto (preferably auto-expanding) height <gregwhitworth> Rossen: when you consider extensions they try to size the box, and it's shrink to fit it becomes very bad for perf <gregwhitworth> Rossen: Our experimentation for this suggests it was bad, but maybe you'll find something <gregwhitworth> TabAtkins: they're both pretty separate features anyways <Rossen> q? <gregwhitworth> TabAtkins: are we ok experimenting in this space <gregwhitworth> TabAtkins: the textarea would go into sizing 4 <gregwhitworth> smfr: we've had the auto sizing of the iframe even COR <gregwhitworth> smfr: it makes your frame layout outside in rather than inside out <gregwhitworth> smfr: we've had quite a few media query bugs <gregwhitworth> smfr: we ran into media query cycles <gregwhitworth> TabAtkins: that means that you weren't doing media queries the way we defined <smfr> q- <gregwhitworth> smfr: it does bring about nasty things in the code <gregwhitworth> TabAtkins: how is this different from regular layout <gregwhitworth> smfr: you can avoid laying out the iframe, if you have to you have to dirty the other nodes <gregwhitworth> TabAtkins: ok, let's talk about this later <gregwhitworth> dbaron: I think the media query problems you had were due to doing what authors weren't expecting <gregwhitworth> TabAtkins: this would be opt in <gregwhitworth> tantek: how do you trigger behavior in iOS <gregwhitworth> smfr: you always get it <gregwhitworth> smfr: users don't experience nested scrollers, we always wanted page scrolling to win so you don't get trapped <gregwhitworth> tantek: width is expected and height is auto <gregwhitworth> smfr: yes <gregwhitworth> Rossen: ok, so - it seems that Google wants to experiment with this - Apple has it and wants to remove it <gregwhitworth> Rossen: do you want a resolution <gregwhitworth> TabAtkins: The textarea one is simple enough to go into sizing 4 <gregwhitworth> TabAtkins: the iframe one can go in WICG <gregwhitworth> Rossen: any objections to adding textareas to CSS Sizing L3 <gregwhitworth> fantasai: yes <gregwhitworth> TabAtkins: I said 4 <gregwhitworth> Rossen: Ok, L4 <gregwhitworth> fantasai: ok - I'm ok with that <gregwhitworth> Rossen: Changes to sizing L4 <fantasai> fantasai: we can add a note for L3 <gregwhitworth> Resolved: Add textarea sizing to Sizing L4 <fantasai> RESOLVED: Add textarea sizing to Sizing L4 <gregwhitworth> *discuss whether to do in WICG* <gregwhitworth> TabAtkins to spin up a WICG regarding auto sizing of iframes <tantek> I'm a bit surprised that we're not even putting into a WD something that's been shipping in iOS for 10 years |
|
The auto-resizing (specifically height) of iframes is a highly desirable feature for authors. I have been using this feature for quite some time on my event posts, e.g.: http://tantek.com/2017/305/e1/homebrew-website-club I use an iframe to embed an unknown number of RSVPs generated by an external service, and it is quite handy (e.g. on iOS Safari) for that iframe of RSVPs to auto-grow (in height) as more RSVPs come in. I'd very much like to see iframe auto-sizing added to Sizing L4 as well. |
|
@tantek I'm in favor, but that requires addressing the security concerns at the very least; textarea doesn't have that consideration. If we work it out in the same timeframe as the rest of the features and get implementer backing, I'd be happy to have it in L4. |
|
I vote for max-content for Reason: the autosizing of textarea should be implemented, and also horizontal equivalent for width for BTW. |
|
Moving |
|
Note: The CSSWG resolved to accept this for |
From whatwg/html#555:
|
|
Since an This is actually great that something might actually happen, because it means we could finally:
|
|
I don't buy the security argument, who cares if someone knows that you are logged in somewhere? When couldn't you infer the same information using timing attacks to see if a resource has been cached? And any half-competent sysadmin worried about that kind of leak should be blocking frame embedding entirely. |
|
Could it be implemented for same-origin iframes please even if not all security concerns are sorted out for the foreign-origin scenario yet? |
|
What I'd be interested in seeing here is a more formal description as "contents" isn't really cutting it I think. It's effectively about resizing the viewport to some dimension and that definition will need to account for negative margins and other fun tricks. |
|
When an I'm fairly sure we can treat the width as fixed, as we do with the main browser window - where it will wrap the contents, or use a horizontal scroll bar when that's not possible (I think most developers will understand if they try to show something that's too wide). |
|
Yeah, I'm not really sure where all that machinery is defined and what defines that overflow to the left on ltr pages is ignored, etc. There is probably something there that can be used, but then there's also the complication of defining this in a way that works for mobile, where there's multiple viewports and such. |
|
Just a note on why this would be useful, even if only for same-origin iframes in the beginning: With Edge soon using chromium, all major browsers will support Encapsulating comments in a blog is a use case for |
|
@emilio the proposal for recursion appears to be to do an initial pass and then let the scrollbars appear as needed: https://github.com/craigfrancis/iframe-height/blob/master/problems/infinite-loops.md. |
|
So if you do layout during page load, then you get an empty iframe? What Roc implemented in Gecko was that media queries were resolved against the parent document. |
|
@emilio, I'll be very happy if you can improve on this... my suggestion it just there to make the most basic implementation that should work for both browser and website developers (I have since updated that page to note a suggestion where the child page could call a JavaScript method to request the height be updated, but that's just to round off the idea). |
|
Maybe my tone was harsh (sorry) but I am confused about the downvotes with regard to my comment on side channels.
I think relaxing the header policy for same origin and subdomains would be reasonable. At the very least, allow this to be set using |
|
Side-channels are indeed real and problematic and therefore we should strive not to introduce more of them. The primary security boundary of the web is origins and therefore subdomains are not that reasonable as you might think. |
I'm sorry, I understand wanting to err on the safe side. A lot of "technically less secure" arguments make implementation and uptake harder without materially impacting security. I was also just interested in what serious attack would be Ergonomics is my main concern, which can be addressed by making this feature controllable via HTTP headers and |
In https://lists.w3.org/Archives/Public/www-style/2017Aug/0045.html, Craig Francis said:
Just re-raising the suggestion of allowing an iframe or textarea to increase its height based on its content.
Mats Palmgren suggested that I raise this issue again, as Firefox is unlikely to implement it unless the CSSWG agrees to spec it.
For iframes, this feature would allow easy and secure (isolated) embedding of third party content without issues relating to scroll bars (i.e. needing custom JavaScript to ask the parent page, via postMessage, to change the iframe height).
For textrareas, this is just a convenience feature, as trying to get JavaScript to do this is tricky (e.g. the browser can automatically add/remove scroll bars, which can throw off the calculations).
When we discussed this last time (after the @seamless attribute on the <iframe> was removed from the WHATWG spec), it was suggested that we used:
In the case of the iframe, the child page would need to send a HTTP header (e.g. Expose-Height-Cross-Origin: 1), so it does not leak information about that website (e.g. if the user is logged in).
PS: This has been discussed in a number of times before, the earliest one I've found is 16 years old:
https://bugzilla.mozilla.org/show_bug.cgi?id=80713
And I've written up some notes about this feature, which includes the suggestion of using it for element height animation (e.g. disclosure widgets):
https://github.com/craigfrancis/iframe-height