title: Detect a hard reload with JavaScript
body: <p><strong>For clarification:</strong> I am <strong>not</strong> trying to differentiate between a refresh and a reload, hence this is not a duplicate of <a href="https://stackoverflow.com/questions/5004978/check-if-page-gets-reloaded-or-refreshed-in-javascript">refresh vs reload</a>. I am trying to find out if there is a way to detect when a user triggers a <a href="https://stackoverflow.com/a/14969509/981933"><em>hard</em> reload</a> instead of a normal reload. I am asking because I want to execute some code prior to a <em>hard</em> reload only.</p>
  
  <hr>
  
  <p>Using JavaScript, via the browsers' reload button, or by a shortcut like <kbd>Shift</kbd>+<kbd>Ctrl</kbd>+<kbd>R</kbd> it is possible to perform a <strong>hard</strong> reload of a browser tab. Is it possible to detect such a <strong>hard</strong> reload with JavaScript and if so how?</p>
  
  <p>I know one can detect when a normal reload event is triggered with the <code>onbeforeunload</code> event and I can find out the navigation type to differentiate between a refresh and a reload but I am unable to detect a hard reload.</p>
  
  <p>So far I'am using the following JS code to detect a reload:</p>
  
  <pre><code>window.addEventListener('beforeunload', function (e) {
    // Cancel the event
    e.preventDefault();
    // Chrome requires returnValue to be set
    e.returnValue = '';
  
    // For older browsers
    console.log('Is reloading?', event.currentTarget.performance.navigation.type === 1);
  
    // For modern browsers
    const perfEntries = performance.getEntriesByType("navigation");
  
    for (let i = 0; i &lt; perfEntries.length; i++) {
      console.log('Is reloading? ', perfEntries[i].type === 1);
    }
  });
  </code></pre>
  
  <p>I would like to be able to distinguish between a normal reload, e.g., <code>location.reload()</code>, and a forced reload, e.g., <a href="https://developer.mozilla.org/en-US/docs/Web/API/Location/reload" rel="nofollow noreferrer"><code>location.reload(true)</code></a>.</p>