supportsHistory.js 1.1 KB

1234567891011121314151617181920212223242526272829
  1. import { getGlobalObject } from '../worldwide.js';
  2. // Based on https://github.com/angular/angular.js/pull/13945/files
  3. // eslint-disable-next-line deprecation/deprecation
  4. const WINDOW = getGlobalObject();
  5. /**
  6. * Tells whether current environment supports History API
  7. * {@link supportsHistory}.
  8. *
  9. * @returns Answer to the given question.
  10. */
  11. function supportsHistory() {
  12. // NOTE: in Chrome App environment, touching history.pushState, *even inside
  13. // a try/catch block*, will cause Chrome to output an error to console.error
  14. // borrowed from: https://github.com/angular/angular.js/pull/13945/files
  15. /* eslint-disable @typescript-eslint/no-unsafe-member-access */
  16. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  17. const chrome = (WINDOW ).chrome;
  18. const isChromePackagedApp = chrome && chrome.app && chrome.app.runtime;
  19. /* eslint-enable @typescript-eslint/no-unsafe-member-access */
  20. const hasHistoryApi = 'history' in WINDOW && !!WINDOW.history.pushState && !!WINDOW.history.replaceState;
  21. return !isChromePackagedApp && hasHistoryApi;
  22. }
  23. export { supportsHistory };
  24. //# sourceMappingURL=supportsHistory.js.map