Skip to content

[bug] Can't immediately access to the created window by WebviewWindow.getByLabel #5191

@shimarulin

Description

@shimarulin

Describe the bug

Can't immediately access to the created window by WebviewWindow.getByLabel in event listener (tauri://window-created).

Reproduction

  1. Add a tauri://window-created event listener on the current application window:
    void listen('tauri://window-created', (event: Event<{label: string}>) => {
      const createdWindow = WebviewWindow.getByLabel(event.payload.label)
      console.log(createdWindow)
      if (createdWindow !== null) {
        onCreateWindow(createdWindow)
      }
    })
  2. Open DevTools Console in the current application window by Ctrl+Shift+I
  3. Create new window (in my case by JS API)
  4. DevTools Console in the current application window output null

Expected behavior

  1. DevTools Console in the current application window output WebviewWindow object

Platform and versions

❯ yarn tauri info

Environment
› OS: Arch Linux Unknown X64
› Node.js: 18.8.0
› npm: 8.18.0
› pnpm: Not installed!
› yarn: 3.2.2
› rustup: 1.24.3
› rustc: 1.59.0
› cargo: 1.59.0
› Rust toolchain: stable-x86_64-unknown-linux-gnu

Packages
WARNING: no lock files found, defaulting to npm
› @tauri-apps/cli [NPM]: 1.0.5
› @tauri-apps/api [NPM]: 1.0.2
› tauri [RUST]: 1.0.5,
› tauri-build [RUST]: 1.0.4,
› tao [RUST]: 0.12.2,
› wry [RUST]: 0.19.0,

App
› build-type: bundle
› CSP: unset
› distDir: ../dist
› devPath: http://localhost:1420/
› framework: Vue.js

App directory structure
├─ src
├─ src-tauri
├─ .vscode
├─ public
├─ node_modules
├─ dist
├─ settings
└─ about

Stack trace

No response

Additional context

Current workaround:

  void listen('tauri://window-created', (event: Event<{label: string}>) => {
    // Can't immediately access to the created window by `WebviewWindow.getByLabel`
    setTimeout(() => {
      const createdWindow = WebviewWindow.getByLabel(event.payload.label)
      if (createdWindow !== null) {
        onCreateWindow(createdWindow)
      }
    }, 100)
  })

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions