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

Uniqueness of WebviewWindow label should be enforced #2067

Closed
BenoitRanque opened this issue Jun 24, 2021 · 2 comments
Closed

Uniqueness of WebviewWindow label should be enforced #2067

BenoitRanque opened this issue Jun 24, 2021 · 2 comments

Comments

@BenoitRanque
Copy link
Contributor

BenoitRanque commented Jun 24, 2021

Describe the bug
It is currently possible to create multiple instances of WebviewWindow with the same label.
This could lead to undefined behavior when we consider that WebviewWindow.getByLabel() returns a single handle.
Alternatively, WebviewWindow.getByLabel() could be changed to return an array if there are multiple windows with that label.

To Reproduce
Steps to reproduce the behavior:
Within a tauri app, execute the following js:

import { getCurrent, WebviewWindow } from '@tauri-apps/api/window';

async function testFunction() {
      const label = 'testlabel' // the label that will be shared between multiple windows
      const webview1 = new WebviewWindow(label);
      const webview2 = new WebviewWindow(label);
      // we now have two webviews with the same label.
}

Expected behavior
The WebviewWindow constructor should throw an error if the label is duplicated.
Alternatively, if we decide to allow duplicated labels, WebviewWindow.getByLabel() should return an array.

Platform and Versions (please complete the following information):
Operating System - Windows, version 10.0.19042 X64
Webview2 - 91.0.864.54

Node.js environment
Node.js - 14.16.1
@tauri-apps/cli - 1.0.0-beta.3
@tauri-apps/api - 1.0.0-beta.2

Global packages
npm - 6.14.12
yarn - 1.22.10

Rust environment
rustc - 1.53.0
cargo - 1.53.0

Additional context
Allowing duplicate labels would permit that the label be a description of the window's role (eg. main, auxiliary, print_preview)
Disallowing duplicate labels ensures a unique window identifier.

Currently we can achieve the best of both worlds by using a patterns such as <role>:<id> so I think it is best we simply enforce uniqueness.

@ultravires
Copy link

BUG:
But parent window can not getAll().

**To Reproduce: **
A.js

const openFacePanel = (event) => {
      console.log(getAll()); // **always [`main`]**
      const emojiPanel = WebviewWindow.getByLabel('emojiPanel');
      console.log(emojiPanel); // **always null**
      if (emojiPanel) {
        emojiPanel.show();
        return;
      }
      const webview = new WebviewWindow('emojiPanel', {
        url: '/src/views/emoji/emoji.html',
        decorations: false,
        width: 420,
        height: 280,
        x: event.screenX - 210,
        y: event.screenY - 310,
        visible: false
      });
      webview.once('tauri://created', () => {});
      webview.once('tauri://error', (error) => {
        console.log(error);
      });
      webview.listen('tauri://blur', () => {
        // webview.hide();
        refEditor.value.quill.focus();
      });
    };

what should i do?

@lucasfernog
Copy link
Member

@ultravires I cannot reproduce this issue with the API example. Please file a dedicated issue with an app we can use to reproduce it, and also share the tauri info output (ensure you're using latest tauri releases).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants