tauri-apps / tauri

Build smaller, faster, and more secure desktop and mobile applications with a web frontend.
https://tauri.app
Apache License 2.0
83.67k stars 2.51k forks source link

[bug] event.listen not allowed on window main, webview main, allowed windows: , allowed webviews: , referenced by ~ #9230

Closed gusxodnjs closed 7 months ago

gusxodnjs commented 7 months ago

Describe the bug

There is a "main" window and I created an additional "google" webviewWindow. When the "google" window was loaded, the "emit_to" sent an event to the "main" window. However, the "main" window received the following error and did not receive the event. What additional settings should I apply? I recently upgraded from alpha version to beta, and I checked the document, but I'm not sure.

image

let _ = WebviewWindowBuilder::new(&_app_handle, "google", WebviewUrl::External(_url.parse().unwrap()))
            .parent(&m_webview).unwrap()
            .decorations(true)
            .resizable(true)
            .initialization_script(&_script)
            .on_page_load(move |window, payload| {
                match payload.event() {
                    PageLoadEvent::Started => {}
                    PageLoadEvent::Finished => {
                        window.get_webview_window("main").unwrap().emit_to(EventTarget::labeled("main"), "onready", payload.url()).unwrap();
                    }
                }
            })
            .build()
            .unwrap();
{
  "productName": "test",
  "version": "0.0.0",
  "identifier": "com.tauri.dev",
  "build": {
    "beforeDevCommand": "yarn dev",
    "devUrl": "http://localhost:1420",
    "beforeBuildCommand": "yarn build",
    "frontendDist": "../dist"
  },
  "app": {
    "withGlobalTauri": true,
    "windows": [
      {
        "title": "main",
        "label": "main",
        "width": 1200,
        "height": 800,
        "url": "http://localhost:3000"
      }
    ],
    "security": {
      "csp": null
    }
  },
  "bundle": {
    "active": true,
    "targets": "all",
    "icon": [
      "icons/32x32.png",
      "icons/128x128.png",
      "icons/128x128@2x.png",
      "icons/icon.icns",
      "icons/icon.ico"
    ]
  }
}
{
  "$schema": "../schemas/desktop-schema.json",
  "identifier": "default",
  "description": "Capability for the main window",
  "windows": ["main"],
  "permissions": [
    "path:default",
    "event:default",
    "window:default",
    "app:default",
    "image:default",
    "resources:default",
    "menu:default",
    "tray:default",
    "shell:allow-open",
    "event:allow-listen",
    "event:allow-emit-to"
  ]
}

Reproduction

No response

Expected behavior

No response

Full tauri info output

[✔] Environment
    - OS: Mac OS 13.5.2 X64
    ✔ Xcode Command Line Tools: installed
    ✔ rustc: 1.75.0 (82e1608df 2023-12-21)
    ✔ cargo: 1.75.0 (1d8b05cdd 2023-11-20)
    ✔ rustup: 1.26.0 (5af9b9484 2023-04-05)
    ✔ Rust toolchain: stable-aarch64-apple-darwin (default)
    - node: 18.16.0
    - pnpm: 8.6.10
    - yarn: 1.22.21
    - npm: 9.5.1

[-] Packages
    - tauri [RUST]: 2.0.0-beta.12
    - tauri-build [RUST]: 2.0.0-beta.10
    - wry [RUST]: 0.37.0
    - tao [RUST]: 0.26.1
    - tauri-cli [RUST]: 2.0.0-alpha.18
    - @tauri-apps/api [NPM]: 2.0.0-beta.6
    - @tauri-apps/cli [NPM]: 2.0.0-beta.10

[-] App
    - build-type: bundle
    - CSP: unset
    - frontendDist: ../dist
    - devUrl: http://localhost:1420/
    - framework: React
    - bundler: Vite

Stack trace

No response

Additional context

No response

wanghanzhen commented 6 months ago

why did you close this issue? I have the same.

gusxodnjs commented 6 months ago

@wanghanzhen I solved it by adding these settings. in /src-tauri/capabilities/default.json

"remote": {
  "urls": ["https://**"]
}