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

[bug] Tauri API not injected into local web server #4449

Closed
cup-dev opened this issue Jun 23, 2022 · 1 comment
Closed

[bug] Tauri API not injected into local web server #4449

cup-dev opened this issue Jun 23, 2022 · 1 comment

Comments

@cup-dev
Copy link

cup-dev commented Jun 23, 2022

Describe the bug

My app requires spawning a local web server at http://localhost:8080 to function (both for development and production).

Despite setting http://localhost:8080 as the distDir, devPath, and main window URL, the tauri context is not injected when the window is open (i.e. window.__TAURI__ is undefined).

Reproduction

See minimal repro and steps here: https://github.com/cup-dev/tauri-webserver-issue

Expected behavior

I would expect an ability to spawn a local web server as part of my Tauri app and have the Tauri context available within.

Platform and versions

Environment
  › OS: Mac OS 12.4.0 X64
  › Node.js: 16.15.0
  › npm: 8.5.5
  › pnpm: Not installed!
  › yarn: Not installed!
  › rustup: 1.24.3
  › rustc: 1.59.0
  › cargo: 1.59.0
  › Rust toolchain: stable-aarch64-apple-darwin

Packages
  › @tauri-apps/cli [NPM]: 1.0.0
  › @tauri-apps/api [NPM]: 1.0.1
  › tauri [RUST]: 1.0.0,
  › tauri-build [RUST]: 1.0.0,
  › tao [RUST]: 0.11.2,
  › wry [RUST]: 0.18.3,

App
  › build-type: bundle
  › CSP: unset
  › distDir: http://localhost:8080/
  › devPath: http://localhost:8080/

App directory structure
  ├─ dist
  ├─ node_modules
  ├─ src-tauri
  ├─ site
  └─ .git

Stack trace

No response

Additional context

No response

@JonasKruckenberg
Copy link
Contributor

Tauri cannot really do this, we can't inject APIs into apps we don't control/own (doing so would require us to inject code into safari, chrome, firefox etc.).
The Tauri APIs are only available in windows created by Tauri. This is both a feature and fact of life.

(Setting the distDir option to anything else than a local path will not work either)

We do offer a workaround for this though: https://github.com/tauri-apps/tauri-invoke-http
It spawns a localhost server from Rust that can interface with the command system. You can then use fetch to issue commands.
That said it's not very polished or documented yet.

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

2 participants