Bug 248964

Summary: Screen share does not work when pass width & height for the video constraint in "getDisplayMedia"
Product: WebKit Reporter: Maksim Ryzhikov <rv.maksim>
Component: WebRTCAssignee: Nobody <webkit-unassigned>
Status: RESOLVED DUPLICATE    
Severity: Critical CC: eric.carlson, jer.noble, ltsg0317, ralphbliu, youennf
Priority: P2    
Version: Safari 16   
Hardware: Mac (Apple Silicon)   
OS: macOS 13   

Description Maksim Ryzhikov 2022-12-08 11:29:40 PST
Demo source: https://codesandbox.io/s/a-mediastreamtrack-ended-due-to-a-capture-failure-mxrpxc?file=/src/index.js
Demo url: https://mxrpxc.csb.app


Steps to reproduce (A):
- Open "Demo url"
- Press "Share screen" button
- "Allow to share screen"

Expected result: video tag display screen
Actual result: Exception "A MediaStreamTrack ended due to a capture failure"


Steps to reproduce (B):
- Open "Demo url"
- Press "Share screen" button
- "Allow to share window"

Expected result: video tag display window stream
Actual result: nothing


Source code (for history):

```javascript
function main() {
  console.clear();

  const video = document.createElement("video");
  video.autoplay = true;
  video.width = 250;
  video.style.display = "block";
  video.style.border = "1px solid red";

  const button = document.createElement("button");
  button.innerText = "Share screen!";
  button.onclick = async () => {
    const stream = await navigator.mediaDevices.getDisplayMedia({
      video: {
        width: 100,
        height: 100
      }
    });
    video.srcObject = stream;
  };
  document.body.append(video);
  document.body.append(button);
}

main();

```
Comment 1 Maksim Ryzhikov 2022-12-08 11:33:47 PST
I have built WebKit from the main branch but problem still present :(
Comment 2 youenn fablet 2022-12-09 02:17:19 PST
This is probably fixed in https://bugs.webkit.org/show_bug.cgi?id=247310.
I cannot reproduce the issue in mini browser.
Comment 3 youenn fablet 2022-12-09 02:44:14 PST

*** This bug has been marked as a duplicate of bug 247310 ***
Comment 4 Brian Liu 2023-01-09 20:42:16 PST
See the solution https://stackoverflow.com/a/75065525/4796724
Comment 5 Maksim Ryzhikov 2023-01-10 01:11:48 PST
(In reply to Brian Liu from comment #4)
> See the solution https://stackoverflow.com/a/75065525/4796724

Thanks, but this is not a solution. This is the one of possible workarounds which may or may not suite.
Comment 6 Maksim Ryzhikov 2023-01-10 01:12:30 PST
(In reply to Brian Liu from comment #4)
> See the solution https://stackoverflow.com/a/75065525/4796724

Thanks, but this is not a solution. This is the one of possible workarounds which may or may not suite.
Comment 7 shuming 2023-03-02 01:44:06 PST
(In reply to Brian Liu from comment #4)
> See the solution https://stackoverflow.com/a/75065525/4796724

Even though it can be called, there is still no limit to the collection resolution, so far the collection is always 1080, my version is Safari16.3.
Has anyone else been in this situation?