WebRTC - Browser doesn't ask for mic access permission for local html file

Yatendra picture Yatendra · Jan 14, 2013 · Viewed 12.3k times · Source

I have some simple webRTC code which uses getUserMedia to gain access to user's mic. Now when I load that html file (saved at my localhost) in my browser, the browser doesn't ask for mic access permission and thus get failed to get access.

But when I run the same html inside the w3schools.com editor, it asks for mic access permission and upon allowing it to access my mic, it works fine...

Why is this strange behaviour?

Answer

Hugo picture Hugo · Apr 18, 2013

When you open an html file right off the filesystem (file:// prefix), Chrome will auto-block getUserMedia permissions. You have to run a server locally.

I started up a sinatra server like this:

# server.rb
require 'sinatra'

get '/' do
  File.read('index.html')
end

Then give it ago.

$ gem install sinatra
$ ruby server.rb

http://localhost:4567