Skip to content

fix(IndexedDB): don't crash on empty IDB#35779

Merged
Skn0tt merged 1 commit into
microsoft:mainfrom
Skn0tt:fix-empty-idb
Apr 28, 2025
Merged

fix(IndexedDB): don't crash on empty IDB#35779
Skn0tt merged 1 commit into
microsoft:mainfrom
Skn0tt:fix-empty-idb

Conversation

@Skn0tt
Copy link
Copy Markdown
Member

@Skn0tt Skn0tt commented Apr 28, 2025

Resolves #35760

@Skn0tt Skn0tt requested review from Copilot and dgozman April 28, 2025 12:54
@Skn0tt Skn0tt self-assigned this Apr 28, 2025
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link

Copilot AI Apr 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
return;
return { restored: false };

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c'mon copilot! restore doesn't have a return value anyways, it's OK that it returns undefined

@github-actions
Copy link
Copy Markdown
Contributor

Test results for "tests 1"

5 flaky ⚠️ [chromium-library] › library/chromium/oopif.spec.ts:284:3 › should click @chromium-ubuntu-22.04-node20
⚠️ [firefox-library] › library/inspector/cli-codegen-1.spec.ts:986:7 › cli codegen › should not throw csp directive violation errors @firefox-ubuntu-22.04-node18
⚠️ [firefox-page] › page/page-evaluate.spec.ts:424:3 › should throw for too deep reference chain @firefox-ubuntu-22.04-node18
⚠️ [installation tests] › playwright-electron-should-work.spec.ts:44:5 › should work when wrapped inside @playwright/test and trace is enabled @package-installations-macos-latest
⚠️ [playwright-test] › ui-mode-test-watch.spec.ts:145:5 › should watch all @windows-latest-node18-1

39092 passed, 809 skipped
✔️✔️✔️

Merge workflow run.

@Skn0tt Skn0tt merged commit ed23a93 into microsoft:main Apr 28, 2025
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Error when saving storageState (with IndexedDB)

3 participants