You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

FCM Web推送通知无法触发问题求助

问题:Web端Firebase Messaging无法接收通知(iOS/Android正常)

我知道这个问题已被多次提及,但仍无法解决。通过Firebase云函数调用sendMulticast函数发送通知,函数返回所有Token均发送成功,且iOS和Android端能正常接收通知,但Web端完全无反应。

云函数发送代码

let res = await admin.messaging().sendMulticast({
  tokens: [...],
  notification: {
    title: title,
    body: body,
  },
  data: {
    ...
  },
  webpush: {
    headers: {
      image: `...`,
    },
    fcmOptions: {
      link: `...`,
    },
  },
  apns: {
    ...
  },
  android: {
    ...
  },
});

SvelteKit Service Worker配置

Service Worker已注册并激活,Chrome开发者工具控制台能输出Listening for background messages.日志:

import { initializeApp } from "firebase/app";
import { getMessaging, onBackgroundMessage } from "firebase/messaging/sw";

const firebaseApp = initializeApp({
  ...
});

self.console.log("Listening for background messages.");

onBackgroundMessage(getMessaging(firebaseApp), payload => {
  self.console.log('Background message received', payload);
});

客户端初始化代码

登录时通过Firebase Messaging获取Token,指定使用SvelteKit的Service Worker而非默认的firebase-messaging-sw,同时监听前台消息,浏览器控制台能输出Listening for foreground messages.日志:

import { getApp } from "firebase/app";
import { getMessaging, onMessage, getToken } from "firebase/messaging";

async function init() {
  let serviceWorkerRegistration = await navigator.serviceWorker.ready;
  let token = await getToken(getMessaging(getApp()), {
    vapidKey: "...",
    serviceWorkerRegistration: serviceWorkerRegistration,
  });
  console.log('Listening for foreground messages.', token);
  onMessage(getMessaging(getApp()), payload => {
    console.log('Foreground message received. ', payload);
  });
}

问题现象

发送通知后Web端无任何反馈:

  • 浏览器关闭或处于后台时,无后台通知日志,也无系统通知弹出
  • 浏览器前台聚焦时,无前台消息接收日志
  • 全程未出现任何错误提示

已排查的基础设置

  • 运行macOS系统,已关闭勿扰模式
  • Chrome浏览器及对应域名的通知权限均已开启

内容的提问来源于stack exchange,提问作者nicholas

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.29 20:05:22