Chrome getUserMedia Not Requesting Permission Locally - html

I'm attempting to play around with navigator.getUserMedia in Chrome; however, it is not requesting permission when served locally (file:///whatever/index.html), but does on JSFiddle ( http://jsfiddle.net/EBsvq/ ) and other sites.
Does anyone know the reason for this? Do I need to somehow reset my permissions?
Here is what I am using locally:
<html>
<head></head>
<body>
<button id="btn">Start</button>
<script type="text/javascript">
/*! jQuery v1.8.3 jquery.com | jquery.org/license */
//JQuery goes here
</script>
<script type="text/javascript">
navigator.getUserMedia = navigator.webkitGetUserMedia || navigator.getUserMedia;
$(function(){
$('#btn').click(function(){
navigator.getUserMedia({audio: true},
function(){
alert('success');
},
function (err) {
alert('fail: ' + JSON.stringify(err));
}); }); });
</script>
</body>
</html>

Chrome blocks a lot of stuff on file:/// URIs without reporting a security error (eg. Geolocation). Your best option is to run from a local webserver, if you have Python installed try SimpleHTTPServer.

You can use the --allow-file-access-from-files flag from the command line when opening chrome to be able to use getUserMedia from a local file system.

I encountered similar problem, but related to microphone access.
Chrome blocks device access if you serve your file via file://(note that on Microsoft Edge and Firefox it worked via file:://).
One solution i've found for Chrome:
open chrome an type in the URL chrome://version/
copy the value of "Command Line" field in your command line and append
--allow-file-access-from-files and run it
after Chrome opened and enter your file:// url.
For starting Chrome always like that, right click on Chrome icon, and then click on properties. In the Shortcut tab append to the Target value all the command line parameters from 2.

It's a little non-trivial how to do the command line arg in OS X. It will usually look like this
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" --allow-file-access-from-files
If you are a freak like me, and put your apps in ~/Applications, then it will be
"/Users/yougohere/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" --allow-file-access-from-files
If neither of those are working, then type chrome://version in your Chrome address bar, and it will tell you what "command line" invocation you should be using. Just add --allow-file-access-from-files to that.

Try Installing Simple Server ( light weight ) , one click install , can be downloaded here
Once it is installed , refer the app to the page you want to run.

Related

How to Automatically redirect website IE browser to Chrome browser?

Recently we migrated to latest version of application which allows the user to open application in any browser.
Earlier it use to support Only IE browsers.
After migration many users still open the application in old browser.
Since the application is very slow in IE browser.We are looking for a solution that will automatically open the URL/Login Page in Chrome browser when user opens in IE browser.
i.e., when a user open URL in IE browser it automatically open the same URL in Google chrome browser.
Google Chrome Legacy Browser support allows this. Under the "Hosts to open in Alternative Browser" policy, put in an entry for the site you want to force to open in Chrome, preceding it with an "!". Example:
!https://www.somesitetoopeninChromeonly.com.
If i understand it correctly, the users open a page in IE and when they click an url on that page, it will open that URL in Chrome.
I guess, you can't do this. You can use target="_blank" to open a new tab in the same browser.
If you want to open a link from an application in chrome and not in IE, you can change the default browser to chrome. Click on Start, type the "default app settings" and change the default browser to chrome.
I think the best solution is to let the user open Google Chrome manually by informing about it.
It is possible however, to make a document called "chrome.hta" for example, with the contents shown below, and then link to it on another page. (This will only work in Internet Explorer, not Edge)
<script type="text/javascript" language="javascript">
var oShell = new ActiveXObject("Shell.Application");
var commandtoRun = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe";
var website = "http://example.com/";
oShell.ShellExecute(commandtoRun, website, "", "open", "1");
window.close();
</script>
The user now has to press "open" and "allow" after they click the link referring to the .hta file.
Now, on the page where you link to the .hta document, you can make the page detect the browser and adjust the link accordingly:
<a id="link" href="example.com">My Application</a>
<script>
if (navigator.appName == 'Microsoft Internet Explorer' || !!(navigator.userAgent.match(/Trident/) || navigator.userAgent.match(/rv:11/)) || (typeof $.browser !== "undefined" && $.browser.msie == 1))
document.getElementById("link").href = "example.com/chrome.hta";
</script>
A bit late, but we have two different solutions for this:
We use a javascript: link to use ShellExecute to run a small exe helper application that checks if Chrome is installed, and if it is, open Chrome to the URL parameter, optionally with switches (e.g. --use-system-default-printer and on shared logon PCs, --incognito). This requires configuring special permissions for the site in Internet Options|Security.
Now we can also use the microsoft-edge: protocol to open sites in Edge.
You could also install your own protocol for opening sites in Chrome but you would need a helper application to re-write the URL. I have one written to add microsoft-edge-private: to open links in Edge in InPrivate mode.
To open the webpage in Microsoft Edge you can try the below code.
TEST

Can't open some html files in chrome (mac)

There are some HTML files (no pattern that I've figured out) that I can't open via the terminal, GUI or right clicking Open in Browser via Sublime Text 3.
The default browser to open the file is definitely set to Chrome. When I say to open the file in the browser it takes me to the Chrome window, but doesn't actually open the file I want.
I can open these files in Chrome itself via command + O and in Firefox or Safari by right clicking on the file and selecting them in the GUI.
It'd be great if Chrome would open files when I expect it to. I'd appreciate any help.
I had the same problem. Fixed it by running this in the terminal after closing Chrome:
open /Applications/Google\ Chrome.app --args --allow-file-access-from-files
The command line args can be viewed in Chrome by visiting chrome://version/
Chrome didn't load local files for me before running this command, but for some reason Chrome Canary did.
On your mac, right click the file and choose 'Open with' and then choose 'other'. Change the default to 'Safari' and then check the 'Always Open With' box. Click open. This should launch the file in Safari. Close the file in the browser and verify that double-clicking it will open it in Safari. Now do the same thing again except change the default back to Chrome.
You may have some security issue if you downloaded the *.html file from somewhere else.
None of the previous answers worked for me, but this one did:
On your Mac, choose Apple menu >> System Preferences >> click Security & Privacy >> click Privacy.
Select Files and Folders.
Please select the checkbox below the Nicepage application to access files and folders in that location.
Source: https://nicepage.com/doc/84207/access-denied-for-documents-folder-macos
Good luck, lads
it's a problem of extend attributes. If you use ls -l to see the attributes of your file, you will see some weird # .
ls -l xxxx.html
-rwxr-xr-x#
the solution is to use xattr.
xattr -c filename
xattr -rc directory
The solution provided by Xiaoou Wang works.
Explanation
I would like to extend this answer and provide below a different solution, which was not given yet.
Chrome (Mac) indeed does not open .html files that have the extended attribute com.apple.quarantine. This attribute is automatically applied on files that are downloaded from the web and are not Apple-authorized applications.
From the terminal, by typing
xattr 'your .html file name'
you can verify whether your .html file has the quarantine attribute set.
With xattr -c command you will remove all attributes, in case there are others set. If you want to only remove the quarantine attribute, type instead
xattr -d com.apple.quarantine 'your .html file name'
Alternative solution
This alternative solution might be even simpler for some people. With my Chrome (mac) I can open .html files by simply dragging the file from finder onto an already opened Chrome window, in spite of their com.apple.quarantine attribute. Important: It does not work if you drag the file onto Chrome's icon in the dock.
There might be an issue with your permissions settings. I tried everything and this is worked for me:
Open your Google Chrome Browser:
click Chrome,
open Preferences,
click Privacy and Security,
click Advanced (at the bottom),
scroll down to "Downloads",
under Location click the Change button.
Then choose where the file you are attempting to open is saved.
you can open this html file and try "command + option + I" to see the file content in the console window, if it's real html file there will be source code reveal. i don't think it can be the chrome's problem.

Unable to enable Chrome app in iframe

I'm trying to load the native messaging example app in an external webpage as follows:
test.html
<html>
<head>
</head>
<body>
<iframe src="chrome-extension://knldjmfmopnpolahpmmgbagdohdnhkik/main.html"</iframe>
</body>
</html>
I have added the web_accessible_resources property in the app's manifest:
manifest.json
{
// <some code snipped>
"web_accessible_resources": ["main.html"]
}
However, when I use the app within test.html, I get the following error in the console, coming from a JavaScript file within the app:
Developer Console
Uncaught TypeError: Object # has no method 'connectNative'
main.js:51
The problematic line of code is the following:
main.js
port = chrome.runtime.connectNative(hostName);
Here's a screenshot - the problem happens when I click on the Connect button (which calls the connect function):
Obviously, this works when the app is run standalone. How can I go about loading the app in a webpage?
You can't. With very few exceptions, Chrome avoids proprietary extensions to the open web. You're asking for exactly that: an external web page that has nonstandard abilities simply because it's opened in Chrome rather than another browser. As the web is today, that kind of behavior would lead to a poor developer and user experience. The native-messaging documentation suggests that the functionality you want is available to Chrome extensions and Chrome apps. And as you're finding out, that's indeed the case: it works as an app, but not as a web-standard iframe. This is by design.
You probably want to write a Chrome extension. Your webpage should detect whether the Chrome extension is installed and whether the user's browser is Chrome. If it's not Chrome, it should give an appropriate error message. If it is Chrome but the extension is not installed, it should urge the user to install your extension.

Unable to load npapi helloworld plugin as extension in chrome browser

Downloaded the NPAPI hello-world plugin from https://github.com/axgle/npapi-chrome-plugin-helloworld and packaged it as a chrome extension (crx) using Chrome developer mode.
Loaded the above extension in chrome browser and tried to open test.html (provided with above plugin) in chrome browser. But it says "Could not load plugin"
Below is the source code of test.html
<doctype html>
<html>
<head>
<script>
window.onload = function(){
test = document.getElementById("pluginObj");
alert(test.sayHello());
}
</script>
</head>
<embed id="pluginObj" type="application/x-helloworld">
<body></body>
</html>
As per my validation, plugin is getting embedded (since on altering test it gives HTML document object) but unable to invoke sayHello method of the plugin.
However when I tried to load the above extension in another PC over there it loaded properly and was able to invoke sayHello method of the plugin.
Both systems have same OS (Windows XP + SP3) and both are using same version of chrome browser (23.0.1271.97 m)
Appreciate any help on this front.
When you added it to the CRX did you mark it public? If you don't it won't be visible outside of the extension.
See the relevant docs
Here is another relevant question: Google Chrome Extensions and NPAPI

How can I run Chrome without all browser's controls (tabs, address line, buttons)?

How can I run Chrome without all browser's controls (tabs, address line, buttons)?
only page-area loaded with specific URL
Thanks
Assuming you want to open a specific URL (let's say http://www.example.com), here are 3 options for your consideration. For all options, start by creating a shortcut to Chrome.exe, which you will edit by adding a flag/switch to the 'Target' property of the shortcut.
Open as an App - Use a 'Target' like this:
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --app=http://www.example.com
This will open the web page in a generic Windows window, with no browser Chrome available although you can still access browser tools, e.g., pressing F12 to open Developer Tools.
Open Fullscreen - Use a 'Target' like this:
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" http://www.example.com --start-fullscreen
This will open the web page in a Chrome window, which will start fullscreen unless there is another instance of Chrome already open, in which case the page will open in that instance. If you press F11, the browser will return to its normal view mode.
Open in Kiosk Mode - Use a 'Target' like this:
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" http://www.example.com --kiosk
This will open the web page in a Chrome window, which will start in Kiosk mode unless there is another instance of Chrome already open, in which case the page will open in that instance. From my understanding, the only way to close this would be to press Alt+F4.
As mr_kazz explained, you can refer to http://www.chromium.org/developers/how-tos/run-chromium-with-flags to see which flags you can use to when launching a Chrome shortcut.
You'll need to start Chrome in "Kiosk mode"
Here is a tutorial for windows: http://think2loud.com/868-google-chrome-full-screen-kiosk-mode/
If you are building a more elaborate kiosk solution, you would put this command in a shell/bash script that would continuously run it (and wait for exit before doing it again). This was if your user pressed Alt+F4 it would just start it again.
http://www.chromium.org/developers/how-tos/run-chromium-with-flags
The above page links to a page with a huge list of arguments, maybe it can be achieved that way. I would also like to know how this can be done.
I currently use this for opening µTorrent server's webUI
chromium-browser --window-size=900,700 http://admin:#localhost:8080/gui/
Run it with the "--kiosk" switch:-
"C:\Program Files\Google\Chrome\Application\chrome.exe" --kiosk
or wherever else it might be installed.
You can open the webpage as an app. To find out how to do so, search a search engine for "open chrome webpage as app" and follow the instructions. I could paste the instructions here, but once you know how to search for it, it's pretty easy.