partytown icon indicating copy to clipboard operation
partytown copied to clipboard

[🐞] resolveUrl hook doesn't work

Open tcetin opened this issue 1 year ago • 8 comments

Describe the bug

I am trying to implement the partytown for the Facebook pixel. And there is a CORS issue. I created a reverse proxy to solve the problem. I am trying to map the proxy to the original connect.facebook.net hostname by using the resolveUrl hook. It still gives the CORS issue.

I use NextJS 13.

Reproduction

I work on localhost.

Steps to reproduce

Implement the Partytown configuration component in the _document.ts.

<Partytown
						debug={true}
						logScriptExecution
						forward={["dataLayer.push", "fbq", "uetq"]}
						resolveUrl={function (url) {
							const proxyMap = {
								"connect.facebook.net": `https://reverse-proxy-url`
							}
							url.hostname = proxyMap[url.hostname] || url.hostname
							return url
						}}
					/>

See the cors issue still that the resolveUrl hook doesnt work correctly.

Browser Info

Chrome

Additional Information

No response

tcetin avatar Sep 15 '23 16:09 tcetin

I think resolveUrl hook is called for all URLs. can you add console.log to it to see what it is getting called with?

mhevery avatar Sep 15 '23 19:09 mhevery

It was not working when I use "worker" strategy in NextJS. But it works without using "worker" strategy in NextJS. It can be also NextJS issue.

tcetin avatar Sep 18 '23 11:09 tcetin

I believe I am having the same issue. It doesn't seem like the resolveUrl function is being called at all.

Putting a console.log inside the resolveUrl function isn't resulting in anything being written to the console and the function doesn't change the behaviour of Partytown no matter what the function contains. Scripts without an issue with CORs still get fetched successfully and those with CORs issues still have issues.

            <Partytown
              debug={true}
              forward={['dataLayer.push', 'fbq']}
              resolveUrl={(url, location) => {
                return 'balls';
              }
              }
            />
            <script
              type="text/partytown"
              src={`https://www.googletagmanager.com/gtag/js?id=${process.env.NEXT_PUBLIC_GA_TRACKING_ID}`}
            ></script>
            <script
              type="text/partytown"
              dangerouslySetInnerHTML={{
                __html: `window.dataLayer = window.dataLayer || [];
                  function gtag(){dataLayer.push(arguments);}
                  gtag('js', new Date());
                  gtag('config', '${process.env.NEXT_PUBLIC_GA_TRACKING_ID}');`,
              }}
            />

samparmenter avatar Sep 26 '23 19:09 samparmenter

I am also facing the same issue. image

When I pass resolveUrl function as a prop, then it converts the function to a string, as seen in the above image.

I think the issue is at https://github.com/BuilderIO/partytown/blob/main/src/integration/snippet.ts#L7

developerKumar avatar Jan 31 '24 13:01 developerKumar

@developerKumar I see. May I ask you to drop a PR for that?

gioboa avatar Jan 31 '24 18:01 gioboa

I am also facing the same issue.

image

When I pass resolveUrl function as a prop, then it converts the function to a string, as seen in the above image.

I think the issue is at https://github.com/BuilderIO/partytown/blob/main/src/integration/snippet.ts#L7

If I'm not mistaken the function is serialized and converted to string in order to be sent to the worker and accesible from there. This way the worker can invoke it.

franpeza avatar Jan 31 '24 18:01 franpeza

@developerKumar I see. May I ask you to drop a PR for that?

Sure @gioboa , Still debugging it.

developerKumar avatar Feb 01 '24 13:02 developerKumar

Hi any update?

totodot avatar May 21 '24 19:05 totodot