I want to convert the
window.screen
attributes and values into a string to send to the back-end. (I could extract the values for each attribute but curious to understand why the below fails)Not sure why
JSON.stringify(window.screen)
returns"{}"
.Note that the manually created object
orientation_
appears to convert JSON to string fine.
- Experimenting further, I tried copying the object and then deleting the
__proto__
object thinking this might be failing the conversion to string. But strangely I am unable to delete any of the keys!
Update #1:
Based on below tips that circular reference could be the issue...
Here we see that variable
a
has a circular reference to itself. Using Flatted(circular JSON parser) we seea
gets converted into String butwindow.screen
still doesn't convert.Based on the docs JSON.stringify(), functions are stringified as
null
.So functions are not the problem.
So still not clear on the reason for this behavior.