Skip to content

Instantly share code, notes, and snippets.

@Raiondesu
Created September 16, 2020 12:01
Show Gist options
  • Save Raiondesu/d4491ae05b46ea32d6d803066f9d7997 to your computer and use it in GitHub Desktop.
Save Raiondesu/d4491ae05b46ea32d6d803066f9d7997 to your computer and use it in GitHub Desktop.
Check if JS object is a proxy
// Credit to https://stackoverflow.com/a/49651719 and https://stackoverflow.com/a/60323358
const isProxy = obj => {
try {
postMessage(obj, window);
} catch (error) {
return error && error.code === 25;
}
return false;
};
@zb3
Copy link

zb3 commented Feb 28, 2024

This could be shortened to use structuredClone. However, in adversarial context this is invasive, since the object knows it's being checked (some handlers might be executed before an exception is thrown)

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