mirror of
				https://github.com/mozilla/gecko-dev.git
				synced 2025-11-03 17:58:55 +02:00 
			
		
		
		
	Automatic update from web-platform-tests BFCache: Make a WPT test work with BFCache If we enable same-site backward/forward cache, backward navigation does not trigger onload event. This CL updates a WPT that depends on the onload event to handle pageshow event and makes it work with backward/forward cache. Bug: 1132180 Change-Id: I663f9c78e8b9835f081c5262b446bd56dba07cf9 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2520558 Reviewed-by: Fergal Daly <fergal@chromium.org> Reviewed-by: Rakina Zata Amni <rakina@chromium.org> Commit-Queue: Hitoshi Yoshida <peria@chromium.org> Cr-Commit-Position: refs/heads/master@{#824321} -- wpt-commits: 09e030df327205fe29640f24ff7085afc81759bc wpt-pr: 26408
		
			
				
	
	
		
			33 lines
		
	
	
	
		
			1 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			33 lines
		
	
	
	
		
			1 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
function checkScroll() {
 | 
						|
  // Ensure two animation frames on load to test the fallback to element
 | 
						|
  // anchor, which gets queued for the next frame if the text fragment is not
 | 
						|
  // found.
 | 
						|
  requestAnimationFrame(() => {
 | 
						|
    requestAnimationFrame(() => {
 | 
						|
      let results = {
 | 
						|
        scrolled: (window.pageYOffset != 0),
 | 
						|
      };
 | 
						|
 | 
						|
      let key = (new URL(document.location)).searchParams.get("key");
 | 
						|
      stashResultsThenClose(key, results);
 | 
						|
    });
 | 
						|
  });
 | 
						|
}
 | 
						|
 | 
						|
window.addEventListener('pageshow', () => {
 | 
						|
  if (location.hash == "#history") {
 | 
						|
    // This is the "history" test - on the first load we'll navigate to a page
 | 
						|
    // that calls history.back(). When we load a second time (from the back
 | 
						|
    // navigation), record the scroll state at that point to check how history
 | 
						|
    // scroll restoration is handled.
 | 
						|
    if (history.state == null) {
 | 
						|
      history.pushState("test", "test", "");
 | 
						|
      requestAnimationFrame(() => {
 | 
						|
        location.href = "navigate-back.html";
 | 
						|
      });
 | 
						|
      return;
 | 
						|
    }
 | 
						|
  }
 | 
						|
 | 
						|
  checkScroll();
 | 
						|
});
 |