question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

service-worker(safari): POST requests getting blocked with 504 by Service Worker

See original GitHub issue

🐞 bug report

Affected Package

@angular/service-worker

Is this a regression?

I don’t know if this has even worked properly in Safari, but it’s supposed to be production ready.

Description

Service Workers shouldn’t block POST requests AFAIK, but that’s happening on Safari Version 13.1 (15609.1.20.111.8) on macOS Catalina 10.15.4 (19E287).

🔬 Minimal Reproduction

  • Go to https://angular.io/ in Safari on macOS
  • Open your Dev tools Console
  • Browse around to some different pages like resources, guides, events, etc
  • Observe the following error in the console
https://www.google-analytics.com/j/collect?v=1&_v=j82&a=557396380&t=pageview&_s=1&dl=https%3A%2F%2Fangular.io%2Fresources%3Fcategory%3Ddevelopment&dp=%2Fresources&ul=en&de=UTF-8&dt=Angular&sd=24-bit&sr=1920x1080&vp=1914x532&je=1&_u=QACAAEABAAAAAC~&jid=43561559&gjid=590323957&cid=498157216.1589533208&tid=UA-8594346-15&_gid=406270144.1589533208&_r=1&z=73615628
Failed to load resource: the server responded with a status of 504 (Gateway Timeout)

🔥 Exception or Error

Cannot use wildcard in Access-Control-Allow-Origin when credentials flag is true., undefined

NGSW Debug Info:

Driver state: NORMAL ((nominal))
Latest manifest hash: a51465926eaa708ba14e763b3c654f2dc464f776
Last update check: 1m3s560u

=== Version a51465926eaa708ba14e763b3c654f2dc464f776 ===

Clients: 1692-8, 1692-33, 1692-59, 1692-63, 1692-70

=== Idle Task Queue ===
Last update tick: 28s363u
Last update run: 1m3s868u
Task queue:


Debug log:

[1m31s277u] TypeError(Cannot use wildcard in Access-Control-Allow-Origin when credentials flag is true., undefined) Driver.fetch(https://www.google-analytics.com/j/collect?v=1&_v=j82&a=1196111008&t=pageview&_s=1&dl=https%3A%2F%2Fangular.io%2Fguide%2Fservice-worker-communications&dp=%2Fguide%2Fservice-worker-communications&ul=en&de=UTF-8&dt=Angular&sd=24-bit&sr=1920x1080&vp=1914x532&je=1&_u=QACAAEABAAAAAC~&jid=323136214&gjid=1958337307&cid=498157216.1589533208&tid=UA-8594346-15&_gid=406270144.1589533208&_r=1&z=559832955)
[28s598u] TypeError(Cannot use wildcard in Access-Control-Allow-Origin when credentials flag is true., undefined) Driver.fetch(https://www.google-analytics.com/j/collect?v=1&_v=j82&a=1715609439&t=pageview&_s=5&dl=https%3A%2F%2Fangular.io%2Fguide%2Faccessibility&dp=%2Fresources&ul=en&de=UTF-8&dt=Angular%20-%20EVENTS&sd=24-bit&sr=1920x1080&vp=1914x532&je=1&_u=SACAAEABAAAAAC~&jid=721523635&gjid=563131875&cid=498157216.1589533208&tid=UA-8594346-15&_gid=406270144.1589533208&_r=1&z=882809832)
...
[3m52s] TypeError(Cannot use wildcard in Access-Control-Allow-Origin when credentials flag is true., undefined) Driver.fetch(https://www.google-analytics.com/j/collect?v=1&_v=j82&a=1121528947&t=pageview&_s=1&dl=https%3A%2F%2Fangular.io%2Fresources%3Fcategory%3Ddevelopment&dp=%2Fresources&ul=en&de=UTF-8&dt=Angular&sd=24-bit&sr=1920x1080&vp=1914x523&je=1&_u=QACAAEABAAAAAC~&jid=1658082190&gjid=2097738465&cid=498157216.1589533208&tid=UA-8594346-15&_gid=406270144.1589533208&_r=1&z=747985136)
[52s802u] TypeError(Cannot use wildcard in Access-Control-Allow-Origin when credentials flag is true., undefined) Driver.fetch(https://www.google-analytics.com/j/collect?v=1&_v=j82&a=1121528947&t=pageview&_s=3&dl=https%3A%2F%2Fangular.io%2Fresources%3Fcategory%3Ddevelopment&dp=%2Ffeatures&ul=en&de=UTF-8&dt=Angular%20-%20Angular%20Contributors&sd=24-bit&sr=1920x1080&vp=1914x523&je=1&_u=SACAAEABAAAAAC~&jid=2000655573&gjid=1284227509&cid=498157216.1589533208&tid=UA-8594346-15&_gid=406270144.1589533208&_r=1&z=1228242795)

Screen Shot 2020-05-15 at 05 28 50

Screen Shot 2020-05-15 at 05 12 17

🌍 Your Environment

Angular Version: 10.0.0-next.5

Anything else relevant? I’m also seeing this on my site when using LogRocket (another kind of analytics service), but the Headers it complains about are different:

Request header field Pragma is not allowed by Access-Control-Allow-Headers., undefined
NGSW Debug Info:

Driver state: EXISTING_CLIENTS_ONLY (Degraded due to failed initialization: Internal error
undefined)
Latest manifest hash: 5642c5e828814d3dae722eae1783dc4724682328
Last update check: 4s519u

=== Version 5642c5e828814d3dae722eae1783dc4724682328 ===

Clients: 779-37

=== Idle Task Queue ===
Last update tick: 3s197u
Last update run: 46s658u
Task queue:
 * check-updates-on-navigation

Debug log:
[5m51s257u] TypeError(Request header field Pragma is not allowed by Access-Control-Allow-Headers., undefined) Driver.fetch(https://r.lr-ingest.io/i?a=buymic%2Fdevintent-website&r=4-e8456afb-9941-460d-a17c-fddff8c6183e&t=e8d3692a-bb84-48ad-8f91-7dd31c74115c&ir=f&ht=f&s=0)
[5m48s165u] TypeError(Request header field Pragma is not allowed by Access-Control-Allow-Headers., undefined) Driver.fetch(https://r.lr-ingest.io/i?a=buymic%2Fdevintent-website&r=4-e8456afb-9941-460d-a17c-fddff8c6183e&t=e8d3692a-bb84-48ad-8f91-7dd31c74115c&ir=f&ht=f&s=0)

Screen Shot 2020-05-15 at 05 19 27 Screen Shot 2020-05-15 at 05 21 06 Screen Shot 2020-05-15 at 05 20 46

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:4
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
kossocommented, Oct 7, 2020

I am also getting random 504 errors on some HTTP Client API GET requests, only on Safari.

I never thought it might be the Service Worker…

Will attempt to add the ngsw-bypass header (or as a query param) in my HTTP request interceptor.

Update: : Adding ngsw-bypass=true to the HTTPRequest.params in an interceptor seems to have got rid of my random 504 errors.

Note: In the Safari Dev Console the erroneous requests were showing as related to the Service Worker.

1reaction
gkalpakcommented, May 26, 2020

This needs further investigation. Note that it might be related to the SW’s stripping off request headers (see #24227 for more info).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular service worker with @angular/pwa package showing ...
The 504 error doesn't come from your server, it comes from the service worker that is acting like a proxy. Every HTTP request...
Read more >
Angular Service Worker - Step-By-Step Guide
In this post, we will cover the following topics: Step 1 - Scaffolding an Angular PWA Application using the Angular CLI; Step 2...
Read more >
CSP: worker-src - HTTP - MDN Web Docs
The HTTP Content-Security-Policy (CSP) worker-src directive specifies valid sources for Worker , SharedWorker , or ServiceWorker scripts.
Read more >
Service Workers | Can I use... Support tables for ... - CanIUse
Global · Chrome · Edge * · Safari · Firefox · Opera · IE · Chrome for Android.
Read more >
Intermittently Service worker is n… | Apple Developer Forums
we are receiving the below error when service worker is not working: ... f(kDataNotAllowed{Data is not Allowed or Blocked: PDP Context canot ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found