How to Solve"OT_MEDIA_ERR_ABORTED" Error When Sharing Screens How to Solve"OT_MEDIA_ERR_ABORTED" Error When Sharing Screens

How to Solve"OT_MEDIA_ERR_ABORTED" Error When Sharing Screens

Vonage API Support

Symptom

When attempting to share a screen in Safari or Firefox, users may sometimes receive the following error message: 

{"code":1500,"message":"Unknown error while getting user media: InvalidAccessError","name":"OT_MEDIA_ERR_ABORTED","stack":"errorFromVendorNameAndMessage@https://localhost:9090/js/chunk-vendors.js:109328:24\nparseErrorEvent@https://localhost:9090/js/chunk-vendors.js:109362:50\n@https://localhost:9090/js/chunk-vendors.js:109472:36\npromiseReactionJob@[native code]"}

Applies To

  • Video API
  • Screen sharing

Resolution

To resolve "InvalidAccessError","name":"OT_MEDIA_ERR_ABORTED" error when trying to share a screen,

Update the code so that the "initPublisher" method is triggered by a user gesture, such as a click event. 

This is because our SDK uses the "getDisplayMedia" method for screen sharing, and in Safari, calling "getDisplayMedia" using a promise outside of a user gesture context will result in an InvalidAccessError.

Example

function initpublisher() {
  OT.initPublisher('publisher', {
    videoSource: "screen"
  }, (err) => {
    if (err) {
      console.warn(err);
    } else {
  alert('check console - no errors');
    }
  });
}

// This will fail, initpublisher() is called outside of any user interaction or gesture event listener, which will result in an InvalidAccessError because the browser requires a user gesture to access the screen capture feature.
initpublisher() ;

async function userHandler() {
// This will work without throwing an error because it is being called in response to a user gesture (click, double-click, tap, key-press ..)
initpublisher();
}

document.querySelector('#user-gestured').onclick = userHandler;

In the corresponding html file, added a button for the user to click.

<head>
<script src="https://static.opentok.com/v2/js/opentok.min.js"></script>
</head>

<button id="user-gestured">
Some sort of user gesture
</button>

Cause

The "OT_MEDIA_ERR_ABORTED" error occurs when the "initPublisher" method is not triggered by a user gesture. This is because our SDK uses the "getDisplayMedia" method for screen sharing, and in Safari, calling "getDisplayMedia" using a promise outside of a user gesture context will result in an InvalidAccessError.

Additional information