ConstraintError: IndexedDB key already exists

The write conflicts with an existing key or a value that a unique index requires to be distinct. Inspect the object store’s key path and index definitions. Compare the failing record with existing data to find out which constraint it violated.
Use add() to reject a duplicate creation and put() when update or insertion is intended. A unique index on another record can still reject put(). Check which constraint reported the error before changing the operation.
const tx = db.transaction('items', 'readwrite'); const store = tx.objectStore('items'); store.put({ id: 42, label: 'Updated' }); // Overwrite existing key
Try a fresh key, the existing key and a different key with a duplicate unique-index value. The first two show whether creation and update behave as intended. The last one checks the constraint that put() still has to honor.
Check the store key path and unique indexes against the failing record before choosing add() or put().