Skip to content

Auth state lost after service worker terminates despite successful sign-in #9732

@phalgun

Description

@phalgun

Operating System

macOS (also reported on Windows)

Environment (if applicable)

Chrome 120+ (Manifest V3)

Firebase SDK Version

10.11.1

Firebase SDK Product(s)

Auth

Project Tooling

  • Chrome Extension with Manifest V3
  • Service Worker background script
  • Webpack bundler
  • React for popup UI

Detailed Problem Description

We are using firebase/auth/web-extension as documented for Chrome extensions with Manifest V3. Users successfully sign in with Google OAuth (via signInWithCredential), but after the service worker terminates and restarts (which happens after a few minutes of inactivity), onAuthStateChanged returns null even though the user was previously authenticated.

Expected behavior: Auth state should be persisted in IndexedDB and restored when the service worker restarts.

Actual behavior: Auth state is lost. Users have to sign in again after the service worker terminates.

We have added diagnostic code that checks IndexedDB directly when onAuthStateChanged returns null. In some cases, we observe that IndexedDB contains auth data but Firebase SDK fails to restore it.

We would like to understand how to persist the Firebase SDK authentication and connection in Chrome extension with manifest v3 specifically.

Steps and code to reproduce issue

  1. Install a Chrome extension using Manifest V3 with firebase/auth/web-extension. You can use ours (https://simplehuman.email/install) -> it is an extension with free trial for Gmail.
  2. Sign in with Google
  3. Verify user is authenticated (onAuthStateChanged returns user object)
  4. Close the extension popup and wait for the service worker to terminate (~5 minutes of inactivity)
  5. Reopen the extension or trigger service worker restart
  6. Observe that onAuthStateChanged returns null (user is logged out) -> You can see this in the extension Settings page where "Simplehuman Tabs" doesn't work as the Firebase connection isn't working anymore.

Only a sign in with Google again fixes this. But then after a few minutes of inactivity, the Firebase connection is lost again.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions