Skip to content

Instantly share code, notes, and snippets.

@epreston
Created April 30, 2023 05:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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;
}
}
@epreston
Copy link
Author

This sidesteps a browser compatibility issue with Safari.

At the time or writing, 16.4 is the recent release introducing support for OffscreenCanvas. Version 15 is still popular, and version 14 is rare but still 3x more common than the latest release.

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