MediaDevices.getUserMedia API from web extension background page is not running

(Pankaj Agarwal) #1

We want to capture users screen,desktop application, browser’s tabs using getUserMedia API. where it first ask user to give permission and then share stream.
But it mentioned that we can only call this API from secure origin (https or localhost).

We already have website (hosted on https and as local product you can host on http as well) and hosted web extension (for firefox)

our flow is like this -

  1. user login to our web page, where It will send message to content script to capture media
  2. content script will send message to extension’s background
  3. then extension should have to use getUserMedia API to launch permission popup and start capturing media stream

but when we execute this API in background then it not launching permission poup.

Please suggest any possible solution for this and If it is not support then let us know what experience we can use here.

(Jorge) #2

I think the getUserMedia call needs to happen in the content script, and not the background script. The background script is global to the entire browser, so it wouldn’t know which tab to run this for.

(Pankaj Agarwal) #4

Thanks for reply.

I tried following api in content script -

but it throws error -
chrome-extension://glhknecmiannbjlkopjnacjmphbpnbkm/ContentScript/CustomisedWorkItemMessaging.js:54 [Deprecation] getUserMedia() no longer works on insecure origins. To use this feature, you should consider switching your application to a secure origin, such as HTTPS. See for more details.
Uncaught (in promise) DOMException: Only secure origins are allowed (see:

then what is feasible way to use this API ?

(Pankaj Agarwal) #5

error is coming If I run same API in
a) content script (loaded in http domain web app)
b) background page of web extension

message:"The request is not allowed by the user agent or the platform in the current context."
name :NotAllowedError

(Jorge) #6

Sounds like the API is only available for secure sites.

(Pankaj Agarwal) #7

But extension background seems to be more secure, then why it is not supported there ?