Bug 193663

Summary: Cannot select text in iFrame with top padding on iOS
Product: WebKit Reporter: Mark W <mark.watkins1>
Component: FramesAssignee: Nobody <webkit-unassigned>
Status: RESOLVED DUPLICATE    
Severity: Normal CC: megan_gardner, simon.fraser, webkit-bug-importer, wenson_hsieh
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: iPhone / iPad   
OS: iOS 12   

Description Mark W 2019-01-21 19:53:53 PST
It seems that mobile selection on iOS devices does not work correctly when text is contained within an iFrame that is offset (padded, margined) from the top of the page.

In the example below, if one opens the page: https://viking2917.github.io/mobileselectionbug/ on an iOS mobile browser, and them tap-and-hold on the word "amet" in the first line to select it, then attempt to expand the selection by dragging the text selection drag handles, the drag handle will immediately jump down to near the bottom of page, and if you drag it around you will see the drag handle is offset from your finger (looks like by the amount the iFrame is offset from the top of the page).

The HTML to reproduce this (hosted at the link above):

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, user-scalable=no">
  </head>
  <body>
    <div>
      <div>
    <div style="height: 200px;"></div>
    <iframe srcdoc="<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam dignissim neque nec ante suscipit semper. Sed sit amet rutrum metus, in mattis ante. Quisque at nunc tellus. Maecenas ut rhoncus erat, sit amet ultricies augue. Aliquam et consectetur mauris. Pellentesque porttitor accumsan pretium. Vivamus risus lorem, varius in laoreet vel, interdum nec metus. Nam gravida vehicula lorem at lobortis. Curabitur sit amet libero ut nulla fermentum volutpat sed at mauris. Ut mollis at tellus vel tincidunt. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Integer lacinia iaculis odio, sed tincidunt massa accumsan a. Aliquam arcu urna, ullamcorper sagittis nunc eu, facilisis tempor felis. Ut fermentum justo in risus ullamcorper, tempus viverra neque venenatis. Aenean lectus sapien, interdum ut congue non, hendrerit sed diam. Suspendisse ante tellus, luctus eget ex eu, faucibus porttitor nulla.</p><p> Aliquam iaculis placerat tincidunt. Donec justo ligula, dictum ac volutpat accumsan, molestie eu est. Pellentesque lectus est, elementum sed finibus non, scelerisque a nunc. Cras id ornare turpis. Quisque consequat erat turpis. Vestibulum ut nulla feugiat, pretium eros et, dignissim nisi. Sed et finibus turpis. Morbi viverra vulputate lacus.</p><p>Sed in lorem laoreet, gravida metus nec, cursus nunc. Proin dignissim elit id urna imperdiet commodo. Nullam laoreet elementum risus vel tristique. Praesent aliquam ante id nibh condimentum, in semper lectus porta. Proin commodo leo sit amet finibus consectetur. Nam posuere lorem elit, at eleifend odio lobortis nec. Aenean ultricies tellus nec nunc porta, id hendrerit dui malesuada. Aliquam vel lacus feugiat tellus fermentum sollicitudin. Suspendisse consectetur ipsum ac ligula tincidunt molestie. Aenean vel ex eget justo pretium sodales eu sed lectus. Quisque malesuada rutrum tincidunt. Cras sit amet massa pulvinar, fermentum ante in, tristique diam. Etiam nec semper mauris. Donec ultricies purus ut est scelerisque eleifend imperdiet accumsan mi.</p>">
    </iframe>
      </div>
    </div>
  </body>
Comment 1 Radar WebKit Bug Importer 2019-01-22 14:17:55 PST
<rdar://problem/47459916>
Comment 2 Wenson Hsieh 2019-01-22 14:36:44 PST
Hi Mark,

Thanks for the report! I'm unable to reproduce this on trunk WebKit; I suspect this may have been fixed after <https://trac.webkit.org/r234661>. What minor version of iOS 12 did you test on?
Comment 3 Mark W 2019-01-22 14:44:44 PST
Thanks for the quick response! It occurs for me on an iPad Mini running 12.1.3 (16D39) as well as in the xCode simulator running 12.1 (16B91). 

Thanks also for pointer to 234661. If that indeed corrects this issue, when would that be available to devices? (I don't know how to download a nightly build to a device but if you tell me how I'd be happy to do that and see if it corrects). 

(probably out of your purview but the originating issue actually occurs in an ionic app that uses the integrated webview, would that also be corrected by this do you think?).
Comment 4 Wenson Hsieh 2019-01-22 14:57:27 PST
(In reply to Mark W from comment #3)
> Thanks for the quick response! It occurs for me on an iPad Mini running
> 12.1.3 (16D39) as well as in the xCode simulator running 12.1 (16B91). 
> 
> Thanks also for pointer to 234661. If that indeed corrects this issue, when
> would that be available to devices? (I don't know how to download a nightly
> build to a device but if you tell me how I'd be happy to do that and see if
> it corrects). 

Ah, for a second there, I thought the fix had already shipped with an iOS 12 update, but on closer examination this does not appear to be the case.

We'll update you in the future, when there's a beta version of iOS that contains the fix.

> 
> (probably out of your purview but the originating issue actually occurs in
> an ionic app that uses the integrated webview, would that also be corrected
> by this do you think?).

The bug and the fix are relevant to both Safari and embedded WKWebViews, so I would expect it to apply there as well! This is, of course, assuming that the bug observed in the ionic app is the same — i.e., unable to extend text selections in iframe that are not located at the main document origin.
Comment 5 Mark W 2019-01-22 15:03:14 PST
Awesome. Without committing to a specific timeline, would you expect that to be in order days, weeks, or months? I have customers in the field impacted by this and need to decide whether to wait or try to find some kind of workaround. 

My sense was that this was some kind of coordinate system thing so your analysis of the previous bug sounds similar; I'm optimistic this will fix :)

Thanks again for the quick response!
Comment 6 Alexey Proskuryakov 2019-01-26 20:53:54 PST
Can you test with iOS 12.2 beta?
Comment 7 Mark W 2019-01-26 21:13:35 PST
Would love to. How do I install that on a device? (the problem only seems to occur on iPads)
Comment 8 Mark W 2019-01-26 21:33:32 PST
(In reply to Mark W from comment #7)
> Would love to. How do I install that on a device? (the problem only seems to
> occur on iPads)

OK I RTFM'd and beta download in progress. Will report back.
Comment 9 Mark W 2019-01-27 13:52:25 PST
I can confirm the problem is fixed in 12.2 Beta, including both in mobile Safari and in embedded webviews. 

Let me know if I should change the status on this bug / or close it, or whether someone else will do that. 

Any feedback on roughly (days, weeks, months) on when 12.2 might be released would be much appreciated!

Thanks so much!
Comment 10 Wenson Hsieh 2019-01-27 14:23:49 PST
(In reply to Mark W from comment #9)
> I can confirm the problem is fixed in 12.2 Beta, including both in mobile
> Safari and in embedded webviews. 
> 
> Let me know if I should change the status on this bug / or close it, or
> whether someone else will do that. 
> 
> Any feedback on roughly (days, weeks, months) on when 12.2 might be released
> would be much appreciated!
> 
> Thanks so much!

That's great to hear, Mark! I've gone ahead and marked this bug as a duplicate of the other bug (https://bugs.webkit.org/show_bug.cgi?id=188374) which contains the fix.

*** This bug has been marked as a duplicate of bug 188374 ***
Comment 11 Mark W 2019-01-27 22:34:52 PST
Awesome thank you!