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

sharedStorage not available in worklet JS #404

Open
ankwok opened this issue Aug 7, 2024 · 2 comments
Open

sharedStorage not available in worklet JS #404

ankwok opened this issue Aug 7, 2024 · 2 comments

Comments

@ankwok
Copy link

ankwok commented Aug 7, 2024

I'm trying to put together a toy example that sets some ID in Shared Storage, then uses the selectURL() function to choose a url based on that ID. This is pretty much the AB-test use-case here.

  • I can see that my (key, value) gets set into Shared Storage from the Chrome dev tools
  • From my server logs, the worklet JS code gets fetched

However, I get the following error in the console logs:

TypeError: Cannot read properties of undefined (reading 'get')

This happens inside my worklet's run(urls, data) function where I simply follow the example and perform await this.sharedStorage.get(myKey). Am I missing something here? Any help would be greatly appreciated. Thanks.

@xyaoinum
Copy link

xyaoinum commented Aug 7, 2024

In an object method, this refers to the object rather than the global object. I think you want globalThis, or, you can use sharedStorage directly.

The developer page seems to have the same problem, and we are working to correct it. Thanks for bringing this up.

@ankwok
Copy link
Author

ankwok commented Aug 7, 2024

Thanks @xyaoinum, this fixes the problem. I see that the docs are getting updated as we speak :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants