partytown icon indicating copy to clipboard operation
partytown copied to clipboard

Add new parameter to resolveUrl (cors: boolean)

Open wardpeet opened this issue 2 years ago • 1 comments

The reverse proxy feature is excellent to combat CORS. We've found some friction with it if we want to configure it with Google Tag Manager or other tag managers.

  1. We can route all traffic through a reverse proxy to mitigate CORS, but this can increase bandwidth usage and increase pricing depending on caching rules.
  2. We can configure all domains we should run through the proxy but that makes us a bottleneck when marketing folks want to add their scripts.

My suggestion here is to change the signature of resolveUrl. Current:

resolveUrl(url: URL, location: Location): URL | undefined | null

New:

resolveUrl(url: URL, location: Location, cors: boolean): URL | undefined | null

Hear me out :) First-time resolveUrl is called with cors false. If the request fails because of cors we try to fetch again and set cors to true. Now, we can only route the scripts missing cors headers through our reverse proxy.

I'm curious what you think, I don't mind implementing this feature with the proper guidance :)

wardpeet avatar Apr 07 '22 14:04 wardpeet

oh that's interesting, or we can allow a lower level replacement of the fetch implementation entirely so you could patch in special logic like this yourself. will leave this issue open for discussion

steve8708 avatar May 28 '22 19:05 steve8708