tauri-apps / plugins-workspace

All of the official Tauri plugins in one place!
https://tauri.app
Apache License 2.0
758 stars 202 forks source link

handling of websocket on webview reload #1507

Open rtiagom opened 2 days ago

rtiagom commented 2 days ago

What's the recommended way to handle the websocket when reloading the webview? If we don't disconnect the websocket we get a lot of error messages similar to the one below:

[Error] TypeError: window['_' + 1465076431] is not a function. (In 'window['_' + 1465076431]({ message: response, id: 8 })', 'window['_' + 1465076431]' is undefined) — 127.0.0.1:1:162
    error

We tried to disconnect the socket during the unload event but it doesn't work. Fetch API cannot load ipc://localhost/plugin%3Awebsocket%7Csend due to access control checks.

beforeunload event doesn't trigger.

> tauri info

[✔] Environment
    - OS: Mac OS 14.5.0 X64
    ✔ Xcode Command Line Tools: installed
    ✔ rustc: 1.77.2 (25ef9e3d8 2024-04-09)
    ✔ cargo: 1.77.2 (e52e36006 2024-03-26)
    ✔ rustup: 1.27.1 (54dd3d00f 2024-04-24)
    ✔ Rust toolchain: 1.77.2-aarch64-apple-darwin (default)
    - node: 20.11.0
    - npm: 10.2.4

[-] Packages
    - tauri [RUST]: 2.0.0-beta.22
    - tauri-build [RUST]: 2.0.0-beta.17
    - wry [RUST]: 0.40.1
    - tao [RUST]: 0.28.1
    - @tauri-apps/api [NPM]: 2.0.0-beta.13
    - @tauri-apps/cli [NPM]: 2.0.0-beta.20

[-] App
    - build-type: bundle
    - CSP: unset
    - frontendDist: ../src
    - bundler: Webpack

Permissions

{
  "identifier": "main-capability",
  "description": "Capability for the main window",
  "local": true,
  "windows": [
    "main"
  ],
  "permissions": [
    "store:allow-get",
    "store:allow-set",
    "store:allow-save",
    "store:allow-load",
    "path:default",
    "event:default",
    "window:default",
    "app:default",
    "resources:default",
    "menu:default",
    "dialog:default",
    "fs:default",
    "log:default",
    "websocket:default",
    "window-state:default",
    "window-state:allow-restore-state",
    "window:allow-show"
  ]
}
rtiagom commented 2 days ago

unload is not really recommended but the same issue applies to visibilitychange event