Bug 226323 - REGRESSION (iOS 14.5): Can't go back and render previous page properly after "location.href"
Summary: REGRESSION (iOS 14.5): Can't go back and render previous page properly after ...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: History (show other bugs)
Version: Safari 14
Hardware: Unspecified Unspecified
: P2 Major
Assignee: Alex Christensen
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-05-27 03:18 PDT by Okamoto Takuya
Modified: 2021-06-01 12:02 PDT (History)
6 users (show)

See Also:


Attachments
reproducing steps (4.85 MB, video/quicktime)
2021-05-27 03:18 PDT, Okamoto Takuya
no flags Details
Patch (5.97 KB, patch)
2021-05-28 14:43 PDT, Alex Christensen
no flags Details | Formatted Diff | Diff
Patch (7.90 KB, patch)
2021-06-01 09:06 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Okamoto Takuya 2021-05-27 03:18:19 PDT
Created attachment 429863 [details]
reproducing steps

# Reproducible environment

- Safari and Webview on iOS 14.5
- Safari 14.1 on Mac 10.15

# Reproducing steps

Please see the attached video, too.

1. Access to SiteA located in "https://siteA.com/"
2. In SiteA, run JS code like this immediately:
```
<script type="text/javascript">
  location.href="https://siteB.com/" // SiteB
</script>
```

This page of SiteA won’t be recorded in the browser’s history since this "location.href" is called without user interactions.
https://html.spec.whatwg.org/multipage/history.html#location-object-setter-navigate

3. After arriving at SiteB, click browser's history back button to go back to SiteA
4. I expected to see the page before SiteA, but the issue below occurs

# Issue

Even though the browser's URL bar shows SiteA's URL, but I can't see SiteA contents because:
- The browser shows a blank screen instead (iOS)
- Or, the browser keeps and shows previous page's contents of SiteA (Mac)

## Note

- When SiteA and SiteB are on a same domain, this issue isn't reproduced.
- Sometimes the issue won't occur anymore after accessing SiteA multiple times. In that case, once clear the browser cache, you can reproduce it again.

# Reproducible page

page: https://redirect-issue.web.app
code: https://github.com/cola119/safari-redirect-issue
Comment 1 Alexey Proskuryakov 2021-05-27 18:17:24 PDT
Thank you for the report! 

> - Safari and Webview on iOS 14.5
> - Safari 14.1 on Mac 10.15


Could you please confirm if these are the first versions where this happens, and earlier ones worked as expected?
Comment 2 Okamoto Takuya 2021-05-27 19:22:52 PDT
(In reply to Alexey Proskuryakov from comment #1)

> Could you please confirm if these are the first versions where this happens,
> and earlier ones worked as expected?

Thank you for your reply.

Regarding iOS, we confirmed that we couldn't reproduce the issue in iOS 14.4 and earlier.
Regarding Mac, we don't have many environments, so we could check only on Safari 14.1 in Mac 10.15.
Comment 3 Alexey Proskuryakov 2021-05-28 10:33:53 PDT
Thank you, this is what we need to know about regression story.

I should have asked right away about customer impact. Does this affect specific existing websites and/or apps? How bad is the impact?
Comment 4 Radar WebKit Bug Importer 2021-05-28 10:34:09 PDT
<rdar://problem/78623536>
Comment 5 Alex Christensen 2021-05-28 11:58:26 PDT
This worked before r269170 which caused the web process to crash when pushing the back button.  When that crash was fixed in r270789 it no longer showed the previous page when pushing the back button.
Comment 6 Alex Christensen 2021-05-28 14:43:07 PDT
Created attachment 430056 [details]
Patch
Comment 7 Okamoto Takuya 2021-05-30 18:52:17 PDT
(In reply to Alexey Proskuryakov from comment #3)
Thank you for your confirmation!

> I should have asked right away about customer impact. Does this affect specific existing websites and/or apps? How bad is the impact?

We offer the platform to our customers and this issue affects to one feature of it.
We have a redirector which was made with "location.href" and can pass path/query/fragment from original access.

It means:

Click the link to SiteA (a redirector) with path/query/fragment
-> Site A redirect to Site B (different domain) with the passed path/query/fragment
-> Land at Site B with the passed path/query/fragment

In the way of redirecting with HTTP status code 301/302, we can't pass fragment to the final destination since server side can't recognize fragment in URL. Therefore we use "location.href" since JS can recognize it.
Comment 8 Chris Dumez 2021-06-01 09:06:42 PDT
Created attachment 430266 [details]
Patch
Comment 9 EWS 2021-06-01 12:02:45 PDT
Committed r278318 (238354@main): <https://commits.webkit.org/238354@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 430266 [details].