MatthieuLemoine / electron-push-receiver

A module to bring Web Push support to Electron allowing it to receive notifications from Firebase Cloud Messaging (FCM).
https://medium.com/@MatthieuLemoine/my-journey-to-bring-web-push-support-to-node-and-electron-ce70eea1c0b0
MIT License
191 stars 62 forks source link

PUSH_RECEIVER:::Error while starting the service TypeError: Object has been destroyed #70

Open calvinckho opened 3 years ago

calvinckho commented 3 years ago

Here is my setup.

"dependencies": { "@capacitor/electron": "2.2.1", "electron-push-receiver": "^2.1.3", "electron-updater": "^4.3.1", }, "devDependencies": { "electron": "9.1.0", "electron-builder": "22.7.0" },

in the renderer process:

import {
    START_NOTIFICATION_SERVICE,
    NOTIFICATION_SERVICE_STARTED,
    NOTIFICATION_SERVICE_ERROR,
    NOTIFICATION_RECEIVED as ON_NOTIFICATION_RECEIVED,
    TOKEN_UPDATED,
} from 'electron-push-receiver/src/constants';

// Listen for service successfully started
ipcRenderer.on(NOTIFICATION_SERVICE_STARTED, (_, token) => // do something);
// Handle notification errors
ipcRenderer.on(NOTIFICATION_SERVICE_ERROR, (_, error) => // do something);
// Send FCM token to backend
ipcRenderer.on(TOKEN_UPDATED, (_, token) => // Send token);
// Display notification
ipcRenderer.on(ON_NOTIFICATION_RECEIVED, (_, notification) => // display notification);
// Start service
ipcRenderer.send(START_NOTIFICATION_SERVICE, senderId);

in the main process:

setupPushReceiver(mainWindow.webContents);

I received the following error when running the electron app, when it is setting up the push receiver :

PUSHRECEIVER:::Error while starting the service TypeError: Object has been destroyed at WebContents..send (electron/js2c/browser_init.js:173:2098) at IpcMainImpl. (/Users/pianokai/Sites/restvo/front/electron/nodemodules/electron-push-receiver/src/index.js:55:19) (node:81584) UnhandledPromiseRejectionWarning: TypeError: Object has been destroyed at WebContents..send (electron/js2c/browser_init.js:173:2098) at IpcMainImpl. (/Users/pianokai/Sites/restvo/front/electron/node_modules/electron-push-receiver/src/index.js:59:19)

upon further investigation, it seems like it crashed in src/index.js line 52 - 55

      // Listen for GCM/FCM notifications
      await listen(Object.assign({}, credentials, { persistentIds }), onNotification(webContents));
      // Notify the renderer process that we are listening for notifications
      webContents.send(NOTIFICATION_SERVICE_STARTED, credentials.fcm.token);
calvinckho commented 3 years ago

11