5

Try this in dev tools console:

JSON.stringify(document.body.getBoundingClientRect())

the output is {}, instead of something sensible.

Any ideas?

SuperUberDuper
  • 9,242
  • 9
  • 39
  • 72

1 Answers1

2

JSON.stringify internally uses a method called toJSON.

You can specify it for your object or in your case, override it:

ClientRect.prototype.toJSON = function(){ return { top: this.top } }

JSON.stringify(document.body.getBoundingClientRect())

"{"top":-583}"
johnnydev
  • 164
  • 1
  • 4