Skip to content

[bug] Event payload sent between frontends does not get parsed into an object #5482

@ghost

Description

Describe the bug

I have two Tauri windows communicating with each other via events on the frontend. I would like to send an object from one window to another. From my understanding, the serialized JSON should be parsed automatically on the receiving end, but instead I'm getting the string representation. This does not seem to be intended behavior.

Possibly related: #2929

Reproduction

In the main window:

type Message = { message: string };

const secondWindow = new WebviewWindow("secondWindow", { /* ... */ });

secondWindow.listen<Message>("message-sent", (e) => console.log(e.payload.message)); // ERROR: `e.payload` is a string

In the secondary window:

const mainWindow = WebviewWindow.getByLabel("main");

mainWindow?.emit("message-sent", { message: "Hello from other window!" });

Expected behavior

e.payload should be an object instead of a string.

Platform and versions

Environment
  › OS: Windows 10.0.22621 X64
  › Webview2: 106.0.1370.52
  › MSVC: 
      - Visual Studio Build Tools 2022
  › Node.js: 16.17.1
  › npm: 8.15.0
  › pnpm: Not installed!
  › yarn: Not installed!
  › rustup: 1.25.1
  › rustc: 1.64.0
  › cargo: 1.64.0
  › Rust toolchain: stable-x86_64-pc-windows-msvc 

Packages
  › @tauri-apps/cli [NPM]: 1.1.1
  › @tauri-apps/api [NPM]: 1.1.0
  › tauri [RUST]: 1.1.1,
  › tauri-build [RUST]: 1.1.1,
  › tao [RUST]: 0.14.0,
  › wry [RUST]: 0.21.1,

App
  › build-type: bundle
  › CSP: unset
  › distDir: ../build
  › devPath: http://localhost:5173/
  › framework: Svelte

App directory structure
  ├─ .git
  ├─ .svelte-kit
  ├─ build
  ├─ node_modules
  ├─ src
  ├─ src-tauri
  └─ static

Stack trace

No response

Additional context

No response

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