Skip to content
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

Background runner plugin: backgroundrunner.dispatchEvent error #62

Open
JEricaM opened this issue Oct 30, 2023 · 4 comments
Open

Background runner plugin: backgroundrunner.dispatchEvent error #62

JEricaM opened this issue Oct 30, 2023 · 4 comments

Comments

@JEricaM
Copy link

JEricaM commented Oct 30, 2023

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

@jcesarmobile jcesarmobile transferred this issue from ionic-team/capacitor-plugins Nov 1, 2023
@theproducer
Copy link
Collaborator

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

@ondrix
Copy link

ondrix commented Feb 24, 2024

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
Copy link

ondrix commented Feb 25, 2024

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants