tauri-apps / tauri-apps/plugins-workspace

handling of websocket on webview reload

Open
#1,507 3 comments 3 reactions 0 assignees View on GitHub
plugin: websocket type: question
Dominant language
Rust
Stars
1.8k
Forks
602
Avg merge
4d 14h
Merged PRs (30d)
9

Description

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"
]
}
```

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.