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

Creating multiple window forms exception [bug] #9152

Closed
LOWRUI opened this issue Mar 11, 2024 · 3 comments
Closed

Creating multiple window forms exception [bug] #9152

LOWRUI opened this issue Mar 11, 2024 · 3 comments
Labels
status: needs triage This issue needs to triage, applied to new issues type: bug

Comments

@LOWRUI
Copy link

LOWRUI commented Mar 11, 2024

Describe the bug

When I use new Window to create a new Windows form in JavaScript, the created form is blank. If I use WebviewWindow to create it, an error POST will be reported http://ipc.localhost/plugin%3Awebview%7Ccreate_webview_window 400 (Bad Request), I'm not sure if I missed something. Because I should have already configured the URL and src tauri/capabilities/main.json

When using WebviewWindow
image

When using Window
image

Reproduction

import { useState } from "react";
import reactLogo from "./assets/react.svg";
import { invoke } from "@tauri-apps/api/core";
import { WebviewWindow } from '@tauri-apps/api/webviewWindow'
import { Window } from '@tauri-apps/api/Window'
import "./App.css";

function App() {
  const [greetMsg, setGreetMsg] = useState("");
  const [name, setName] = useState("");

  async function greet() {
    // Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
    //setGreetMsg(await invoke("greet", { name }));
  }

  function create_windows(){
    
    const webview = new WebviewWindow('my-label', {
      url: 'https://tauri.app/'
    });
    webview.once('tauri://created', function () {
    // webview successfully created
    });
    webview.once('tauri://error', function (e) {
    // an error happened creating the webview
    });

    // const webview = new Window('my-label', {
    //   url: 'https://tauri.app/'
    // });
    // webview.once('tauri://created', function () {
    // // webview successfully created
    // });
    // webview.once('tauri://error', function (e) {
    // // an error happened creating the webview
    // });
}

  return (
    <div className="container">
      <h1>Welcome to Tauri!</h1>

      <div className="row">
        <a href="https://vitejs.dev" target="_blank">
          <img src="/vite.svg" className="logo vite" alt="Vite logo" />
        </a>
        <a href="https://tauri.app" target="_blank">
          <img src="/tauri.svg" className="logo tauri" alt="Tauri logo" />
        </a>
        <a href="https://reactjs.org" target="_blank">
          <img src={reactLogo} className="logo react" alt="React logo" />
        </a>
      </div>

      <p>Click on the Tauri, Vite, and React logos to learn more.</p>

      <form
        className="row"
        onSubmit={(e) => {
          e.preventDefault();
          create_windows();
        }}
      >
        <input
          id="greet-input"
          onChange={(e) => setName(e.currentTarget.value)}
          placeholder="Enter a name..."
        />
        <button type="submit">Greet</button>
      </form>

      <p>{greetMsg}</p>
    </div>
  );
}

export default App;

src-tauri/capabilities/main.json

{
  "$schema": "../gen/schemas/desktop-schema.json",
  "description": "Capability for the main window",
  "windows": [
    "main",
    "my-label"
  ],
  "identifier": "http:default",
  "allow": [
    { "url": "https://tauri.app/" }
  ],
  "permissions": [
    "path:default",
    "event:default",
    "window:default",
    "app:default",
    "resources:default",
    "menu:default",
    "tray:default",
    "window:allow-set-title",
    "window:allow-show",
    "window:allow-create"
  ]
}

Expected behavior

I hope to be able to create a new sub window form normally on 2.0

Full tauri info output

[✔] Environment
    - OS: Windows 10.0.22631 X64
    ✔ WebView2: 122.0.2365.80
    ✔ MSVC: 
        - Visual Studio Enterprise 2019
        - Visual Studio Enterprise 2022
    ✔ rustc: 1.76.0 (07dca489a 2024-02-04)
    ✔ cargo: 1.76.0 (c84b36747 2024-01-18)
    ✔ rustup: 1.26.0 (5af9b9484 2023-04-05)
    ✔ Rust toolchain: stable-x86_64-pc-windows-msvc (default)
    - node: 20.9.0
    - pnpm: 8.15.3
    - npm: 10.5.0

[-] Packages
    - tauri [RUST]: 2.0.0-beta.10
    - tauri-build [RUST]: 2.0.0-beta.8
    - wry [RUST]: 0.37.0
    - tao [RUST]: 0.26.1
    - tauri-cli [RUST]: 1.4.0
    - @tauri-apps/api [NPM]: 2.0.0-beta.4
    - @tauri-apps/cli [NPM]: 2.0.0-beta.8

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

Stack trace

No response

Additional context

No response

@LOWRUI LOWRUI added status: needs triage This issue needs to triage, applied to new issues type: bug labels Mar 11, 2024
@amrbashir
Copy link
Member

you're missing "webview:allow-create-webview-window" permission in your capability file.

@amrbashir amrbashir closed this as not planned Won't fix, can't repro, duplicate, stale Mar 11, 2024
@LOWRUI
Copy link
Author

LOWRUI commented Mar 12, 2024

"webview:allow-create-webview-window"您的功能文件中缺少权限。

Thank you, but I have discovered a new issue,When I was about to create it for the second time, "WebviewWindow. getByLabel ('my label ');" returned as "null"

[✔] Environment
    - OS: Windows 10.0.22631 X64
    ✔ WebView2: 122.0.2365.80
    ✔ MSVC: 
        - Visual Studio Enterprise 2019
        - Visual Studio Enterprise 2022
    ✔ rustc: 1.76.0 (07dca489a 2024-02-04)
    ✔ cargo: 1.76.0 (c84b36747 2024-01-18)
    ✔ rustup: 1.26.0 (5af9b9484 2023-04-05)
    ✔ Rust toolchain: stable-x86_64-pc-windows-msvc (default)
    - node: 20.9.0
    - pnpm: 8.15.3
    - npm: 10.5.0

[-] Packages
    - tauri [RUST]: 2.0.0-beta.11
    - tauri-build [RUST]: 2.0.0-beta.9
    - wry [RUST]: 0.37.0
    - tao [RUST]: 0.26.1
    - tauri-cli [RUST]: 1.4.0
    - @tauri-apps/api [NPM]: 2.0.0-beta.5
    - @tauri-apps/cli [NPM]: 2.0.0-beta.9

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

image

@amrbashir
Copy link
Member

sounds like duplicate of #5380

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