Skip to content

Commit

Permalink
Fix Service Worker matching external top-level URLs
Browse files Browse the repository at this point in the history
At the moment the Service Worker matches any external top-level path (e.g. https://any.external.domain.com/?query_params) as a home url, as `isHomeRoute` makes a mere string equality check against `url.pathname`.

I stumbled upon these while trying to load the script for Zendesk Chat, whose URL has the form `https://v2.zopim.com/?APP_KEY_HASH`.

This commit introduces an additional check to make sure that the URL origin matches the service worker origin, too, just as it would happen when passing a `RegExp` (bc of additional assumptions of workbox on the use of `RegExp`s that only make them match on local URLS)
  • Loading branch information
millennialdeveloper authored May 25, 2021
1 parent 888b9ba commit efe28fe
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion packages/venia-concept/src/ServiceWorker/registerRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export default function() {
* and the cycle repeats.
*/
registerRoute(
({ url }) => isHTMLRoute(url),
({ url }) => (url.origin === self.location.origin) && isHTMLRoute(url),
new StaleWhileRevalidate({
plugins: [
{
Expand Down

0 comments on commit efe28fe

Please sign in to comment.