From 6cd3743b44ce3f2d40b846c728f82f7d1816ad4f Mon Sep 17 00:00:00 2001 From: George Kalpakas Date: Wed, 20 Mar 2019 23:29:16 +0200 Subject: [PATCH] refactor(service-worker): use `Adapter#parseUrl()` for all URL parsing (#27080) This commit also ensures that the correct implementation is used on environments that do not support `URL` (e.g. Node.js). PR Close #27080 --- packages/service-worker/worker/src/adapter.ts | 2 +- packages/service-worker/worker/testing/scope.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/service-worker/worker/src/adapter.ts b/packages/service-worker/worker/src/adapter.ts index 5955cdd56b..a8fb54058c 100644 --- a/packages/service-worker/worker/src/adapter.ts +++ b/packages/service-worker/worker/src/adapter.ts @@ -18,7 +18,7 @@ export class Adapter { constructor(scope: ServiceWorkerGlobalScope) { // Suffixing `ngsw` with the baseHref to avoid clash of cache names // for SWs with different scopes on the same domain. - const baseHref = new URL(scope.registration.scope).pathname; + const baseHref = this.parseUrl(scope.registration.scope).path; this.cacheNamePrefix = 'ngsw:' + baseHref; } diff --git a/packages/service-worker/worker/testing/scope.ts b/packages/service-worker/worker/testing/scope.ts index 20fedb6a95..5ce782c98a 100644 --- a/packages/service-worker/worker/testing/scope.ts +++ b/packages/service-worker/worker/testing/scope.ts @@ -116,9 +116,9 @@ export class SwTestHarness implements ServiceWorkerGlobalScope, Adapter, Context constructor( private server: MockServerState, readonly caches: MockCacheStorage, private origin: string) { - this.time = Date.now(); - const baseHref = new URL(this.registration.scope).pathname; + const baseHref = this.parseUrl(origin).path; this.cacheNamePrefix = 'ngsw:' + baseHref; + this.time = Date.now(); } async resolveSelfMessages(): Promise {