That's because window
has circular references (for instance, in most cases window.self
refers to window
) and then it cannot be converted to JSON, otherwise it would turn into an infinite loop.
This may happen on any object, not only on window
:
var foo = {
bar: 'bar'
};
JSON.stringify(foo); // works fine
var foo = {
bar: foo
};
JSON.stringify(foo); // circular reference -> crashes