ionic-team / ionic-team/capacitor-background-runner

dispatchEvent details are not passed to background args

Open
#100 0 comments 1 reaction 1 assignee Claimed by @theproducer View on GitHub
Dominant language
C
Stars
56
Forks
36
Avg merge
4d 12h
Merged PRs (30d)
7

Description

As the title describes `dispatchEvent details are not passed to background args` so i cannot use any component data in my background proces for fetching stuff for example

**Let's say i have a function triggered by a button:**

```
async activateBackgroundTask() {
try {
await BackgroundRunner.dispatchEvent({
label: 'com.app.app.check',
event: 'backgroundEventExecute',
details: { hello: "Hello world"},
})
} catch (error) {
console.error('Background task error:', error);
}
}
```

**And a runner.js like this:**

```
addEventListener('backgroundEventExecute', async (resolve, reject, args) => {
try {
// Notify that the background event was triggered
console.log('backgroundEventExecute: ', args, args.hello);
resolve();
} catch (error) {
console.error('Error in backgroundEvent:', error);
reject(error);
}
});
```

My args is always empty so the data i want to pass will never reach the background process. My console.log is reached and printed in the console. I've also tried to use CapacitorKV.get but i cannot use CapacitorKV.set in my angular/ionic component as it is not available there..

Specs:
```
"@capacitor/background-runner": "^1.1.0",
Angular: 17.x.x
Capacitor: 6.x.x
```

Can someone please tell me how to solve this issue OR fix this so we can use this background-runner?

Thanks in advance!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.