Typescript: navigator.mediaDevices should have getDisplayMedia

Created on 4 Sep 2019  ·  15Comments  ·  Source: microsoft/TypeScript


TypeScript Version: Version 3.7.0-dev.20190904, also 3.6.2


Search Terms: web api, media devices, display media, screen capture, navigator, types

Code

const opts = { audio: false, video: true }
navigator.mediaDevices.getDisplayMedia(opts) // TS2339: Property 'getDisplayMedia' does not exist on type 'MediaDevices'.

per lib.dom.d.ts, MediaDevices has getUserMedia but not getDisplayMedia. also: https://github.com/Microsoft/TypeScript/blob/master/src/lib/dom.generated.d.ts#L10201

Expected behavior:
getDisplayMedia should be present on MediaDevices, according to https://github.com/w3c/mediacapture-screen-share/pull/86

Actual behavior:
getDisplayMedia is missing on MediaDevices

Playground Link:
https://www.typescriptlang.org/play/#code/MYewdgzgLgBCAOUIwLwwN4wIYFcAmAliAFwwBmWANhAKYA0MAbgXjSTFAE440wC+AKDBZmAcyxQQnAHQBbGoSwARGs2A0I00TShKCEeJSwBPALIKCWABQIkASiA

Related Issues:

Bug lib.d.ts

Most helpful comment

Workaround to disable Typescript error:
const mediaDevices = navigator.mediaDevices as any;
const stream = await mediaDevices.getDisplayMedia();

All 15 comments

why they still not fix this problem... then how they're using right now

Hi Team,

Looks like this issue is not fixed yet, getDisplayMedia is still missing on mediaDevices.
What can be an alternative to use for getting the getDisplayMedia capability? I am using angular 6 in my project..

still an issue

@LolliDepp Yeah still an issue

someone got to fix the issue?

I'm also having this issue

Is there a workaround for this error? I'm using Angular 9 and can't build project.

Workaround to disable Typescript error:
const mediaDevices = navigator.mediaDevices as any;
const stream = await mediaDevices.getDisplayMedia();

Also having the issue =(

Same issue :(
typescript 3.7.2

Still a problem in nightly version.

Maybe you can define it by yourself:

declare global {
  interface MediaDevices {
    getDisplayMedia(constraints?: MediaStreamConstraints): Promise<MediaStream>;
  }

  // if constraints config still lose some prop, you can define it by yourself also
  interface MediaTrackConstraintSet {
    displaySurface?: ConstrainDOMString;
    logicalSurface?: ConstrainBoolean;
    // more....
  }
}

Nope, still this problem, also trying workaround..
Right now i'm workaround this adding this line before my getDisplayMedia
// @ts-ignore
Thanks this i can compile successfully, at least

Workarounds are bad. getDisplayMedia is complex as it is. We need good definitions.

Seconded - any progress? This API is probably only going to grow in in importance and popularity.

Still an issue. The workaround by @aponski works though

Was this page helpful?
0 / 5 - 0 ratings