electron-push-receiver icon indicating copy to clipboard operation
electron-push-receiver copied to clipboard

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

Open calvinckho opened this issue 5 years ago • 1 comments

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 :

PUSH_RECEIVER:::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/node_modules/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 avatar Jul 08 '20 09:07 calvinckho

#11

calvinckho avatar Jul 09 '20 00:07 calvinckho