diff --git a/packages/service-worker/worker/src/adapter.ts b/packages/service-worker/worker/src/adapter.ts index b9d81091f5..08f2d13b38 100644 --- a/packages/service-worker/worker/src/adapter.ts +++ b/packages/service-worker/worker/src/adapter.ts @@ -53,7 +53,9 @@ export class Adapter { * Extract the pathname of a URL. */ parseUrl(url: string, relativeTo?: string): {origin: string, path: string, search: string} { - const parsed = new URL(url, relativeTo); + // Workaround a Safari bug, see + // https://github.com/angular/angular/issues/31061#issuecomment-503637978 + const parsed = !relativeTo ? new URL(url) : new URL(url, relativeTo); return {origin: parsed.origin, path: parsed.pathname, search: parsed.search}; } diff --git a/packages/service-worker/worker/testing/scope.ts b/packages/service-worker/worker/testing/scope.ts index 997b7615cb..0ae7d384a6 100644 --- a/packages/service-worker/worker/testing/scope.ts +++ b/packages/service-worker/worker/testing/scope.ts @@ -186,7 +186,7 @@ export class SwTestHarness implements ServiceWorkerGlobalScope, Adapter, Context parseUrl(url: string, relativeTo?: string): {origin: string, path: string, search: string} { const parsedUrl: URL = (typeof URL === 'function') ? - new URL(url, relativeTo) : + (!relativeTo ? new URL(url) : new URL(url, relativeTo)) : require('url').parse(require('url').resolve(relativeTo || '', url)); return {