Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[🐞] Objects and object properties can't be forwarded #588

Open
DzmVasileusky opened this issue Apr 26, 2024 · 2 comments
Open

[🐞] Objects and object properties can't be forwarded #588

DzmVasileusky opened this issue Apr 26, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@DzmVasileusky
Copy link
Contributor

DzmVasileusky commented Apr 26, 2024

Describe the bug

Many third-party scripts are initialising global objects allowing to use its methods and properties (e.g. AppcuesBundleSettings.accountId).
Unfortunately object or non-functional object property can't be forwarded it seems.
Example of object:

const Foo {
  id: '123',
  func: () => {}
}

So Foo.func can be forwarded and used, while Foo.id isn't accessible.
Tried to set it in all the following ways with no luck (either returns 'undefined' or function definition from partytown):

partytown = {
  forward: ['Fooj', 'Foo.id'],
  globalFns: ['Foo', 'Foo.id']
};

Reproduction

https://82qcgq-5000.csb.app/

Steps to reproduce

  1. Open the link
  2. Open the console.log
  3. Refresh to see the initial log

Browser Info

Any

Additional Information

Feel free to convert to an Improvement if there is no any workaround

@DzmVasileusky DzmVasileusky added the bug Something isn't working label Apr 26, 2024
@mdrmtz
Copy link

mdrmtz commented May 16, 2024

Workaround using custom events to pass information or call objects from the main thread to Partytown or vice versa.

@DzmVasileusky
Copy link
Contributor Author

@mdrmtz Can you give an example of a custom event usage for this?
Do you mean calling window.postMessage from a loaded via partytown script and send an object inside?

Using loadScriptsOnMainThread isn't an option really when we can just not use partytown for it. It is more like a workaround when we want a tag script being called via partytown while the loaded script on the main thread. Not sure how much optimisation it provides.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants