fix(IndexedDB): don't crash on empty IDB#35779
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR addresses an issue where an empty IndexedDB could cause a crash by adding a dedicated test and introducing early returns in the storage state retrieval logic.
- Adds a new test to ensure proper handling of an empty IndexedDB.
- Implements early return checks in the storage script to prevent crashes when no object stores are present.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/library/browsercontext-storage-state.spec.ts | Introduces a test to verify safe handling of empty IndexedDB databases. |
| packages/playwright-core/src/server/storageScript.ts | Adds early return checks to avoid processing empty IndexedDB instances. |
| const db = await this._idbRequestToPromise(openRequest); | ||
|
|
||
| if (db.objectStoreNames.length === 0) | ||
| return; |
There was a problem hiding this comment.
The early return here returns undefined, which is inconsistent with the branch at line 88 that returns an object with empty stores. To avoid potential type inconsistencies for callers, consider unifying the behavior so that both cases return a consistent storage state representation.
| return; | |
| return { restored: false }; |
There was a problem hiding this comment.
c'mon copilot! restore doesn't have a return value anyways, it's OK that it returns undefined
Test results for "tests 1"5 flaky39092 passed, 809 skipped Merge workflow run. |
Resolves #35760