Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
shimarulin opened this issue Sep 14, 2022 · 1 comment
Labels
status: needs triage This issue needs to triage, applied to new issues type: bug

Comments

@shimarulin
Copy link

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)
  })
@shimarulin shimarulin added status: needs triage This issue needs to triage, applied to new issues type: bug labels Sep 14, 2022
@amrbashir
Copy link
Member

that is expected because the state of the current window hasn't been updated yet, maybe we can provide a way to skip checking the state, like

WebviewWindow.getByLabelUnchecked(event.payload.label)

or

WebviewWindow.getByLabel(event.payload.label, { skip: true })

lucasfernog added a commit that referenced this issue Oct 21, 2022


Tauri fires event listeners in reverse order, so our own tauri://window-created listener is the last to execute. This commit changes the listen JS code to keep our own listener as the last one in the array, so the metadata is updated before user code is executed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs triage This issue needs to triage, applied to new issues type: bug
Projects
None yet
Development

No branches or pull requests

2 participants