<script>
onload = function() {
    setTimeout(function() {
        // Start to go back (runs asynchonously)
        history.back();
        // But immediately cancel that load of a history item and navigate to
        // a fragment on the page instead. We should remain on this page and
        // a history item should be added (with past ones not being affected)
        setTimeout(function(){window.location = '#foo'}, 0);
    }, 0);
}
  
onhashchange = function() {
    setTimeout(done, 100);
}

function done() {
    delete sessionStorage.didNavigate;
    console.log('Visited fragment and waited.');
    if (window.testRunner) {
        testRunner.notifyDone();
    }
}
</script>
PASS
