I encountered strange behavior with the JSON.parse and JSON.stringify functions on one particular website, and I can’t figure out why this is happening. Running a snippet
typeof JSON.parse(JSON.stringify([1,3,4]))
on the tab with this site returns a result as a string
(when it should be an object
), but on all other tabs, it returns an object. There are no extensions enabled. A double JSON.parse (on the problematic tab) helps typeof JSON.parse(JSON.parse(JSON.stringify([1,3,4])))
, but it doesn’t explain where the issue originates. I suspect that some scripts might be loading on the problematic page, altering the function’s behavior, but I’m unsure how to check for this. JSON.stringify.toString()
and JSON.parse.toString()
returns native code in both cases.
What other checks can I perform? Which direction should I investigate, and what specifically should I look into?