fix(service-worker): ignore invalid only-if-cached requests (#22883)

Under some circumstances (possibly related to opening Chrome DevTools),
requests are made with `cache: 'only-if-cached'` and `mode: 'no-cors'`.
These request will eventually fail, because `only-if-cached` is only
allowed to be used with `mode: 'same-origin'`.
This is likely a bug in Chrome DevTools.

This commit avoids errors related to such requests by not handling them.

Fixes #22362

PR Close #22883
This commit is contained in:
George Kalpakas
2018-03-20 15:10:59 +02:00
committed by Alex Rickabaugh
parent ae9c25ff3d
commit 0d4fe38a09
3 changed files with 43 additions and 6 deletions

View File

@ -708,6 +708,15 @@ const manifestUpdateHash = sha1(JSON.stringify(manifestUpdate));
expect(driver.state).toEqual(DriverReadyState.EXISTING_CLIENTS_ONLY);
});
async_it('ignores invalid `only-if-cached` requests ', async() => {
const requestFoo = (cache: RequestCache | 'only-if-cached', mode: RequestMode) =>
makeRequest(scope, '/foo.txt', undefined, {cache, mode});
expect(await requestFoo('default', 'no-cors')).toBe('this is foo');
expect(await requestFoo('only-if-cached', 'same-origin')).toBe('this is foo');
expect(await requestFoo('only-if-cached', 'no-cors')).toBeNull();
});
});
});
})();