@@ -1482,23 +1482,6 @@ 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-
15021485 Ref frame = m_frame.get ();
15031486
15041487 // Anchor target is ignored when the download attribute is set since it will download the hyperlink rather than follow it.
@@ -1577,15 +1560,39 @@ void FrameLoader::loadURL(FrameLoadRequest&& frameLoadRequest, const String& ref
15771560
15781561 if (!dispatchNavigateEvent (newURL, newLoadType, action, frameLoadRequest.navigationHistoryBehavior (), true ))
15791562 return ;
1563+ static bool keepNavigationOnFragmentLoad = false ;
1564+ static bool keepNavigationOnFragmentLoadInitialized = false ;
1565+
1566+ if (!keepNavigationOnFragmentLoadInitialized) {
1567+ keepNavigationOnFragmentLoad = !!getenv (" WPE_KEEP_NAVIGATION_ON_FRAGMENT_LOAD" );
1568+ keepNavigationOnFragmentLoadInitialized = true ;
1569+ }
15801570
15811571 oldDocumentLoader->setTriggeringAction (WTFMove (action));
15821572 oldDocumentLoader->setLastCheckedRequest (ResourceRequest ());
1583- policyChecker ().stopCheck ();
1573+ auto loadType = policyChecker ().loadType ();
1574+ bool resetLoadTypeAfterFragmentNavigation = false ;
1575+ if (keepNavigationOnFragmentLoad && (m_policyDocumentLoader && !equalIgnoringFragmentIdentifier (m_policyDocumentLoader->request ().url (), frameLoadRequest.resourceRequest ().url ()) ||
1576+ m_provisionalDocumentLoader && !equalIgnoringFragmentIdentifier (m_provisionalDocumentLoader->request ().url (), frameLoadRequest.resourceRequest ().url ()))) {
1577+ resetLoadTypeAfterFragmentNavigation = true ;
1578+
1579+ const auto fragmentNavigationURL = frameLoadRequest.resourceRequest ().url ();
1580+ const auto navigationURL = m_policyDocumentLoader ? m_policyDocumentLoader->request ().url (): m_provisionalDocumentLoader->request ().url ();
1581+ FRAMELOADER_RELEASE_LOG (ResourceLoading, " loadURL: navigation to: %s will be continued after fragment navigation to url: %s" ,
1582+ navigationURL.string ().utf8 ().data (), fragmentNavigationURL.string ().utf8 ().data ());
1583+ } else {
1584+ policyChecker ().stopCheck ();
1585+ }
1586+
15841587 policyChecker ().setLoadType (newLoadType);
15851588 RELEASE_ASSERT (!isBackForwardLoadType (newLoadType) || frame->history ().provisionalItem ());
15861589 policyChecker ().checkNavigationPolicy (WTFMove (request), ResourceResponse { } /* redirectResponse */ , oldDocumentLoader.get (), WTFMove (formState), [this , frame, requesterOrigin = Ref { frameLoadRequest.requesterSecurityOrigin () }, historyHandling = frameLoadRequest.navigationHistoryBehavior ()] (const ResourceRequest& request, WeakPtr<FormState>&&, NavigationPolicyDecision navigationPolicyDecision) {
15871590 continueFragmentScrollAfterNavigationPolicy (request, requesterOrigin.ptr (), navigationPolicyDecision == NavigationPolicyDecision::ContinueLoad, historyHandling);
15881591 }, PolicyDecisionMode::Synchronous);
1592+
1593+ if (resetLoadTypeAfterFragmentNavigation)
1594+ policyChecker ().setLoadType (loadType);
1595+
15891596 return ;
15901597 }
15911598
0 commit comments