#Unhandled Promise Rejection: webview not found: invalid label or it was closed

3 messages · Page 1 of 1 (latest)

fallen hare
#

This error appeared in webview's console.
Why is this error appearing and how to solve it?

In my real app, I want to the button be shown if and only if the new window is not opened.
I managed to do that with onCloseRequested, but met this issue.

minimal reproduction:

  1. pnpm create tauri-app
  2. add "window": { "all": true } in allowlist in tauri in tauri.conf.json
  3. add below in App.tsx
import { WebviewWindow } from "@tauri-apps/api/window";
<input
  type="button"
  onClick={() => {
    const wv = new WebviewWindow("a", { url: "../index.html" });
    wv.onCloseRequested(() => {});
  }}
  value="new"
/>
  1. pnpm tauri dev
  2. click the button above, a window will appear
  3. close the new window, the error message appears in the main window's console

pnpm tauri info

[✔] Environment
    - OS: EndeavourOS Rolling Release X64
    ✔ webkit2gtk-4.0: 2.42.4
    ✔ rsvg2: 2.57.1
    ✔ rustc: 1.75.0 (82e1608df 2023-12-21)
    ✔ cargo: 1.75.0 (1d8b05cdd 2023-11-20)
    ✔ rustup: 1.26.0 (2023-11-14)
    ✔ Rust toolchain: stable-x86_64-unknown-linux-gnu (default)
    - node: 21.6.0
    - pnpm: 8.14.1
    - npm: 10.3.0

[-] Packages
    - tauri [RUST]: 1.5.4
    - tauri-build [RUST]: 1.5.1
    - wry [RUST]: 0.24.7
    - tao [RUST]: 0.16.6
    - @tauri-apps/api [NPM]: 1.5.3
    - @tauri-apps/cli [NPM]: 1.5.9

[-] App
    - build-type: bundle
    - CSP: unset
    - distDir: ../dist
    - devPath: http://localhost:1420/
    - framework: React
    - bundler: Vite
proper steeple
#

does the error actually cause falsy behavior here though? Cause if it works for your usecase but just prints that error without actual consequences i'd just suggest to live with that until v2 comes (iirc we can't fix the linked issue in v1). Or maybe adding some .catch(() => {}) can get rid of it.