tauri-apps / tauri

Build smaller, faster, and more secure desktop and mobile applications with a web frontend.
https://tauri.app
Apache License 2.0
82.63k stars 2.48k forks source link

[bug] capture_screen question #6496

Open chongqiangchen opened 1 year ago

chongqiangchen commented 1 year ago

Describe the bug

Why can I only capture the desktop but not the contents of other windows when I use "let screenshot_path = capture_screen().unwrap();" in Tauri? Do I need to open any specific permissions?

Reproduction

No response

Expected behavior

No response

Platform and versions

Environment
  › OS: Mac OS 12.0.0 X64
  › Node.js: 14.20.0
  › npm: 6.14.17
  › pnpm: 7.13.6
  › yarn: 1.22.19
  › 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: ../out
  › devPath: http://localhost:3000/
  › framework: React (Next.js)
  › bundler: Webpack

App directory structure
  ├─ .husky
  ├─ out
  ├─ node_modules
  ├─ .next
  ├─ public
  ├─ .github
  ├─ src-tauri
  ├─ .git
  ├─ .idea
  └─ src

Stack trace

No response

Additional context

No response

IvanLi-CN commented 1 year ago

I think it's a permission issue. When you don't grant screen recording permission on Mac OS, it behaves as you described, only the current application and desktop background are captured, and even desktop files are not displayed.

chongqiangchen commented 1 year ago

I think it's a permission issue. When you don't grant screen recording permission on Mac OS, it behaves as you described, only the current application and desktop background are captured, and even desktop files are not displayed.

my guess is that it's also a permission issue, but it's just occasionally normal and occasionally abnormal during the development phase, which makes me a little confused.

FabianLars commented 1 year ago

Hey 👋 Which rust crate are you using to take screenshots here?

chongqiangchen commented 1 year ago

Hey 👋 Which rust crate are you using to take screenshots here? use std::process::Command;

fn capture_screen() -> Result<PathBuf, Box> { let screenshot_path = std::env::temp_dir().join("screenshot.png");

Command::new("screencapture")
    .arg("-i")
    .arg(screenshot_path.to_str().unwrap())
    .output()?;

Ok(screenshot_path)

}

chongqiangchen commented 1 year ago

I used it directly like this, do you have any other recommendations?

FabianLars commented 1 year ago

Ah alright. Then it really should be a permission issue as @IvanLi-CN said. Looks like there's a (user-side) setting in System Preferences -> Security & Privacy -> Privacy -> Screen Recording, source: https://discussions.apple.com/thread/251116945