Git Product home page Git Product logo

dynamic-getusermedia's Introduction

Manipulate getUserMedia and enumerateDevices with an extension

For advanced testing scenarios it may be desirable to manipulate the behaviour of navigator.mediaDevices.getUserMedia and navigator.media.

While both Chrome and Firefox support basic command line flags for using fake media and skipping the permission prompt, these are static and can not be controlled at runtime by a webdriver script.

This extension injects a small content script that overrides getUserMedia and enumerateDevices and allows controlling the behaviour at runtime via flags in the sessionStorage.

Supported flags

    sessionStorage.__getUserMediaAudioError = "NotAllowedError";
    sessionStorage.__getUserMediaVideoError = "NotFoundError";

make calls to getUserMedia return an error. The error name is taken from the sessionStorage flag.

    sessionStorage.__filterAudioDevices = true;
    sessionStorage.__filterVideoDevices = true;
    sessionStorage.__filterDeviceLabels = true;

control the behaviour of navigator.mediaDevices.enumerateDevices and filter audio input devices, video input devices or the device label respectively. These flags also interact with getUserMedia and will return a NotFoundError when a device kind that is filtered is requested.

Loading the extension

To use this extension in Chrome, first clone or download this repository. Then enable Developer mode in chrome://extensions. While in chrome://extensions, click the "Load unpacked" button and select your local extension folder to install it.

⚠️ After developing remember to disable the extension to avoid getting affected by it.

For testing with selenium, the extension can be automatically be loaded with the --load-extension= command line flag in Chrome. Note that this flag takes a comma₋separated list of paths.

Known issues

Due to timing, loading and parsing the injected script may not intercept very early calls to getUserMedia or enumerateDevices.

dynamic-getusermedia's People

Contributors

fippo avatar phsultan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

dynamic-getusermedia's Issues

Is it possible to set an HTMLVideoElement as a device?

Re https://testrtc.com/manipulating-getusermedia-available-devices/ is it possible to set an HTMLVideoElement as a device either for getUserMedia or getDisplayMedia, to avoid MediaRecorder stop being executed when src of <video> changes as the current Media Capture From DOM Elements specification

A captured MediaStreamTrack ends when playback ends (and the ended event fires) or when the track that it captures is no longer selected or enabled for playback. A track is no longer selected or enabled if the source is changed by setting the src or srcObject attributes of the media element. The steps in MediaStreamTrack.stop() are performed on the MediaStreamTrack when it ends.

requires?

It is currently not possible to select only specific dimensions of a screen using the Screen Capture API, e.g., the bounding client rect of a <video> element, excluding the remainder of the surrounding screen (using window.open()), fullscreen needs to be used to not record title and menu bars; and <video> element is not listed as a device which can be selected using getUserMedia().

support for different resolutions from fake devices

currently defaults to 640x480 in #4. @jan-ivar suggested

clamp = (min, v, max) => Math.max(min, Math.min(v, max))
canvas.width = (typeof c.video.width === 'object') ? 
      clamp(c.video.width.min || c.video.width.exact,
    (("ideal" in c.video.width)? c.video.width.ideal : 640), c.video.width.max ||
            c.video.width.exact) : c.video.width;

NotAllowedError filters regardless of device kind

setting sessionStorage.__getUserMediaAudioError= 'NotAllowedError' currently filters device labels both on audio and video.

This is not very realistic even though it will rarely happen in practice.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.