简体   繁体   中英

Service worker fetch event not triggered by Google API requests

I've found that my requests to the Google API do not trigger a service-worker fetch event. Fetches for static resources and to other APIs trigger the event as expected.

Demo: https://laurieboyes.github.io/test-gapi-sw/

Demo code: https://github.com/laurieboyes/test-gapi-sw/blob/master/index.html

I haven't been able to find any documentation suggesting that this is by design.

Is anyone able to explain why the Google API requests don't trigger the fetch event? Could it be something to do with oAuth?

You can inspect your DOM and notice that Google's OAuth lib injects several invisible <iframe> s into your page, like this one:

<iframe name="oauth2relay368346125" id="oauth2relay368346125" 
  src="https://accounts.google.com/o/oauth2/postmessageRelay?parent=https%3A%2F%2Flaurieboyes.github.io&amp;...&amp;forcesecure=1"
  tabindex="-1" aria-hidden="true" 
  style="width: 1px; height: 1px; position: absolute; top: -100px;">
</iframe>

These <iframe> s are used for all the network communication with Google API. Note the <iframe> s are sourced from https://accounts.google.com origin, so these calls are made from outside of the scope of your service worker (that works within https://laurieboyes.github.io only).

There's no way your Service Worker can intercept that communication for security reasons.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM