Skip to content

Tauri spawns multiple windows with app.create_window() in certain situations #2284

@woubuc

Description

@woubuc

Describe the bug

If no window is added in the config file, but a window is created through app.create_window(), if the Javascript code in that window imports @tauri-apps/api then Tauri will incorrectly spawn a second window pointing to index.html (the default). This happens both in dev and in release builds.

To Reproduce

Steps to reproduce the behavior:

  1. Create a Tauri project with API
  2. Add a frontend page with a Javascript module that contains an import * as Tauri from '@tauri-apps/api';
  3. Remove all windows from the config file ("windows": [],)
  4. Create a window in the app setup with a label that isn't main, that loads the frontend page with the api import:
app.create_window(
    "test".into(),
    WindowUrl::App("test".into()),
    |builder, attrs| (builder, attrs)
).expect("Could not create window");
  1. Run the app
  2. It will spawn the created window and then quickly after it will spawn a second window pointing to the index page of the frontend app

I've reduced my test project to the minimal code that reproduces the error: woubuc/tauri-double-windows-repro.

Expected behavior

I expect that only 1 window opens after 1 call to app.create_window().

Platform and Versions (required):

Operating System - Windows, version 10.0.19042 X64
Webview2 - 91.0.864.71

Node.js environment
  Node.js - 14.16.0
  @tauri-apps/cli - 1.0.0-beta.6
  @tauri-apps/api - 1.0.0-beta.5

Global packages
  npm - 6.14.11
  yarn - 1.22.4

Rust environment
  rustc - 1.53.0
  cargo - 1.53.0

App directory structure
/.git
/.idea
/.nuxt
/assets
/components
/dist
/i18n
/layouts
/node_modules
/pages
/src-tauri
/static
/types

App
  tauri.rs - 1.0.0-beta.5
  build-type - bundle
  CSP - default-src blob: data: filesystem: ws: wss: http: https: tauri: 'unsa
fe-eval' 'unsafe-inline' 'self' img-src: 'self'
  distDir - ../dist
  devPath - http://localhost:3000
  framework - Vue.js (Nuxt)
  bundler - Webpack

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