You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm exploring the option of integrating Partytown into our app, but have come across a hitch.
Some of our tags are "Custom HTML", that actually inject a <script> tag in the DOM and expect some global methods to be available in the window scope. Here's a pared-down example of the Custom HTML tag:
<script>// Prepare some payloadwindow.someObject.someMethod(preparedPayload);</script>
When the tag is executed in the context of the service worker, someObject does not exist so we get warnings like this on the main thread:
TypeError: Cannot read properties of undefined (reading 'someMethod')
at Proxy.eval (eval at run (partytown-ww-sw.js?v=0.8.2:707:9), <anonymous>:3:147)
at run (partytown-ww-sw.js?v=0.8.2:707:37)
at runScriptContent (partytown-ww-sw.js?v=0.8.2:691:13)
at partytown-ww-sw.js?v=0.8.2:1788:54
at receiveMessageFromSandboxToWorker (partytown-ww-sw.js?v=0.8.2:1792:19)
There are two things I am hoping to get help with
1. Is there a workaround for this?
I tried to add 'someObject' and 'someObject.someMethod' to the forward option, no luck
2. Can i somehow move calls to someObject.someMethod into the Partytown worker as well?
someMethod is actually a function that sends the payload to a tracking service, so it's a prime candidate for moving off the main thread.
However, given the business requirements we need to keep it exposed under window.someObject in order for it to be called from tags.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi all,
I'm exploring the option of integrating Partytown into our app, but have come across a hitch.
Some of our tags are "Custom HTML", that actually inject a
<script>
tag in the DOM and expect some global methods to be available in the window scope. Here's a pared-down example of the Custom HTML tag:When the tag is executed in the context of the service worker,
someObject
does not exist so we get warnings like this on the main thread:There are two things I am hoping to get help with
1. Is there a workaround for this?
I tried to add
'someObject'
and'someObject.someMethod'
to theforward
option, no luck2. Can i somehow move calls to
someObject.someMethod
into the Partytown worker as well?someMethod
is actually a function that sends the payload to a tracking service, so it's a prime candidate for moving off the main thread.However, given the business requirements we need to keep it exposed under
window.someObject
in order for it to be called from tags.Beta Was this translation helpful? Give feedback.
All reactions