Skip to content

analytics error in service worker window is not defined #7534

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Capricair opened this issue Aug 8, 2023 · 2 comments
Closed

analytics error in service worker window is not defined #7534

Capricair opened this issue Aug 8, 2023 · 2 comments

Comments

@Capricair
Copy link

Operating System

Windows 10

Browser Version

Chrome/114

Firebase SDK Version

10.1.0

Firebase SDK Product:

Analytics

Describe your project's tooling

nextjs app with webpack

Describe the problem

getAnalytics(app) throw window is not defined error in service worker

Steps and code to reproduce issue

// service worker

import { initializeApp } from "https://www.gstatic.com/firebasejs/10.1.0/firebase-app.js";
import { getAnalytics } from "https://www.gstatic.com/firebasejs/10.1.0/firebase-analytics.js";

const app = initializeApp({...});
const analytics = getAnalytics(app);
@Capricair Capricair added new A new issue that hasn't be categoirzed as question, bug or feature request question labels Aug 8, 2023
@google-oss-bot
Copy link
Contributor

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

@jbalidiong jbalidiong added needs-attention api: analytics and removed needs-triage new A new issue that hasn't be categoirzed as question, bug or feature request labels Aug 8, 2023
@jbalidiong
Copy link
Contributor

Hi @Capricair, thanks for reaching out to us. If you are receiving this error, it means that this method should be use in the regular client code and not in service worker. Cookies aren't available in service workers, and Analytics requires cookies to work.

This seems to be out of scope for Firebase JS SDK. There doesn't seem to be a bug, and Analytics will not work in a service worker context and for additional information (see #2243 (comment)). I'll be closing this issue now. If you encounter another issue, feel free to create a new one.

@firebase firebase locked and limited conversation to collaborators Sep 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants