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
- Similar WebKit error https://bugs.webkit.org/show_bug.cgi?id=251906
- Js fiddle: https://jsfiddle.net/hatvd6mk/
Related to:
Articles in this section
- How to use Completion handler for Exception Handling
- Firefox Pre-call test not supported
- Error Creating Session Using Vonage Video API .NET SDK
- Unable to Create Session Even Though API Key and Secret Are Valid
- HTTP 415 Error When Archiving Video Session
- Troubleshooting Invalid JWT When Creating a Video Session using REST API
- Camara Still in Use after Session Disconnect on Android
- Token Shows as Invalid
- HTTP 400 Error When Archiving Video Session
- 1541 Timed out while attempting to publish Error