feat(service-worker): support bypassing SW with specific header/query param (#30010)
Add support for bypassing the ServiceWorker for a request by using the ngsw-bypass header or query parameter. Fixes #21191 PR Close #30010
This commit is contained in:

committed by
Andrew Kushnir

parent
304a12f027
commit
6200732e23
@ -52,9 +52,9 @@ export class Adapter {
|
||||
/**
|
||||
* Extract the pathname of a URL.
|
||||
*/
|
||||
parseUrl(url: string, relativeTo?: string): {origin: string, path: string} {
|
||||
parseUrl(url: string, relativeTo?: string): {origin: string, path: string, search: string} {
|
||||
const parsed = new URL(url, relativeTo);
|
||||
return {origin: parsed.origin, path: parsed.pathname};
|
||||
return {origin: parsed.origin, path: parsed.pathname, search: parsed.search};
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -179,6 +179,10 @@ export class Driver implements Debuggable, UpdateSource {
|
||||
const scopeUrl = this.scope.registration.scope;
|
||||
const requestUrlObj = this.adapter.parseUrl(req.url, scopeUrl);
|
||||
|
||||
if (req.headers.has('ngsw-bypass') || /[?&]ngsw-bypass(?:[=&]|$)/i.test(requestUrlObj.search)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// The only thing that is served unconditionally is the debug page.
|
||||
if (requestUrlObj.path === '/ngsw/state') {
|
||||
// Allow the debugger to handle the request, but don't affect SW state in any other way.
|
||||
|
Reference in New Issue
Block a user