Partytown worker failing to initialize after passing non-serializable objects to postMessage #458
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What is it?
Description
After adding an example Klaviyo script tag, the Partytown workers fails to initialize because of the following error:
Further debugging shows that the Klaviyo object (
window.klaviyo
) is the culprit of the non-serializable objects (below links are images):Analyzing Klaviyo object serializability
Debug logs before initial
postMessage
call with the results ofreadMainPlatform
More information at the following Loom recording
In the Loom there seems to be weird behavior with reloading with/without cache and with the "Update on reload" option checked for the service worker.
Gists mentioned in recording:
Gist 1
Gist 2
Debugging
The debugging I did was on a different version of Partytown, but:
NB: I tried adding a check whether an object is serializable before pushing it to the interfaces array, which helped with initializing the worker, but it then started throwing errors about missing constructors (I remember it missing a constructor for
Element
), which made me think the solution might not be a simple serializability check.I can reproduce the debugging if that would help, but it's mostly just a
isSerializable
function and some console logs inreadOwnImplementation
.Checklist: