supportsHistory.js 1.2 KB

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