Skip to content

Instantly share code, notes, and snippets.

@epreston
Created April 30, 2023 05:18
Show Gist options
  • Save epreston/9a65f60517969981d29e8a0d195d5cb3 to your computer and use it in GitHub Desktop.
Save epreston/9a65f60517969981d29e8a0d195d5cb3 to your computer and use it in GitHub Desktop.
javascript - compatibility - determine if an object is transferable to worker thread
function isTranferable(obj) {
try {
return (
obj instanceof ArrayBuffer ||
obj instanceof MessagePort ||
obj instanceof ImageBitmap || // safari 15+ ios 15+
obj instanceof OffscreenCanvas // safari 16.4+ ios 16.4+
);
} catch {
return false;
}
}
@allsey87
Copy link

I was hoping for an inbuilt browser function for this, but considering the list of transferable objects is quite short, this seems like a reasonable approach to me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment