tauri icon indicating copy to clipboard operation
tauri copied to clipboard

[bug] use `enigo` in tauri cause app crashed

Open jackeydou opened this issue 2 years ago • 11 comments
trafficstars

Describe the bug

I try to use enigo to do some keyboard event mock in my tauri app, and it will crash when the macOS api TISCopyCurrentKeyboardInputSource or TISGetInputSourceProperty execute in enigo.

I start an issue in enigo before, but we found the crash will only appear in my Tauri app.

Reproduction

  1. register a shortcut
import { isRegistered, register, unregister } from '@tauri-apps/api/globalShortcut';
export async function registerShortcut(shortcut: string, callback: (shortcut?: string) => void) {
  await register(shortcut, (shortcut) => {
    callback(shortcut);
  });
}

and there is a log in shell:

register Accelerator { id: Some(AcceleratorId(29420)), mods: ALT, key: KeyS }
  1. write a tauri command, and invoke in javascript
#[tauri::command]
async fn paste_content(window: tauri::Window) {
    let mut enigo = Enigo::new();
    let trusted = accessibility::query_accessibility_permissions();
    if trusted {
        enigo.key_down(Key::Meta);
        enigo.key_click(Key::Layout('v'));
        enigo.key_up(Key::Meta);

    }
}
invoke("paste_content").then(async _ => {
        
 })

I use accessibility to help me request the macOS accessibility permission, and it returns true. 3. the application crashed

Expected behavior

The app does not crash.

Platform and versions

Environment
  › OS: Mac OS 13.0.0 X64
  › Node.js: 16.14.0
  › npm: 8.3.1
  › pnpm: 7.9.5
  › yarn: 3.1.1
  › rustup: 1.25.2
  › rustc: 1.68.0
  › cargo: 1.68.0
  › Rust toolchain: stable-aarch64-apple-darwin 

Packages
  › @tauri-apps/cli [NPM]: 1.2.3
  › @tauri-apps/api [NPM]: 1.2.0
  › tauri [RUST]: 1.2.4,
  › tauri-build [RUST]: 1.2.1,
  › tao [RUST]: 0.15.8,
  › wry [RUST]: 0.23.4,

App
  › build-type: bundle
  › CSP: unset
  › distDir: ../dist
  › devPath: http://localhost:1420/
  › framework: React
  › bundler: Vite

App directory structure
  ├─ dist
  ├─ node_modules
  ├─ public
  ├─ .github
  ├─ src-tauri
  ├─ api
  ├─ .git
  ├─ .vscode
  ├─ assets
  └─ src

Stack trace

There is no output in my shell when it crashed, I try to debug it and set some breakpoints, I put the screenshots [here](https://github.com/enigo-rs/enigo/pull/161#issuecomment-1460236620)

Additional context

No response

jackeydou avatar Mar 11 '23 01:03 jackeydou

I have encountered the same problem and it is very troubling.

yetone avatar Mar 12 '23 11:03 yetone

I have encountered the same problem and it is very troubling.

Did you find the cause of the crash and how did you fix it?

jackeydou avatar Mar 17 '23 14:03 jackeydou

Have the same problem, though the app doesn't crash in my case

garrrikkotua avatar Apr 13 '23 15:04 garrrikkotua

@zeenix @amrbashir could you please take a look? 🙏

garrrikkotua avatar Apr 13 '23 20:04 garrrikkotua

@garrrikkotua why me? I don't even know what enigo is.

zeenix avatar Apr 13 '23 21:04 zeenix

@garrrikkotua why me? I don't even know what enigo is.

Apologies, it was a suggestion from GitHub 😅

garrrikkotua avatar Apr 13 '23 21:04 garrrikkotua

I don't have access to a mac unfortunately so I can't triage this issue.

amrbashir avatar Apr 14 '23 00:04 amrbashir

This is going to sound a bit strange, but try disabling spellcheck in the HTML.

<html spellcheck="false">
    <!-- ... -->
</html>

About a year ago this was causing WebKit to crash in our MacOS variant.

parker-codes avatar May 03 '23 16:05 parker-codes

A user tried it out and the problem persisted

pentamassiv avatar Jun 03 '23 20:06 pentamassiv

@pentamassiv Is there an update on this. I notice app exists without any error code. Disabeling spellchecker does not help.

uwejan avatar Jun 18 '23 15:06 uwejan

No, sorry I have not looked into it. I am not familiar at all with tauri

pentamassiv avatar Jun 18 '23 15:06 pentamassiv