Skip to content

Manipulate getUserMedia and enumerateDevices with an extension

License

Notifications You must be signed in to change notification settings

fippo/dynamic-getUserMedia

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Manipulate getUserMedia and enumerateDevices with an extension

Topics

Resources

License

Stars

Watchers

Forks

Packages