Created
September 16, 2020 12:01
-
-
Save Raiondesu/d4491ae05b46ea32d6d803066f9d7997 to your computer and use it in GitHub Desktop.
Check if JS object is a proxy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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)