ionic-team / capacitor-background-runner

Other
35 stars 18 forks source link

Background runner plugin: backgroundrunner.dispatchEvent error #62

Open JEricaM opened 9 months ago

JEricaM commented 9 months ago

Bug Report

Plugin(s)

"@capacitor/background-runner": "^1.0.5",

Capacitor Version

@capacitor/cli: 5.0.5 @capacitor/core: 5.0.5 @capacitor/android: 5.0.5 @capacitor/ios: 5.0.5

Platform(s)

Android, ios

Current Behavior

I'm using capacitor in a ionic+ stencil application

I'm not able to start correctly BackgroundRunner plugin

This is my runner.js location

Screenshot 2023-10-30 alle 14 58 49

this is my capacitor.config.ts

{
  "appId": "com.myapp.app",
  "appName": "MyApp",
  "webDir": "www",
  "server": {
    "androidScheme": "https"
  },
  "ios": {
    "handleApplicationNotifications": false
  },
  "plugins":{
    "BackgroundRunner": {
      "label": "com.myapp.app.check",
      "src": "runner.js",
      "event": "checkIn",
      "repeat": true,
      "interval": 2,
      "autoStart": false
    }
  }
}

And I have this error

Screenshot 2023-10-30 alle 15 01 33

Is a problem cause by a wrong path for the runner.js file or something else? I'm not able to make it work!

Expected Behavior

Plugin runs correctly

theproducer commented 9 months ago

What does your js file look like? It looks like you may have a syntax error.

ondrix commented 5 months ago

Hi, same problem here. This is my runner file. That import at the top is a troublemaker. Without it the runner is working but the reference is missing. Is it a bug or am I doing something wrong?

import { LocalNotifications } from "@capacitor/local-notifications";

addEventListener("myCustomEvent", (resolve, reject, args) => {
  try {
    LocalNotifications.checkPermissions().then((result) => {
      if (result.display === "granted") {
        LocalNotifications.schedule({
          notifications: [
            {
              title: "Push working",
              body: "100%",
            },
          ],
        });
      }
    });
  } catch (error) {
    console.error("Background task error:", error);
  }
  resolve();
});
ondrix commented 5 months ago

OK if I understand correctly just few common use cases are supported for background runner and the root of the runner file can contain only runner function itself. Maybe some explanaitory error message would be fine ;)

razvidos commented 2 months ago

the same shit. So stupid that it is only a short message without any details.