Hi
when I run my runner.js file, i get Uncaught (in promise) Error: Error: public/runner.js from logcat
// runner.js
addEventListener('fetchTest', async (resolve, reject, args) => {
console.log(JSON.stringify({ EVENT: 'fetchTest' }));
try {
const res = await fetch('https://randomuser.me/api/');
if (!res.ok) {
throw new Error('Could not fetch user');
}
const result = await res.json();
resolve(result['results'][0]);
} catch (err) {
console.log(JSON.stringify({ ERROR1: 'test' }));
reject(err);
}
});
addEventListener('test', async (resolve, reject, args) => {
console.log(JSON.stringify({ EVENT: 'test' }));
try {
console.log(JSON.stringify({ test: 'test' }));
resolve();
} catch (err) {
console.log(JSON.stringify({ ERROR2: 'test' }));
reject(err);
}
});
capacitor.config.ts
const config: CapacitorConfig = {
...
plugins: {
BackgroundRunner: {
label: 'com.va.mozatunes.app.task',
src: 'runner.js',
event: 'test',
repeat: true,
interval: 5,
autoStart: true,
},
},
...
}
//my code
await BackgroundRunner.dispatchEvent({
label: 'com.my.app.task',
event: 'test',
details: {},
});