Skip to content

Back button not enabled on sciencedirect.com to support Safari's "Close and return to ..." feature for new windows#65548

Merged
webkit-commit-queue merged 1 commit into
WebKit:mainfrom
beidson:eng/Back-button-not-enabled-on-sciencedirect-com-to-support-Safari-s-Close-and-return-to-feature-for-new-windows
May 24, 2026
Merged

Back button not enabled on sciencedirect.com to support Safari's "Close and return to ..." feature for new windows#65548
webkit-commit-queue merged 1 commit into
WebKit:mainfrom
beidson:eng/Back-button-not-enabled-on-sciencedirect-com-to-support-Safari-s-Close-and-return-to-feature-for-new-windows

Conversation

@beidson
Copy link
Copy Markdown
Contributor

@beidson beidson commented May 24, 2026

523b810

Back button not enabled on sciencedirect.com to support Safari's "Close and return to ..." feature for new windows
rdar://177792841
https://bugs.webkit.org/show_bug.cgi?id=315440

Reviewed by Richard Robinson.

Before this change, we add new history items to the back/forward list in one step, then flag them as
"created by JS without user interaction" in a separate step.

The first step performs a delegate callback to notify the app that the bf-list changed.
The app then runs some code based on the bf-list change.

Then the second step updates the items flag, which can change the presentation of the bf-list,
notably by making it shorter by hiding some items.

But the app saw the "incorrect" list already, and already ran code, which might've been destructive.

This patch sets the flag upon initial creation of the history item which removes this interstitial gap.

This allows the app to make its decisions based on an always accurate presentation of the bf-list.

Test: Tools/TestWebKitAPI/Tests/WebKit/WKWebView/WKBackForwardListTests.mm

* Source/WebCore/loader/FrameLoader.cpp:
(WebCore::FrameLoader::loadInSameDocument):
* Source/WebCore/loader/HistoryController.cpp:
(WebCore::HistoryController::updateBackForwardListForFragmentScroll):
(WebCore::HistoryController::updateForStandardLoad):
(WebCore::HistoryController::updateBackForwardListClippedAtTarget):
(WebCore::HistoryController::updateBackForwardListForReplaceState):
* Source/WebCore/loader/HistoryController.h:
* Tools/TestWebKitAPI/Tests/WebKit/WKWebView/WKBackForwardListTests.mm:
(-[ItemAddedRecordingDelegate webView:didFinishNavigation:]):
(-[ItemAddedRecordingDelegate _webView:navigation:didSameDocumentNavigation:]):
(-[ItemAddedRecordingDelegate _webView:backForwardListItemAdded:removed:]):
(TEST(WKBackForwardList, ItemAddedDelegateObservesUserGestureFlagAtCallbackTime)):

Canonical link: https://commits.webkit.org/313814@main

6b7554a

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows Apple Internal
✅ 🧪 style ✅ 🛠 ios ❌ 🛠 mac ✅ 🛠 wpe ✅ 🛠 win ✅ 🛠 ios-apple
✅ 🧪 bindings loading 🛠 ios-sim ✅ 🛠 mac-AS-debug 🧪 wpe-wk2 ❌ 🧪 win-tests ✅ 🛠 mac-apple
✅ 🧪 webkitperl ✅ 🧪 ios-wk2 ❌ 🧪 api-mac ✅ 🧪 api-wpe ✅ 🛠 vision-apple
✅ 🧪 ios-wk2-wpt 🧪 api-mac-debug ✅ 🛠 gtk3-libwebrtc
✅ 🧪 api-ios ❌ 🧪 mac-wk1 ✅ 🛠 gtk
✅ 🛠 ios-safer-cpp ❌ 🧪 mac-wk2 ✅ 🧪 gtk-wk2
✅ 🛠 vision loading-orange 🧪 mac-AS-debug-wk2 ✅ 🧪 api-gtk
✅ 🛠 🧪 merge ✅ 🛠 vision-sim ❌ 🧪 mac-wk2-stress ✅ 🛠 playstation
✅ 🧪 vision-wk2 ❌ 🧪 mac-intel-wk2
✅ 🛠 tv ✅ 🛠 mac-safer-cpp
✅ 🛠 tv-sim ❌ 🧪 mac-site-isolation
✅ 🛠 watch
✅ 🛠 watch-sim

@beidson beidson requested review from cdumez and rr-codes as code owners May 24, 2026 04:04
@beidson beidson self-assigned this May 24, 2026

@end

TEST(WKBackForwardList, ItemAddedDelegateObservesUserGestureFlagAtCallbackTime)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional: consider writing this or future tests using Swift Testing, it's much more ergonomic and nicer to use!

Comment thread Source/WebCore/loader/FrameLoader.cpp
Comment thread Tools/TestWebKitAPI/Tests/WebKit/WKWebView/WKBackForwardListTests.mm Outdated
@beidson beidson force-pushed the eng/Back-button-not-enabled-on-sciencedirect-com-to-support-Safari-s-Close-and-return-to-feature-for-new-windows branch from edd5ebb to 6b7554a Compare May 24, 2026 16:20
@beidson
Copy link
Copy Markdown
Contributor Author

beidson commented May 24, 2026

The last EWS run had an apparently-new API test failure on iOS:
TestWebKitAPI.CopyHTML.SanitizationPreservesCharacterSetInSelectedText

The odds that this patch caused that test to fail seem extremely low to me. And also to Claude.
But since I'm addressing some minor review feedback, I'll wait for api-ios to complete again.

@beidson
Copy link
Copy Markdown
Contributor Author

beidson commented May 24, 2026

The last EWS run had an apparently-new API test failure on iOS: TestWebKitAPI.CopyHTML.SanitizationPreservesCharacterSetInSelectedText

The odds that this patch caused that test to fail seem extremely low to me. And also to Claude. But since I'm addressing some minor review feedback, I'll wait for api-ios to complete again.

Actually, I probably won't even wait... That test does a single synchronous HTML load then never navigates again or introspects the back/forward list. It doesn't plug into the delegate on bflist changes, or do anything else relevant.

@beidson beidson added the merge-queue Applied to send a pull request to merge-queue label May 24, 2026
…se and return to ..." feature for new windows

rdar://177792841
https://bugs.webkit.org/show_bug.cgi?id=315440

Reviewed by Richard Robinson.

Before this change, we add new history items to the back/forward list in one step, then flag them as
"created by JS without user interaction" in a separate step.

The first step performs a delegate callback to notify the app that the bf-list changed.
The app then runs some code based on the bf-list change.

Then the second step updates the items flag, which can change the presentation of the bf-list,
notably by making it shorter by hiding some items.

But the app saw the "incorrect" list already, and already ran code, which might've been destructive.

This patch sets the flag upon initial creation of the history item which removes this interstitial gap.

This allows the app to make its decisions based on an always accurate presentation of the bf-list.

Test: Tools/TestWebKitAPI/Tests/WebKit/WKWebView/WKBackForwardListTests.mm

* Source/WebCore/loader/FrameLoader.cpp:
(WebCore::FrameLoader::loadInSameDocument):
* Source/WebCore/loader/HistoryController.cpp:
(WebCore::HistoryController::updateBackForwardListForFragmentScroll):
(WebCore::HistoryController::updateForStandardLoad):
(WebCore::HistoryController::updateBackForwardListClippedAtTarget):
(WebCore::HistoryController::updateBackForwardListForReplaceState):
* Source/WebCore/loader/HistoryController.h:
* Tools/TestWebKitAPI/Tests/WebKit/WKWebView/WKBackForwardListTests.mm:
(-[ItemAddedRecordingDelegate webView:didFinishNavigation:]):
(-[ItemAddedRecordingDelegate _webView:navigation:didSameDocumentNavigation:]):
(-[ItemAddedRecordingDelegate _webView:backForwardListItemAdded:removed:]):
(TEST(WKBackForwardList, ItemAddedDelegateObservesUserGestureFlagAtCallbackTime)):

Canonical link: https://commits.webkit.org/313814@main
@webkit-commit-queue webkit-commit-queue force-pushed the eng/Back-button-not-enabled-on-sciencedirect-com-to-support-Safari-s-Close-and-return-to-feature-for-new-windows branch from 6b7554a to 523b810 Compare May 24, 2026 17:16
@webkit-commit-queue
Copy link
Copy Markdown
Collaborator

Committed 313814@main (523b810): https://commits.webkit.org/313814@main

Reviewed commits have been landed. Closing PR #65548 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit 523b810 into WebKit:main May 24, 2026
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label May 24, 2026
@RupinMittal
Copy link
Copy Markdown
Contributor

Fixing the build in #65591.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants