JSON Parse error: Unrecognized token '!' - error caught by Sentry

I'm seeing this a lot, and it seems to be coming 100% from users using Facebook browser on iOS (I guess this is the browser you see when you're using the Facebook app).

I tried to debug this with a snippet:

<script>
    window.addEventListener('message', function (e) {
        console.log(e);
        JSON.parse(e.data);
        console.log('foo');
    }, false);
</script>

This is from the library you linked. Assuming that e.data is JSON string (not e.g. an object?), without any safeguard seems to be breaking things.

The second console.log doesn't fire, so I think this is causing some unexpected behaviours in my case (buttons not reacting to clicks with js listeners etc)

I don't know if there is a workaround or a way to protect from this in Facebook embedded browser (I guess it's loaded there)

Looking forward to hear more info