Closed Bug 1384800 Opened 7 years ago Closed 5 years ago

"Failed to allocate videosource" error if you try to call getUserMedia inside an iframe in JSBin

Categories

(Core :: WebRTC: Audio/Video, defect, P3)

56 Branch
defect

Tracking

()

RESOLVED DUPLICATE of bug 1366357

People

(Reporter: adam, Assigned: padenot)

References

Details

(Keywords: stale-bug)

Steps to repro:

See https://jsbin.com/yokexuc/edit?html,js,output

1) Create an iframe
2) call iframe.contentWindow.navigator.getUserMedia

Result: You get an error "Failed to allocate audiosource"

This is a regression in Firefox 56. Not sure whether it is intentional. If it is it seems there could be a nicer error message. It took me a while to figure out what was the problem.
Interesting, I can repro, but it says "Failed to allocate videosource".

In any case, I tracked it down, seems like a regression from bug 1320170. Considering this bug does not talk about iframes, it must be accidental.

Baku, it seems like your patch changed this, was it on purpose ?
Flags: needinfo?(amarchesini)
Rank: 15
Priority: -- → P1
Component: WebRTC → WebRTC: Audio/Video
Depends on: 1320170
The issue here is about the principal of a new iframe element. When a new iframe is created, we load about:blank, but the iframe principal has the codebase of the parent window (https://jsbin.com/something)

Here what happens in steps:

1. Using the principal, getUserMedia() checks the permission. the principal says that the codebase is equal to the URL of iframe parent (https://jsbin.com/something)
2. We need to show the permission prompt. This operation is done by the parent process.
3. the parent process, using the windowID, knows that the URL is about:blank and it shows a permission prompt for it.
4. the permission is granted by the user.
5. the content process tries to create a audio/video source and it checks the permission again using the same principal as point 1. the URL https://jsbin.com/something doesn't have permission.
6. we show the error.

Smaug, is it correct that a new iframe, after loading about:blank, has a principal with the parent URL as codebase?
Flags: needinfo?(amarchesini) → needinfo?(bugs)
yes.
Flags: needinfo?(bugs)
Assignee: nobody → padenot
Adam, Can we verify that it said "videosource" for you, and not "audiosource", and that your problem is limited to cameras, not microphones?
Flags: needinfo?(adam)
Summary: "Failed to allocate audiosource" error if you try to call getUserMedia inside an iframe → "Failed to allocate videosource" error if you try to call getUserMedia inside an iframe
Note that even though the regression-range is the same, this differs from bug 1367805 in that the iframe is not sandboxed, so we should make it work if we can.

Also, JSBin, like JSFiddle, uses "allow-same-origin" in the implicit sandboxed iframe(s) they wrap everything in (JSBin apparently wraps it in two nested iframes for some reason, the inner one without a src attribute apparently, dunno if that matters)

FWIW gUM in plain iframes appears to work just fine in https://jsfiddle.net/jib1/hut751ep/
See Also: → 1367805
Summary: "Failed to allocate videosource" error if you try to call getUserMedia inside an iframe → "Failed to allocate videosource" error if you try to call getUserMedia inside an iframe in JSBin
Now I'm getting "Failed to allocate videosource". Yes, my problem is also limited to cameras, if I do video:false as the constraint then it works fine with audio only. Also, it works fine with fake devices, it's only with a real camera that I get this error.
Flags: needinfo?(adam)
Mass change P1->P2 to align with new Mozilla triage process
Priority: P1 → P2
Moving to p3 because no activity for at least 1 year(s).
See https://github.com/mozilla/bug-handling/blob/master/policy/triage-bugzilla.md#how-do-you-triage for more information
Priority: P2 → P3

jib, you've been doing some stuff in the area lately, what is the currrent behaviour here?

Flags: needinfo?(jib)

This particular iframe bug was somewhat particular to JBin—which if I'm guessing, may have had to do with delayed setting of .src attribute, see comment 5—with unique symptoms:

In the case where it fails with "Failed to allocate videosource":

  • The prompt will say "Will you allow about:blank to use your camera and microphone?
  • And when you allow, it JSBin says: "The page at https://null.jsbin.com says: Failed to allocate videosource"

I did some archeology, and this was fixed in 2017-12-06 in bug 1366357, after which it works:

  • The prompt will say "Will you allow null.jsbin.com to use your camera and microphone?
  • Camera and mic succeed.

5:51.11 INFO: First good revision: 99a3b09ac1898eb1db05430e2876d6643ba0d4a8 (2017-12-06)
5:51.11 INFO: Last bad revision: 18a9cb5cb32d0e8031d0a80901b199d5e9827d83 (2017-12-05)
5:51.11 INFO: Pushlog:
https://hg.mozilla.org/mozilla-central/pushloghtml?fromchange=18a9cb5cb32d0e8031d0a80901b199d5e9827d83&tochange=99a3b09ac1898eb1db05430e2876d6643ba0d4a8

Note that while this still works in release, it will stop working and fail with NotAllowedError once we enable dom.security.featurePolicy.enabled (which is currently enabled in Nightly).

Status: NEW → RESOLVED
Closed: 5 years ago
Flags: needinfo?(jib)
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.