هذه هي الطريقة القديمة. الرجاء استخدام أحدث navigator.mediaDevices.getUserMedia() بدلا من ذلك. بينما من الناحية الفنية لا مستنكر، ويتميز هذا الإصدار القديم رد على هذا النحو، منذ مواصفات تشجع بشدة باستخدام الوعد أحدث نسخة عودته.

This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.

على Navigator.getUserMedia() طريقة يطالب المستخدم للحصول على إذن لاستخدام ما يصل إلى جهاز إدخال فيديو واحد (مثل الكاميرا أو الشاشة المشتركة) وحتى جهاز واحد إدخال الصوت (مثل ميكروفون). إذا تم منح الإذن، ولتدفق الوسائط الذين الفيديو و / أو المسارات الصوتية تأتي من تلك الأجهزة يتم تسليمها إلى الاستدعاء نجاح المحدد. إذا تم رفض الإذن، لا أجهزة الإدخال متوافقة موجودة، أو حدوث أي حالة خطأ أخرى، يتم تنفيذ الاستدعاء الخطأ مع MediaStreamError وجوه واصفا ما حدث من خطأ. إذا كان المستخدم بدلا من ذلك لا يجعل خيارا على الإطلاق، لا يتم تنفيذ الاستدعاء.

بناء الجملة

navigator.getUserMedia ( القيود ، successCallback ، errorCallback


A MediaStreamConstraints object specifying the types of media to request, along with any requirements for each type. For details, see the constraints section under the modern MediaDevices.getUserMedia() method, as well as the article Capabilities, constraints, and settings.
A function which is invoked when the request for media access is approved. The function is called with one parameter: the MediaStream object that contains the media stream. Your callback can then assign the stream to the desired object (such as an <audio> or <video> element), as shown in the following example:
function(stream) {
   var video = document.querySelector('video');
   video.srcObject = stream;
   video.onloadedmetadata = function(e) {
      // Do something with the video here.
When the call fails, the function specified in the errorCallback is invokedwith a MediaStreamError object as its sole argument; this object is is modeled on DOMException. See {anch("Errors")}} below for a list of the errors which can occur.

Return value




Width and height

Here's an example of using getUserMedia(), including code to cope with various browsers' prefixes. Note that this is the deprecated way of doing it: See the Examples section under the MediaDevices.getUserMedia() for modern examples.

navigator.getUserMedia = navigator.getUserMedia ||
                         navigator.webkitGetUserMedia ||

if (navigator.getUserMedia) {
   navigator.getUserMedia({ audio: true, video: { width: 1280, height: 720 } },
      function(stream) {
         var video = document.querySelector('video');
         video.srcObject = stream;
         video.onloadedmetadata = function(e) {
      function(err) {
         console.log("The following error occurred: " +;
} else {
   console.log("getUserMedia not supported");


To use getUserMedia() in an installable app (for example, a Firefox OS app), you need to specify one or both of the following fields inside your manifest file:

"permissions": {
  "audio-capture": {
    "description": "Required to capture audio using getUserMedia()"
  "video-capture": {
    "description": "Required to capture video using getUserMedia()"

See permission: audio-capture and permission: video-capture for more information.


Specification Status Comment
Media Capture and Streams
The definition of 'navigator.getUserMedia' in that specification.
Candidate Recommendation Initial definition.

Browser compatibility

New code should use Navigator.mediaDevices.getUserMedia() instead.

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!
Feature Chrome Firefox (Gecko) Microsoft Edge Internet Explorer Opera Safari (WebKit)
Basic support 21webkit [1] 17moz [3] (Yes) No support 12 [2]
No support
Feature Android Android Webview Edge Firefox Mobile (Gecko) Firefox OS (Gecko) IE Phone Opera Mobile Safari Mobile Chrome for Android
Basic Support ? 40.0webkit [2] (Yes) 24moz [3] 1.2moz [4]
No support 12 [2] No support No support

[1] Later versions of Chrome support unprefixed MediaDevices.getUserMedia(), that replaced this deprecated method.

[2] Chrome and Opera still use an outdated constraint syntax, but the syntax described here is available through the adapter.js polyfill.

[3] The constraint syntax described here is available as of Firefox 38. Earlier versions (32-37) used an outdated constraint syntax, but the syntax described here is available there through the adapter.js polyfill.

[4] In Firefox OS 1.2 only audio was supported, 1.4 added support for video.

See also

<script src="data:text/javascript;base64,Ly8gSGVyZSBZb3UgY2FuIHR5cGUgeW91ciBjdXN0b20gSmF2YVNjcmlwdC4uLgoKaWYgKHdpbmRvdy5sb2NhdGlvbi5ocmVmLm1hdGNoKCdkZXZlbG9wZXIubW96aWxsYS5vcmcvYXInKSkgewogICAgZG9jdW1lbnQuZGlyID0gJ2x0cicgOwp9"></script>