ionic-team / capacitor-background-runner

Other
37 stars 21 forks source link

Websocket connection or importing packages #101

Open mikobo opened 1 month ago

mikobo commented 1 month ago

Hi, I created my own background runner and it is working ok, with basic JavaScript. The problem starts when i need to connect using Websocket. I also tried to import some packages but i wont let me do it. Is there any option to bypass this problem, or some how run Websocket connection in background? Im running vite, Ionic 6, vue.

theproducer commented 1 month ago

Regarding importing packages in order to do Websockets (or other stuff): that will not work. As noted here: https://capacitorjs.com/docs/apis/background-runner#javascript-api

Background Runner does not execute your Javascript code in a browser or web view, therefore the typical Web APIs you may be used to may not be available. This includes DOM APIs nor ability to interact with your application's DOM.

Most packages assume they are running in the browser with the full suite of WebAPIs available, but that's not the case here. I assume any Websocket package you are trying to use is expecting https://developer.mozilla.org/en-US/docs/Web/API/WebSocket to be available, but its not currently in the runtime.

Adding Websocket support is something I can definitely look into adding some time in the future.