RESOLVED FIXED 147782
Add support for history.scrollRestoration
https://bugs.webkit.org/show_bug.cgi?id=147782
Summary Add support for history.scrollRestoration
Majid Valipour
Reported 2015-08-07 07:40:58 PDT
Currently there is no reliable and cross-browser solution for developers to opt out the automatic scroll restoration behavior or control any of its aspects. The automatic restoration works well for document style web sites but it is often not appropriate for single-page web applications where they are re-constructing the page content onpopstate every time and often asynchronously or need to control the visual transition between states. Here is more the problem background and existing workarounds: http://majido.github.io/scroll-restoration-proposal/ We in blink team have proposed a solution to this issue on WHATWG and there is some consensus (with spec editors and Mozilla experts) around a simple API based on a new attribute added to the history object. I would like to know if Webkit has any feedback on this solution and API and help make the consensus more inclusive if possible. Unofficial spec: http://majido.github.io/scroll-restoration-proposal/history-based-api.html Web platform tests: http://majido.github.io/scroll-restoration-proposal/tests/ WhatWG discussion thread: https://lists.w3.org/Archives/Public/public-whatwg-archive/2015Mar/0070.html WICG discourse: http://discourse.wicg.io/t/disabling-automatic-scroll-restoration-on-navigation/1012/2 Also you can find a summary of alternative APIs and solutions that were considered before reaching the current design here: http://discourse.wicg.io/t/disabling-automatic-scroll-restoration-on-navigation/1012/4?u=majidvp
Attachments
Patch (18.13 KB, patch)
2017-01-22 10:52 PST, Simon Fraser (smfr)
no flags
Patch (20.11 KB, patch)
2017-01-22 11:24 PST, Simon Fraser (smfr)
no flags
Archive of layout-test-results from ews102 for mac-elcapitan (783.27 KB, application/zip)
2017-01-22 12:26 PST, Build Bot
no flags
Archive of layout-test-results from ews105 for mac-elcapitan-wk2 (851.30 KB, application/zip)
2017-01-22 12:29 PST, Build Bot
no flags
Archive of layout-test-results from ews114 for mac-elcapitan (1.50 MB, application/zip)
2017-01-22 12:40 PST, Build Bot
no flags
Archive of layout-test-results from ews121 for ios-simulator-wk2 (2.48 MB, application/zip)
2017-01-22 14:42 PST, Build Bot
no flags
Patch (23.32 KB, patch)
2017-01-22 22:05 PST, Simon Fraser (smfr)
no flags
Archive of layout-test-results from ews126 for ios-simulator-wk2 (831.07 KB, application/zip)
2017-01-22 23:23 PST, Build Bot
no flags
Archive of layout-test-results from ews117 for mac-elcapitan (1.47 MB, application/zip)
2017-01-22 23:28 PST, Build Bot
no flags
Patch (27.33 KB, patch)
2017-02-11 22:55 PST, Simon Fraser (smfr)
no flags
Archive of layout-test-results from ews126 for ios-simulator-wk2 (851.60 KB, application/zip)
2017-02-12 00:15 PST, Build Bot
no flags
Archive of layout-test-results from ews112 for mac-elcapitan (1.48 MB, application/zip)
2017-02-12 00:17 PST, Build Bot
no flags
patching test for CORS (3.91 KB, patch)
2017-02-13 14:46 PST, youenn fablet
no flags
Patch (62.21 KB, patch)
2017-02-21 14:52 PST, Simon Fraser (smfr)
no flags
Archive of layout-test-results from ews102 for mac-elcapitan (4.58 MB, application/zip)
2017-02-21 16:13 PST, Build Bot
no flags
Archive of layout-test-results from ews125 for ios-simulator-wk2 (3.66 MB, application/zip)
2017-02-21 16:16 PST, Build Bot
no flags
Patch (61.06 KB, patch)
2017-03-06 12:02 PST, Simon Fraser (smfr)
no flags
Patch (62.59 KB, patch)
2017-03-06 12:47 PST, Simon Fraser (smfr)
no flags
Archive of layout-test-results from ews103 for mac-elcapitan (928.23 KB, application/zip)
2017-03-06 13:58 PST, Build Bot
no flags
Archive of layout-test-results from ews115 for mac-elcapitan (1.53 MB, application/zip)
2017-03-06 14:23 PST, Build Bot
no flags
Patch (63.18 KB, patch)
2017-03-06 22:10 PST, Simon Fraser (smfr)
no flags
Archive of layout-test-results from ews125 for ios-simulator-wk2 (930.20 KB, application/zip)
2017-03-06 23:36 PST, Build Bot
no flags
Patch (71.21 KB, patch)
2017-03-07 14:44 PST, Simon Fraser (smfr)
sam: review+
Ali Shah
Comment 2 2015-08-22 20:03:41 PDT
We also have this problem for some of the javascript served on Google Search. We have a couple work arounds that all seem to rely on making sure everything happens before the popState to avoid a scroll position flash to the user. This mechanism has always been finicky, and it would be awesome to see a cross platform solution to this.
Radar WebKit Bug Importer
Comment 3 2015-09-08 11:58:26 PDT
Rick Byers
Comment 4 2016-01-07 13:32:35 PST
Note this is now part of the HTML5 spec: https://html.spec.whatwg.org/multipage/browsers.html#dom-history-scroll-restoration and is being implemented in Firefox (in addition to shipping in Chromium).
Rick Byers
Comment 5 2016-01-07 13:32:55 PST
*** Bug 51899 has been marked as a duplicate of this bug. ***
Simon Fraser (smfr)
Comment 6 2017-01-22 10:52:12 PST
Simon Fraser (smfr)
Comment 7 2017-01-22 11:24:08 PST
Build Bot
Comment 8 2017-01-22 12:26:50 PST
Comment on attachment 299473 [details] Patch Attachment 299473 [details] did not pass mac-ews (mac): Output: http://webkit-queues.webkit.org/results/2931605 New failing tests: fast/history/history-scroll-restoration.html imported/w3c/web-platform-tests/html/browsers/browsing-the-web/history-traversal/persisted-user-state-restoration/scroll-restoration-basic.html fast/dom/Window/window-appendages-cleared.html media/audio-concurrent-supported.html
Build Bot
Comment 9 2017-01-22 12:26:55 PST
Created attachment 299476 [details] Archive of layout-test-results from ews102 for mac-elcapitan The attached test failures were seen while running run-webkit-tests on the mac-ews. Bot: ews102 Port: mac-elcapitan Platform: Mac OS X 10.11.6
Build Bot
Comment 10 2017-01-22 12:29:52 PST
Comment on attachment 299473 [details] Patch Attachment 299473 [details] did not pass mac-wk2-ews (mac-wk2): Output: http://webkit-queues.webkit.org/results/2931616 New failing tests: imported/w3c/web-platform-tests/html/browsers/browsing-the-web/history-traversal/persisted-user-state-restoration/scroll-restoration-basic.html fast/dom/Window/window-appendages-cleared.html imported/w3c/web-platform-tests/html/browsers/browsing-the-web/history-traversal/persisted-user-state-restoration/scroll-restoration-fragment-scrolling-cross-origin.html
Build Bot
Comment 11 2017-01-22 12:29:57 PST
Created attachment 299477 [details] Archive of layout-test-results from ews105 for mac-elcapitan-wk2 The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews. Bot: ews105 Port: mac-elcapitan-wk2 Platform: Mac OS X 10.11.6
Build Bot
Comment 12 2017-01-22 12:40:34 PST
Comment on attachment 299473 [details] Patch Attachment 299473 [details] did not pass mac-debug-ews (mac): Output: http://webkit-queues.webkit.org/results/2931632 New failing tests: fast/history/history-scroll-restoration.html imported/w3c/web-platform-tests/html/browsers/browsing-the-web/history-traversal/persisted-user-state-restoration/scroll-restoration-basic.html fast/dom/Window/window-appendages-cleared.html imported/w3c/web-platform-tests/html/browsers/browsing-the-web/history-traversal/persisted-user-state-restoration/scroll-restoration-fragment-scrolling-cross-origin.html
Build Bot
Comment 13 2017-01-22 12:40:39 PST
Created attachment 299478 [details] Archive of layout-test-results from ews114 for mac-elcapitan The attached test failures were seen while running run-webkit-tests on the mac-debug-ews. Bot: ews114 Port: mac-elcapitan Platform: Mac OS X 10.11.6
Build Bot
Comment 14 2017-01-22 14:42:44 PST
Comment on attachment 299473 [details] Patch Attachment 299473 [details] did not pass ios-sim-ews (ios-simulator-wk2): Output: http://webkit-queues.webkit.org/results/2932014 New failing tests: fast/history/history-scroll-restoration.html imported/w3c/web-platform-tests/html/browsers/browsing-the-web/history-traversal/persisted-user-state-restoration/scroll-restoration-basic.html fast/dom/Window/window-appendages-cleared.html
Build Bot
Comment 15 2017-01-22 14:42:51 PST
Created attachment 299485 [details] Archive of layout-test-results from ews121 for ios-simulator-wk2 The attached test failures were seen while running run-webkit-tests on the ios-sim-ews. Bot: ews121 Port: ios-simulator-wk2 Platform: Mac OS X 10.11.6
Simon Fraser (smfr)
Comment 16 2017-01-22 22:05:51 PST
Build Bot
Comment 17 2017-01-22 23:23:47 PST
Comment on attachment 299499 [details] Patch Attachment 299499 [details] did not pass ios-sim-ews (ios-simulator-wk2): Output: http://webkit-queues.webkit.org/results/2933700 New failing tests: fast/history/history-scroll-restoration.html
Build Bot
Comment 18 2017-01-22 23:23:54 PST
Created attachment 299505 [details] Archive of layout-test-results from ews126 for ios-simulator-wk2 The attached test failures were seen while running run-webkit-tests on the ios-sim-ews. Bot: ews126 Port: ios-simulator-wk2 Platform: Mac OS X 10.11.6
Build Bot
Comment 19 2017-01-22 23:28:34 PST
Comment on attachment 299499 [details] Patch Attachment 299499 [details] did not pass mac-debug-ews (mac): Output: http://webkit-queues.webkit.org/results/2933709 New failing tests: imported/w3c/web-platform-tests/html/browsers/browsing-the-web/history-traversal/persisted-user-state-restoration/scroll-restoration-fragment-scrolling-cross-origin.html
Build Bot
Comment 20 2017-01-22 23:28:39 PST
Created attachment 299506 [details] Archive of layout-test-results from ews117 for mac-elcapitan The attached test failures were seen while running run-webkit-tests on the mac-debug-ews. Bot: ews117 Port: mac-elcapitan Platform: Mac OS X 10.11.6
Sam Weinig
Comment 21 2017-01-23 12:57:47 PST
Comment on attachment 299499 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=299499&action=review > Source/WebCore/history/HistoryItem.h:221 > + float m_pageScaleFactor { 0 }; // 0 indicates "unset". Should this be changed to an Optional<float> to make it more clear? > Source/WebCore/page/History.cpp:77 > +ExceptionOr<History::ScrollRestoration> History::scrollRestoration() const > +{ > + auto* historyItem = m_frame->loader().history().currentItem(); > + if (!historyItem) > + return ScrollRestoration::Auto; > + > + return historyItem->shouldRestoreScrollPosition() ? ScrollRestoration::Auto : ScrollRestoration::Manual; > +} > + > +ExceptionOr<void> History::setScrollRestoration(ScrollRestoration scrollRestoration) > +{ > + auto* historyItem = m_frame->loader().history().currentItem(); > + if (historyItem) > + historyItem->setShouldRestoreScrollPosition(scrollRestoration == ScrollRestoration::Auto); > + > + return { }; > +} Neither of these seem to ever throw an exception. Why ExceptionOr?
Simon Fraser (smfr)
Comment 22 2017-01-23 13:33:04 PST
(In reply to comment #21) > Comment on attachment 299499 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=299499&action=review > > > Source/WebCore/history/HistoryItem.h:221 > > + float m_pageScaleFactor { 0 }; // 0 indicates "unset". > > Should this be changed to an Optional<float> to make it more clear? It should, yes (existing code). > > Source/WebCore/page/History.cpp:77 > > +ExceptionOr<History::ScrollRestoration> History::scrollRestoration() const > > +{ > > + auto* historyItem = m_frame->loader().history().currentItem(); > > + if (!historyItem) > > + return ScrollRestoration::Auto; > > + > > + return historyItem->shouldRestoreScrollPosition() ? ScrollRestoration::Auto : ScrollRestoration::Manual; > > +} > > + > > +ExceptionOr<void> History::setScrollRestoration(ScrollRestoration scrollRestoration) > > +{ > > + auto* historyItem = m_frame->loader().history().currentItem(); > > + if (historyItem) > > + historyItem->setShouldRestoreScrollPosition(scrollRestoration == ScrollRestoration::Auto); > > + > > + return { }; > > +} > > Neither of these seem to ever throw an exception. Why ExceptionOr? The spec says 'If this History object is associated with a Document that is not fully active, both getting and setting must instead throw a "SecurityError" DOMException." but I wasn't sure if we reflect that state.
Sam Weinig
Comment 23 2017-01-24 08:32:55 PST
(In reply to comment #22) > (In reply to comment #21) > > Comment on attachment 299499 [details] > > Patch > > > > View in context: > > https://bugs.webkit.org/attachment.cgi?id=299499&action=review > > > > > Source/WebCore/history/HistoryItem.h:221 > > > + float m_pageScaleFactor { 0 }; // 0 indicates "unset". > > > > Should this be changed to an Optional<float> to make it more clear? > > It should, yes (existing code). > > > > Source/WebCore/page/History.cpp:77 > > > +ExceptionOr<History::ScrollRestoration> History::scrollRestoration() const > > > +{ > > > + auto* historyItem = m_frame->loader().history().currentItem(); > > > + if (!historyItem) > > > + return ScrollRestoration::Auto; > > > + > > > + return historyItem->shouldRestoreScrollPosition() ? ScrollRestoration::Auto : ScrollRestoration::Manual; > > > +} > > > + > > > +ExceptionOr<void> History::setScrollRestoration(ScrollRestoration scrollRestoration) > > > +{ > > > + auto* historyItem = m_frame->loader().history().currentItem(); > > > + if (historyItem) > > > + historyItem->setShouldRestoreScrollPosition(scrollRestoration == ScrollRestoration::Auto); > > > + > > > + return { }; > > > +} > > > > Neither of these seem to ever throw an exception. Why ExceptionOr? > > The spec says 'If this History object is associated with a Document that is > not fully active, both getting and setting must instead throw a > "SecurityError" DOMException." but I wasn't sure if we reflect that state. We reflect that as a Document without a Frame pointer.
Majid Valipour
Comment 24 2017-01-25 07:58:22 PST
I am excited to see this happen \o/. Also great to see most of web-platform-tests passing which hopefully should mean good interop behavior. The only exception seems to be |scroll-restoration-fragment-scrolling-same-origin.html|. It may not be relevant to webkit but in Blink I had to change the FrameLoader::processFragment logic to respect the manual scroll restoration to make that work I think. [1] [1] https://codesearch.chromium.org/chromium/src/third_party/WebKit/Source/core/loader/FrameLoader.cpp?dr=Ss&q=scrollToFragment&sq=package:chromium&l=1549
Simon Fraser (smfr)
Comment 25 2017-01-25 08:07:44 PST
Ah, thanks for the hint!
Simon Fraser (smfr)
Comment 26 2017-02-11 22:55:34 PST
Build Bot
Comment 27 2017-02-12 00:15:42 PST
Comment on attachment 301291 [details] Patch Attachment 301291 [details] did not pass ios-sim-ews (ios-simulator-wk2): Output: http://webkit-queues.webkit.org/results/3071866 New failing tests: fast/history/history-scroll-restoration.html
Build Bot
Comment 28 2017-02-12 00:15:48 PST
Created attachment 301294 [details] Archive of layout-test-results from ews126 for ios-simulator-wk2 The attached test failures were seen while running run-webkit-tests on the ios-sim-ews. Bot: ews126 Port: ios-simulator-wk2 Platform: Mac OS X 10.11.6
Build Bot
Comment 29 2017-02-12 00:17:20 PST
Comment on attachment 301291 [details] Patch Attachment 301291 [details] did not pass mac-debug-ews (mac): Output: http://webkit-queues.webkit.org/results/3071871 New failing tests: imported/w3c/web-platform-tests/html/browsers/browsing-the-web/history-traversal/persisted-user-state-restoration/scroll-restoration-fragment-scrolling-cross-origin.html
Build Bot
Comment 30 2017-02-12 00:17:25 PST
Created attachment 301295 [details] Archive of layout-test-results from ews112 for mac-elcapitan The attached test failures were seen while running run-webkit-tests on the mac-debug-ews. Bot: ews112 Port: mac-elcapitan Platform: Mac OS X 10.11.6
Sam Weinig
Comment 31 2017-02-12 10:32:21 PST
Comment on attachment 301291 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=301291&action=review > Source/WebCore/page/History.cpp:77 > +ExceptionOr<History::ScrollRestoration> History::scrollRestoration() const > +{ > + auto* historyItem = m_frame->loader().history().currentItem(); > + if (!historyItem) > + return ScrollRestoration::Auto; > + > + return historyItem->shouldRestoreScrollPosition() ? ScrollRestoration::Auto : ScrollRestoration::Manual; > +} > + > +ExceptionOr<void> History::setScrollRestoration(ScrollRestoration scrollRestoration) > +{ > + auto* historyItem = m_frame->loader().history().currentItem(); > + if (historyItem) > + historyItem->setShouldRestoreScrollPosition(scrollRestoration == ScrollRestoration::Auto); > + > + return { }; > +} Unless you are going to start throwing exceptions here, I would remove the ExceptionOr return types. When/if an exception is needed, they can be added back.
Simon Fraser (smfr)
Comment 32 2017-02-13 11:02:59 PST
Testing is blocked by bug 127676.
Simon Fraser (smfr)
Comment 33 2017-02-13 13:40:24 PST
Still need to fix iOS WK2.
youenn fablet
Comment 34 2017-02-13 14:46:51 PST
Created attachment 301392 [details] patching test for CORS
Simon Fraser (smfr)
Comment 35 2017-02-21 14:52:30 PST
Build Bot
Comment 36 2017-02-21 16:13:49 PST
Comment on attachment 302314 [details] Patch Attachment 302314 [details] did not pass mac-ews (mac): Output: http://webkit-queues.webkit.org/results/3168633 New failing tests: fast/history/history-scroll-restoration.html
Build Bot
Comment 37 2017-02-21 16:13:55 PST
Created attachment 302330 [details] Archive of layout-test-results from ews102 for mac-elcapitan The attached test failures were seen while running run-webkit-tests on the mac-ews. Bot: ews102 Port: mac-elcapitan Platform: Mac OS X 10.11.6
Build Bot
Comment 38 2017-02-21 16:16:36 PST
Comment on attachment 302314 [details] Patch Attachment 302314 [details] did not pass ios-sim-ews (ios-simulator-wk2): Output: http://webkit-queues.webkit.org/results/3168558 New failing tests: imported/w3c/web-platform-tests/html/browsers/browsing-the-web/history-traversal/persisted-user-state-restoration/scroll-restoration-navigation-samedoc.html
Build Bot
Comment 39 2017-02-21 16:16:41 PST
Created attachment 302331 [details] Archive of layout-test-results from ews125 for ios-simulator-wk2 The attached test failures were seen while running run-webkit-tests on the ios-sim-ews. Bot: ews125 Port: ios-simulator-wk2 Platform: Mac OS X 10.11.6
Sam Weinig
Comment 40 2017-02-21 16:27:45 PST
Comment on attachment 302314 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=302314&action=review > Source/WebCore/page/DOMWindow.cpp:1335 > + WTFLogAlways("DOMWindow::scrollY returning early %d", scrollY); Probably want to remove this. > Source/WebCore/page/DOMWindow.cpp:1342 > + WTFLogAlways("DOMWindow::scrollY returning %d", result); Ditto. > Source/WebCore/page/History.cpp:62 > +ExceptionOr<History::ScrollRestoration> History::scrollRestoration() const Do you disagree with the feedback I have given in previous reviews about removing the ExceptionOr? > Source/WebKit2/Platform/Logging.cpp:61 > + WebKit2LogVisibleRects.state = WTFLogChannelOn; > + WebKit2LogViewState.state = WTFLogChannelOn; > + WebKit2LogViewGestures.state = WTFLogChannelOn; I don't think you meant to keep this in.
Simon Fraser (smfr)
Comment 41 2017-02-21 16:30:49 PST
(In reply to comment #40) > Do you disagree with the feedback I have given in previous reviews about > removing the ExceptionOr? No, this patch was meant to be just for EWS :)
Sam Weinig
Comment 42 2017-02-22 12:02:07 PST
(In reply to comment #41) > (In reply to comment #40) > > > Do you disagree with the feedback I have given in previous reviews about > > removing the ExceptionOr? > > No, this patch was meant to be just for EWS :) Ah. I usually don't set the review=? flag in those cases. If you are using webkit-patch post, you can use the --no-review flag (but note, you will have to click to start the EWS).
Simon Fraser (smfr)
Comment 43 2017-03-06 12:02:54 PST
Simon Fraser (smfr)
Comment 44 2017-03-06 12:47:16 PST
WebKit Commit Bot
Comment 45 2017-03-06 12:48:50 PST
Thanks for the patch. If this patch contains new public API please make sure it follows the guidelines for new WebKit2 GTK+ API. See http://trac.webkit.org/wiki/WebKitGTK/AddingNewWebKit2API
Build Bot
Comment 46 2017-03-06 13:58:25 PST
Comment on attachment 303541 [details] Patch Attachment 303541 [details] did not pass mac-ews (mac): Output: http://webkit-queues.webkit.org/results/3254192 New failing tests: fast/history/history-scroll-restoration.html media/modern-media-controls/tracks-support/tracks-support-click-track-in-panel.html
Build Bot
Comment 47 2017-03-06 13:58:32 PST
Created attachment 303551 [details] Archive of layout-test-results from ews103 for mac-elcapitan The attached test failures were seen while running run-webkit-tests on the mac-ews. Bot: ews103 Port: mac-elcapitan Platform: Mac OS X 10.11.6
Build Bot
Comment 48 2017-03-06 14:23:06 PST
Comment on attachment 303541 [details] Patch Attachment 303541 [details] did not pass mac-debug-ews (mac): Output: http://webkit-queues.webkit.org/results/3254224 New failing tests: fast/history/history-scroll-restoration.html imported/w3c/web-platform-tests/html/browsers/browsing-the-web/history-traversal/persisted-user-state-restoration/scroll-restoration-fragment-scrolling-cross-origin.html
Build Bot
Comment 49 2017-03-06 14:23:12 PST
Created attachment 303557 [details] Archive of layout-test-results from ews115 for mac-elcapitan The attached test failures were seen while running run-webkit-tests on the mac-debug-ews. Bot: ews115 Port: mac-elcapitan Platform: Mac OS X 10.11.6
Simon Fraser (smfr)
Comment 50 2017-03-06 22:10:35 PST
Build Bot
Comment 51 2017-03-06 23:36:31 PST
Comment on attachment 303623 [details] Patch Attachment 303623 [details] did not pass ios-sim-ews (ios-simulator-wk2): Output: http://webkit-queues.webkit.org/results/3257127 New failing tests: fast/history/history-scroll-restoration.html
Build Bot
Comment 52 2017-03-06 23:36:40 PST
Created attachment 303630 [details] Archive of layout-test-results from ews125 for ios-simulator-wk2 The attached test failures were seen while running run-webkit-tests on the ios-sim-ews. Bot: ews125 Port: ios-simulator-wk2 Platform: Mac OS X 10.11.6
Simon Fraser (smfr)
Comment 53 2017-03-07 14:44:39 PST
Sam Weinig
Comment 54 2017-03-08 11:11:43 PST
Comment on attachment 303726 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=303726&action=review > Source/WebCore/ChangeLog:9 > + Add Mac support for history.scrollRestoration, per spec: Is this really just Mac? > Source/WebCore/loader/FrameLoader.cpp:2871 > +static bool itemAllowsScrollRestoration(HistoryItem *historyItem) * on the wrong side.
Simon Fraser (smfr)
Comment 55 2017-03-08 12:01:44 PST
Note You need to log in before you can comment on or make changes to this bug.