tauri-apps / tauri

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

[bug] cannot create webview tauri 2 #10518

Open LeoMartinDev opened 2 months ago

LeoMartinDev commented 2 months ago

Describe the bug

I'm trying to create a webview inside my current WebviewWindow using javascript. It fails with the following error: Failed to load resource: the server responded with a status of 400 (Bad Request)

Reproduction

pnpm create tauri-app --rc

Update permissions:

{
  "$schema": "../gen/schemas/desktop-schema.json",
  "identifier": "default",
  "description": "Capability for the main window",
  "windows": ["main"],
  "permissions": [
    "shell:allow-open",
    "core:webview:allow-create-webview-window",
    "core:webview:allow-create-webview",
    "core:webview:allow-reparent",
    "core:webview:default",
    "core:webview:allow-set-webview-position",
    "core:webview:allow-set-webview-size",
    "core:window:allow-create",
    "core:window:default",
    "core:app:default"
  ]
}

Run the following javascript:

import { Webview, getCurrentWebview } from "@tauri-apps/api/webview";
import { Window } from "@tauri-apps/api/window";

  const window = Window.getCurrent();
  const webview = new Webview(window, 'main2', {
    x: 0,
    y: 0,
    width: 200,
    height: 200,
  });

  webview.once("tauri://created", () => {
    console.log("webview created");
  });

Expected behavior

I would expect a new Webview to be embedded in my window

Full tauri info output

[✔] Environment
    - OS: Mac OS 14.5.0 X64
    ✔ Xcode Command Line Tools: installed
    ✔ rustc: 1.80.0 (051478957 2024-07-21)
    ✔ cargo: 1.80.0 (376290515 2024-07-16)
    ✔ rustup: 1.27.1 (54dd3d00f 2024-04-24)
    ✔ Rust toolchain: stable-aarch64-apple-darwin (default)
    - node: 20.13.1
    - pnpm: 9.7.0
    - npm: 10.5.2
    - bun: 1.1.18

[-] Packages
    - tauri [RUST]: 2.0.0-rc.0
    - tauri-build [RUST]: 2.0.0-rc.0
    - wry [RUST]: 0.41.0
    - tao [RUST]: 0.28.1
    - @tauri-apps/api [NPM]: 2.0.0-rc.0
    - @tauri-apps/cli [NPM]: 2.0.0-rc.1

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

Stack trace

No response

Additional context

No response

FabianLars commented 2 months ago

Did you enable the unstable feature flag on the tauri dep in Cargo.toml? By default multiple webview support is not enabled.

LeoMartinDev commented 2 months ago

Yes I did

LeoMartinDev commented 2 months ago

It works using the rust api but not with the javascript :(