Bug 187523

Summary: WKWebView.backForwardList.currentItem is incorrect after canceled back/forward navigation
Product: WebKit Reporter: Danyao Wang <danyao>
Component: Page LoadingAssignee: Nobody <webkit-unassigned>
Status: RESOLVED WORKSFORME    
Severity: Normal CC: ajuma, beidson, bfulgham, ggaren, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: Safari 11   
Hardware: iPhone / iPad   
OS: iOS 11   
Attachments:
Description Flags
Minimal example to reproduce the bug none

Description Danyao Wang 2018-07-10 09:10:33 PDT
Created attachment 344701 [details]
Minimal example to reproduce the bug

For back/forward navigation, WebKit's URL and history state are updated before the |webView:decidePolicyForNavigationAction| callback. If the embedder returns WKNavigationActionPolicyCancel, only the URL change is undone, but not the WKWebView.backForwardList.currentItem change.

Steps to reproduce:
1. Navigate to a URL in WKWebView, e.g. https://wikipedia.org
2. Navigate to a second URL: e.g. https://apple.com
3. Go back
4. In |webView:decidePolicyForNavigationAction|, return WKNavigationActionPolicyCancel
5. Observe WKWebView.URL and WKWebView.backForwardList.currentItem.URL in URL KVO

Expected result: both WKWebView.URL and WKWebView.backForwardList.currentItem.URL are https://apple.com
Observed result: WKWebView.URL is https://apple.com. WKWebView.backForwardList.currentItem.URL is https://wikipedia.org.

The attached WKWebView project runs through the above states and logs the URLs to debug log.

The history state is corrected after starting a new navigation. So this may be a discrepancy between the WebProcess and UIProcess.
Comment 1 Ali Juma 2018-07-10 09:46:32 PDT
In reply to Danyao Wang from comment #0)
> So this may be a discrepancy between the WebProcess and UIProcess.

FrameLoader::continueLoadAfterNavigationPolicy has logic (in the !canContinue case) to reset back/forward state. Perhaps something is going wrong with sending that change to the UIProcess.
Comment 2 Radar WebKit Bug Importer 2018-07-10 11:19:30 PDT
<rdar://problem/42032341>
Comment 3 Brent Fulgham 2022-02-13 22:08:02 PST
This bug doesn't seem actionable.