title: How to prepare a JavaScript value for storage in Firebase Firestore?
body: <p>Given an unknown JavaScript value, I would like to write it to a property of a Firestore document. But Firestore rejects some values. For example when trying to store the browser's window object, Firestore reports an error:</p>
  <blockquote>
  <p>#object[FirebaseError FirebaseError: [code=invalid-argument]: Function DocumentReference.update() called with invalid data.
  Unsupported field value: a custom Window object (found in field data.window in document errors/Ic0sCeKezM1x1kDBI3Hy1)]</p>
  </blockquote>
  <p>The usecase ist to write catched errors to Firestore. But catched errors can be or can contain all kinds of (nested) properties.</p>
  <p>So how can I &quot;prepare&quot; an arbitrary value for storage in Firebase? Invalid values could be converted to Strings or just skipped from writing. But the coercion must always succeed.</p>