Chrome has recently released an update to its media settings which prompts a user to grant permission to a site allowing access to his/her microphone and camera. Is there a way to detect these settings in Javascript?
I have a flash player (which will eventually be HTML5 based) with microphone functionality. The player is currently set up with a friendly tutorial on how to grant permission before starting the session. However, since Chrome released the update, the flash player and Chrome permissions are conflicting causing an error in the flash until the user has allowed/denied the Chrome settings prompt. What I'd like to do, until the player is moved to HTML5, is detect if the browser is Chrome (with appropriate version) and if the user's settings aren't set to then show additional tutorial screen.
Couple things:
This is specific to Chromes implementation so you can not tell what permissions the user has granted unless Chrome supplies that information to your app. I.E. there is no API you can query for this info.
It's not even something that Chrome stores. If you look under the advanced settings tab on this page, you will see that its on a per app basis not a one time thing. Chrome will only remember what permission was granted for a specific application if that app asks for the permission over https. If it asks for it over http then it will forget what permissions were granted.
Your best bet (though by no means full-proof) is to sniff out the browser agent and version. For one of the better implementations of this see here.
You will want to specifically look for Chrome and any version >= 21. (21 was the version that introduced the getMediaApi). Then it's a simple if check:
if (version >= 21){
//ask permission though the getMediaApi
} else{
//ask permission though flash
}
i stumbled into an approach for this that works fairly well, and doesn't require cookies (people can change these settings out-of-band, so the cookie can become incorrect), or for Chrome to provide an ounce of help (it doesn't).
if (chrome) {
var madeMicDecision = false;
navigator.getUserMedia({whatever},
function(stream) {
madeMicDecision = true;
//close the stream, move to the next page
//they have either just granted permission, or have in the past and it's remembered
},
function(error) {
madeMicDecision = true;
//go to error handling page
//the error handling page should describe going to chrome://settings/contentExceptions#media-stream
//or how to allow the user media via clicking on the crossed out camera icon in the 'wonderbar'
}
}
But we also want to show the tutorial screen - the above code will pop the chrome infobox if the permission setting isn't remembered. But without permission events from chrome, or an API to query permissions, how do we know when to show the chrome+infobox tutorial content?
My trick was to show the content automatically, but only after a delay. People who have accepted or denied permissions previously would never see this content, because our success/error handler would have moved them on before the delay. So, give the getUserMedia call a moment to detect/react - if the browser hasn't moved on, it's time to show the help content.
setTimeout(function() {
if (!madeMicDescision) {
//display chrome/infobox/getUserMedia permissions help content
}
}, 2000);
Not perfect (bizarre and sad really), but seems to work for the most common cases.
Related
I have made an application to record a video by following this steps : https://github.com/muaz-khan/RecordRTC,
I want access to allow the camera always 'allow',
i've tried bypass the allow permission in popup allow webcam use start chrome --use--fake-ui--for--media-stream and it's work for me, but when i closed my chrome and then i opened chrome again , the popup permission allow webcam still showing,
what's the solution?
If you serve your application from an https domain, Chrome will remember the user's answer to the permissions dialog after the first use, so if they use it once, permission is granted (they click "allow"), the next time they use it, permission will be granted automatically and they won't be shown the pop up again.
I have a feature on a site that gives the user the telephone number of their closest branch of shop based on their current location via the google-maps api.
When the page loads for the first time, the browser automatically asks the user if they would like to share their location. That's all fine, except some browsers don't handle it as well as others and continually ask the user when the move from page to page (the number is on every page).
So is there a way I can set a cookie based on weather or not they gave permission and only display the automatic 'this site would like to use your current location' message if the cookie has expired after say, a month?
It is particularly bad on smartphones, it asks all the time.
This is more of a browser related issue rather than a coding issue. In browsers like Chrome this interference in inevitable. It has to do a lot with security concern. Hackers can create a fake webpage for a banking site as a part of phishing and hack peoples password.
Most of the latest browsers disable hiding the location bar, although in some browsers, setting location=no will disable the address bar from being modified.
But from a coding perspective you have some options, Some of them are listed below.
You can use a localStrorage object that persists any saved data indefinitely on the user's computer and across browser tabs (similar to JavaScript cookies).
Here is a demo code:
<script type="text/javascript">
var mydomstorage=window.localStorage || (window.globalStorage?globalStorage[location.hostname] : null)
if (mydomstorage){
var i=(mydomstorage.pagecount)? parseInt(mydomstorage.pagecount)+1 : 1
document.write("You have visited this page <b>" + i + " </b> times altogether.")
mydomstorage.pagecount=i
}
else{
document.write("<b>Your browser doesn't support DOM Storage unfortunately.</b>")
}
</script>
This code works on FF3+, Chrome4+, Safari4+, Opera10.5+, or IE8+
If you have windows popping up that ask for the location you can try out this simple solution by making window.open=null; on the instance that is responsible for fetching out the location.
In our web-conference application we have Flash client through which we provide video and audio communication. Video is done though Red5 Media Server, audio is done through WebRTC.
When you are trying to access mic or camera in Flash, it will prompt the Flash Permission Window to approve the access to video and camera. However in Chrome, it will also prompt for Chrome Mic and Camera Permission. A problem with that is that Chrome Mic and Camera Permission is not very visible and user would usually miss this prompt and then complain that video doesn't work.
The solution that I was thinking about is to manually trigger Chrome Permission prompt through WebRTC call and show the arrow that will point on where to press to allow.
But even after doing that, once it comes to Flash and user approves Flash Permission Window, the Chrome Mic and Camera Permission prompt will pop up again. So it seems like Chrome is not able to remember that permission was already granted.
And the question is: is there a way to make Chrome to know that permission is already there and there is no need to ask again.
This is the function to ask for Camera permission in Chrome through SIP.js:
function getUserWebcamMedia(getUserWebcamMediaSuccess, getUserWebcamMediaFailure) {
if (userWebcamMedia == undefined) {
if (SIP.WebRTC.isSupported()) {
SIP.WebRTC.getUserMedia({audio:false, video:true}, getUserWebcamMediaSuccess, getUserWebcamMediaFailure); // Chrome permission prompt pops up on this call
} else {
console.log("getUserWebcamMedia: webrtc not supported");
getUserWebcamMediaFailure("WebRTC is not supported");
}
} else {
console.log("getUserWebcamMedia: webcam already set");
getUserWebcamMediaSuccess(userWebcamMedia);
}
};
And this is how I am accessing camera in Flash:
var _camera:Camera = null;
_camera = Camera.getCamera();
...
_video = new Video();
_video.attachCamera(_camera); // Flash prompt pops up on this call
Sorry if the situation is not very clear. I can provide more information if needed.
The only way to store webrtc permissions is if it is over a TLS/SSL connection(HTTPS). Then chrome can store what sites were allowed or disallowed. This way, when they visit your site once and approve use of their media inputs, then they do not ever have to approve of their use again on that site.
However, since Flash and WebRTC are two different ways to grab the inputs, there is no way for permissions for one to change permissions for the other.
I'm trying to use the new HTML notification API...
I'm still stuck in the request authorization phase;
when user click on a button it's executed the function:
// this is all inside a click handler
var fn = console.info;
window.Notification.requestPermission(function(grant) {
fn(grant);
});
When i tryed this for the first time in chrome, a chrome's message came out asking me if i want to concede the Notification grant to my localhost web site... I said no (just to test even this case). Then I tried again, but that message from chrome never came out.
My question:
If the user change opinion about notification, how could enable notification for a website?
Maybe do I've to change something in the chrome settings?
Thanks in advance
You can manage and re-allow notifications in Chrome by going to Settings -> Privacy -> Content Settings -> Scroll down to Notifications - here you can manage which sites are allowed to show notifications and which are not.
Update:
As mentioned by #ivan_vaz in the comments, it is also possible to configure this as well as other permissions by clicking the favicon of the website in the address/navigation bar.
I am using the geolocation functionality to track user's locations with javascript. More specifically, I am using navigator.geolocation.watchPosition. My site works fine. When I visit my site on my Android device it prompts if I would like to allow the site to track my location. I tap allow (as well as remember my preference).
After success with that I turned off location services on my phone and went back to the site. It didn't prompt me for permission again (since I told it to remember my preference last time but it didn't prompt me to turn on my location services either. Needless to say at that point my site never got any geolocation data from the browser.
My question: Is there some way to prompt the user to turn on their location services programatically? If I had not saved my security preference and it prompted me to allow again would it have turned on or asked me to turn on location services? I would hate to have to tell the user they need to go into their cell phone's preferences to enable it.
It's browser specific or to be more exact - application specific. What you could do is wait e.g. half a minute or a minute for the location and if it is not available show a warning to the user.