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

getDisplayMedia returning undefined in macos. #2338

Closed
b4s36t4 opened this issue Aug 2, 2021 · 9 comments
Closed

getDisplayMedia returning undefined in macos. #2338

b4s36t4 opened this issue Aug 2, 2021 · 9 comments

Comments

@b4s36t4
Copy link

b4s36t4 commented Aug 2, 2021

I've trying to get the screen recording of my system through the tauri, but When I navigator doesn't even have the MediaDevices object.

Can anyone please help me to get the screen in macos?

Any ideas to implement feature like 'desktopCapturer' in electron?

@nothingismagick
Copy link
Member

Please follow the issue template and provide all information.

@lemarier
Copy link
Member

lemarier commented Aug 8, 2021

May we know your os?

I suspect macos so i’ll give a quick hint;
This is a security thing (specially in dev build, as you need a custom plist to the app)

add this in your Cargo.toml under dependencies;

embed_plist = "1.2.0"

add this is to the top of your main.rs

#[cfg(debug_assertions)]
#[cfg(target_os = "macos")]
embed_plist::embed_info_plist!("../Info.plist");

Then create a sample plist in the root of src-tauri (This will ask permission to access your camera and microphone.)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>NSCameraUsageDescription</key>
	<string>Request camera access for WebRTC</string>
	<key>NSMicrophoneUsageDescription</key>
	<string>Request microphone access for WebRTC</string>
</dict>
</plist>

Then all should works as supposed


For release build you need a custom plist.

@b4s36t4
Copy link
Author

b4s36t4 commented Aug 8, 2021

Thanks @lemarier. Will check it.!

@lucasfernog
Copy link
Member

We need to document this or maybe help users define their plist file.

@lemarier
Copy link
Member

lemarier commented Aug 8, 2021

We need to document this or maybe help users define their plist file.

ref; #1570

@devwolf75
Copy link

I've trying to get the screen recording of my system through the tauri, but When I navigator doesn't even have the MediaDevices object.

Can anyone please help me to get the screen in macos?

Any ideas to implement feature like 'desktopCapturer' in electron?

I wrote an Electron App that captures video from a USB capture card. I am currently in the process of porting it to Tauri. But still having issues and getting the grasp of when to use rust and js. I am a full JS dev.
Capture-Card-Viewer

I based the idea off Firship's 10 minute electron project on youtube. You can use the example from there.
Electron Screen Recorder

@cliqer
Copy link

cliqer commented Jul 23, 2022

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>NSCameraUsageDescription</key>
	<string>Request camera access for WebRTC</string>
	<key>NSMicrophoneUsageDescription</key>
	<string>Request microphone access for WebRTC</string>
</dict>
</plist>

This does not work for me and it throws the following error:

   --> src/main.rs:159:14
    |
159 |         .run(tauri::generate_context!())
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: this error originates in the macro `$crate::embed_info_plist_bytes` which comes from the expansion of the macro `tauri::generate_context` (in Nightly builds, run with -Z macro-backtrace for more info)

any solutions?

@cliqer
Copy link

cliqer commented Jul 23, 2022

So it seems that after creating an Info.plist on the src-tauri folder it gets implemented automatically.
Any *.entitlements files are not getting imported though when added to the configuration file:
Release.entitlements

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>com.apple.security.app-sandbox</key>
    <false/>
    <key>com.apple.security.cs.allow-jit</key>
    <true/>
    <key>com.apple.security.cs.allow-unsigned-executable-memory</key>
    <true/>
    <key>com.apple.security.cs.disable-library-validation</key>
    <true/>
    <key>com.apple.security.cs.allow-dyld-environment-variables</key>
    <true/>
    <key>com.apple.security.automation.apple-events</key>
    <true/>
    <key>com.apple.security.device.usb</key>
    <true/>
    <key>com.apple.security.device.camera</key>
    <true/>
    <key>com.apple.security.network.server</key>
    <true/>
    <key>com.apple.security.network.client</key>
    <true/>
  </dict>
</plist>

tauri.conf.json

  "tauri": {
    "bundle": {
      "macOS": {
        "entitlements": "Release.entitlements",
      }
   }

and when trying to use something like:

    await navigator.mediaDevices.getDisplayMedia({
      audio: false,
      video: true
    })
      .then(stream => console.log(stream))
      .catch(e => console.log(e));

on webkit returns:

NotAllowedError: The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission.

and on the server:

+++     0x600000440540  0       1       341697610581666

as such, there is no way to capture the screen.
This seems to be a Wry problem not being able to display the screen selection dialogue.
It works on latest safari.

@raksa
Copy link

raksa commented Jul 23, 2023

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>NSCameraUsageDescription</key>
	<string>Request camera access for WebRTC</string>
	<key>NSMicrophoneUsageDescription</key>
	<string>Request microphone access for WebRTC</string>
</dict>
</plist>

This does not work for me and it throws the following error:

   --> src/main.rs:159:14
    |
159 |         .run(tauri::generate_context!())
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: this error originates in the macro `$crate::embed_info_plist_bytes` which comes from the expansion of the macro `tauri::generate_context` (in Nightly builds, run with -Z macro-backtrace for more info)

any solutions?

Remove below 3 lines from main.rs should work

#[cfg(debug_assertions)]
#[cfg(target_os = "macos")]
embed_plist::embed_info_plist!("../Info.plist");

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

No branches or pull requests

7 participants