Can HtmlUnit support navigator.mediaDevices? - htmlunit

I'm trying to use HtmlUnit to web-scrape a site, but the start-page requires support for navigator.mediaDevices, which it appears is not supported in HtmlUnit(?)
In the page returned, there is a piece of javascript, like this:
if (!navigator.mediaDevices || !navigator.mediaDevices.getUserMedia)
{
...
windows.stop();
}
Is there a way to get around this?
Or any other similar programmable "browser" that supports this feature?

Yes this is not supported at the moment. Please open an issue on github, adding the support is not that tricky.

Related

Firefox Addon Development - Usage of low-level or non-SDK interface

I am working on Firefox Addon development, I have successfully built the addon, but it is giving me validation error on submission as "Warning: Your add-on uses an interface which bypasses the high-level protections of the add-on SDK. This interface should be avoided, and its use may significantly complicate your review process." on these lines.
const { Cc, Ci } = require("chrome"),
nsIIOService = Cc["#mozilla.org/network/io-service;1"].getService(Ci.nsIIOService),
nsIStyleSheetService = Cc["#mozilla.org/content/style-sheet-service;1"].getService(Ci.nsIStyleSheetService);
I am able run the addon on my machine, but couldn't submit due to this flagged validation check.
Is there any alternative way?
It is completely acceptable to use that. There is not alternative to some APIs in the SDK. That validation is a warning because those features are not frozen and can change at anytime. Can you post a screenshot of the validation blocking your submission? It should be allowed through.
While not entirely identical in function to nsIStyleSheetService, sdk addons can use page-mod to inject stylesheets into some or all content pages.

How to create a javascript mongodb-tutorial-like browser shell

MongoDB website uses a "Browser Shell" to let anybody try how it works really easily. I would like to implement something like that for a site to let devs do some HTTP request for a REST API - how should I approach this? Is there a plugin or tool that I could use?
The mongoDB example can be found here: http://www.mongodb.org/# - click "Try It Out".
The "mongulator" code, written by Kyle Banker, is what you want. He talks about it here:
http://kylebanker.com/blog/2010/1/try-mongodb-browser/
You can see the code on github here:
https://github.com/banker/mongulator
There are also other similar non-MongoDB options available out there as examples - good hunting!
Spring Shell might be helpful
http://www.springsource.org/spring-shell
You can visit www.domongodb.com. I am sure you want like this an online mongodb shell to try actual mongodb commands. http://www.domongodb.com
The latest version of the interactive web shell on try.mongodb.org was discussed on the MongoDB Blog with code available on Github.
Note that interactive shells in a web environment have some peculiar limitations (some of which are covered on the blog post) esp. surrounding activity which can block the browser thread.

How to obtain firefox user agent string?

I'm building an add-on for FireFox that simulates a website, but running from a local library. (If you want to know more, look here)
I'm looking for a way to get a hold of the user-agent string that FireFox would send if it were doing plain http. I'm doing the nsIProtocolHandler myself and serve my own implementation of nsIHttpChannel, so if I have a peek at the source, it looks like I'll have to do all the work myself.
Unless there's a contract/object-id on nsHttpHandler I could use to create an instance just for a brief moment to get the UserAgent? (Though I notice I'll need to call Init() because it does InitUserAgentComponents() and hope it'll get to there... And I guess the http protocol handler does the channels and handlers so there won't be a contract to nsHttpHandler directly.)
If I have a little peek over the wall I notice this globally available call ObtainUserAgentString which does just this in that parallel dimension...
Apparently Firefox changed how this was done in version 4. Have you tried:
alert(window.navigator.userAgent);
You can get it via XPCOM like this:
var httpHandler = Cc["#mozilla.org/network/protocol;1?name=http"].
getService(Ci.nsIHttpProtocolHandler);
var userAgent = httpHandler.userAgent;
If for some reason you actaully do need to use NPAPI like you suggest in your tags, you can use NPN_UserAgent to get it; however, I would be shocked if you actually needed to do that just for an extension. Most likely Anthony's answer is more what you're looking for.

Cross domain content usage from client script (security issues)

I'm trying to load some external content using jQuery load function to div on my page. load method works ok, with local content, but if you want something out of your domain, it won't work.
$("#result").load("http://extrnal.com/page.htm #data);
(it actually works in IE with security warning, but refuses to work in Chrome at all). jQuery documentation says that it is right, because cross-domain content is restricted because of security reasons. Same warning I get if use .getJSON method.
OK, after a googling a bit I found very interesting approach of using YQL for loading content, I've tried some examples, like this:
var request = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D%22http%3A%2F%2Ffinance.yahoo.com%2Fq%3Fs%3Dyhoo%22&format=json&diagnostics=true&callback=?";
$.getJSON(request, function (json) {
alert(json);
}
);
And it really works!
What I dont understand now is that http://query.yahooapis.com is also cross-domain resouce but browser (both IE and Chrome) works OK with that?
Whats the difference? What am I missing?
Thank you
The results you are getting back from YQL are in JSON format which is permitted for cross site AJAX calls like this. Its the same mechanism that allows you to communicate with web services for external sites via JSON (Ie. the twitter API).
Details here - http://www.wait-till-i.com/2010/01/10/loading-external-content-with-ajax-using-jquery-and-yql/
you can make on external site JSON like this:
callback({key:value,etc:1})
and define
function callback(json) {
..here is processing..
}
Thanks for your answers, but unfortunately both of them do not answer my orginal question..
I've checked out related questions on stackoverflow (i know i need to do that first) and found the reason of such behavior.
First code snipset uses AJAX/JSON to retrive the data and it is permitted because of Same Origin Policy. But request to YQL uses JSONP instead, that is OK.
The JSONP was something that I don't know about, that's why I didn't undrestand the behaviour.
Introduction info on JSONP could be found here:
http://ajaxian.com/archives/jsonp-json-with-padding

Twitter OAuth with MGTwitterEngine

I'm using the MGTwitterEngine to connect to twitter and I want to use OAuth with the MGTwitterEngine?
The master branch has merged OAuth and xAuth support back in.
There's a modified version of MGTwitterEngine on GitHub that is supposed to use OAuth: http://github.com/kimptoc/MGTwitterEngine-1.0.8-OAuth/
i would highly suggest using xAuth instead of OAuth as the process on the user's end doesn't at all change. i wrote a tutorial about how I got it to work on iPhone only if it helps. http://www.2bros1blog.com/2010/07/switching-from-basic-to-xauth-with-mgtwitterengine-on-iphone/
I suspect that if the MGTwitterEngine doesn't implement OAuth, it soon will, or will need support for it soon.
I'd suggest seeing if the current development version supports it, and if not -- and you have the motivation -- working on a patch for this functionality.
After having a look at STTwitter, FHSTwitterEngine and MGTwitterEngine I ended up using OAuthConsumer available through github.
My reasons for this were that I was writing an app for Mac OSX Lion in XCode with Objective-C. Most of the OAuth/Twitter code out there was either for other languages, iOS-specific or quite out of date and full of deprecated calls.
Apple's SDK 10.8 now has a social.framework (includes SLRequest) and and accounts.framework (includes ACAccount) which should be really useful for accessing FB, Twitter and some other social site I didn't recognise. Unfortunately that was no good for me working under 10.7 so I did not try those out practically. Would be interested to know anyone's experiences under 10.8.
OAuthConsumer was really straight forward to use to get through Twitter's API properly and is available in a few different languages. You do need to sort out your own JSON etc. but that's pretty straight-forward with NSJSONSerialization etc.
I've written up more detail on this on my blog Twitter OAuth Cocoa. If you need an OAuth, twitter-friendly bit of code, and the function-rich twitter engines aren't working for you then I'd recommend OAuthConsumer.

Resources