feat: Allow forward calls with return value
This PR adds forwardCall functionality. This modification allows 2-way communication between main thread and webworker to retrieve return value of forwarded functions. Such functionality can be usefull when working with more complex third-party scripts when return value of them required in main thread (such as mixpanel and etc). Otherwise developers have to either implement this kind of forwarding themselfs or entirely put additional logic to sandboxed script.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
| Name | Status | Preview | Comments | Updated (UTC) |
|---|---|---|---|---|
| partytown | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Apr 25, 2023 1:03pm |
@Girilloid Is there a way to use mixanel with partytown until your PR is merged? I have tried
function getProxyUrl (url) {
const protocol = location?.protocol || 'https';
return 'https://cdn.builder.codes/api/v1/js-proxy?url=' + encodeURIComponent(protocol + url) + '&apiKey=0000000000000000000000';
}
partytown = {
loadScriptsOnMainThread: [
getProxyUrl('//bat.bing.com/bat.js'),
getProxyUrl('//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js')
],
resolveUrl: function (url, location, type) {
if (type === 'script' || type === 'iframe') {
const proxyUrl = new URL('https://cdn.builder.codes/api/v1/js-proxy');
proxyUrl.searchParams.append('url', url.href);
proxyUrl.searchParams.append('apiKey', '0000000000000000000000');
return proxyUrl;
}
return url;
}
};
It is working for bing but isn't working for mixpanel
@Girilloid Is there a way to use mixanel with partytown until your PR is merged? I have tried ... It is working for bing but isn't working for mixpanel
Actually we don't proxy mixpanel, as we had no CORS issues with it. For other stuff it was working pretty fine, except some situations. Actually this PR solves problem when you need to get some information from mixpanel in main thread, i.e. get mixpanel user id or registered values. You are still able to use mixpanel without such feature. The only thing is that you will have to move mentioned functionality to some script which will run inside partytown worker.
@Girilloid thanks have figured it out as well and created a list of scripts which don't need proxy.
seems this can support the use case on https://github.com/BuilderIO/partytown/issues/350
Any plans to merge these changes?
This PR is old, so I'm closing this for now. Feel free to re-open it if it's still valid. Thanks.