Skip to content

Commit fe9ed18

Browse files
Fragment navigation should be cancelled if there is ongoing navigation
Fragment navigation is synchronous, while navigation is asynchronous. It can happen that fragment navigation starts when navigation is in the policy or provisional step of loading. In that case, we should cancel the requested fragment navigation and make the navigation finish.
1 parent 09f6529 commit fe9ed18

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Source/WebCore/loader/FrameLoader.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,6 +1482,23 @@ void FrameLoader::loadURL(FrameLoadRequest&& frameLoadRequest, const String& ref
14821482
if (m_inStopAllLoaders || m_inClearProvisionalLoadForPolicyCheck)
14831483
return;
14841484

1485+
static bool keepNavigationOnFragmentLoad = false;
1486+
static bool keepNavigationOnFragmentLoadInitialized = false;
1487+
1488+
if (!keepNavigationOnFragmentLoadInitialized) {
1489+
keepNavigationOnFragmentLoad = !!getenv("WPE_KEEP_NAVIGATION_ON_FRAGMENT_LOAD");
1490+
keepNavigationOnFragmentLoadInitialized = true;
1491+
}
1492+
1493+
// If we have a policy or provisional request for a different document, a fragment scroll should be cancelled.
1494+
if (keepNavigationOnFragmentLoad && (m_policyDocumentLoader && !equalIgnoringFragmentIdentifier(m_policyDocumentLoader->request().url(), frameLoadRequest.resourceRequest().url()) ||
1495+
m_provisionalDocumentLoader && !equalIgnoringFragmentIdentifier(m_provisionalDocumentLoader->request().url(), frameLoadRequest.resourceRequest().url()))) {
1496+
const auto fragmentNavigationURL = frameLoadRequest.resourceRequest().url();
1497+
const auto navigationURL = m_policyDocumentLoader ? m_policyDocumentLoader->request().url(): m_provisionalDocumentLoader->request().url();
1498+
FRAMELOADER_RELEASE_LOG(ResourceLoading, "loadURL: fragment navigation: %s is cancelled because of ongoing navigation change to url: %s", fragmentNavigationURL.string().utf8().data(), navigationURL.string().utf8().data());
1499+
return;
1500+
}
1501+
14851502
Ref frame = m_frame.get();
14861503

14871504
// Anchor target is ignored when the download attribute is set since it will download the hyperlink rather than follow it.

0 commit comments

Comments
 (0)