getFriendlyURL.js 542 B

123456789101112131415
  1. /*
  2. Copyright 2018 Google LLC
  3. Use of this source code is governed by an MIT-style
  4. license that can be found in the LICENSE file or at
  5. https://opensource.org/licenses/MIT.
  6. */
  7. import '../_version.js';
  8. const getFriendlyURL = (url) => {
  9. const urlObj = new URL(String(url), location.href);
  10. // See https://github.com/GoogleChrome/workbox/issues/2323
  11. // We want to include everything, except for the origin if it's same-origin.
  12. return urlObj.href.replace(new RegExp(`^${location.origin}`), '');
  13. };
  14. export { getFriendlyURL };