09-21-2011 12:15 PM
Hi everyone,
I'm having an issue integrating with Facebook and the Browserfield2.
Basically, what we do is we redirect the user to the Facebook login page with our tokens and the corresponding redirect URL.
When user posts the login credentials, two (Status=Found - 302) redirects occur and then a partial HTML page is returned to the user with the contents similar to this:
<script type="text/JavaScript">
window.location.href="http:\/\/ourredirecturl.com
</script>
Notice that this is only the content sent back in that last page.
The issue is that this last page sent with Status OK-200 and Content-Type=text/html; charset=utf-8 is just being rendered, but the Browserfield2 is not executing the Javascript, so the users ends up stuck on this page.
Both the embedded Browserfield2 in Webworks and a Browserfield2 embedded in native page exhibit this issue, but the default browser provided with BB OS6 does execute the JavaScript and redirects the user to I'm referring above as "ourredirecturl.com" and the user is successfully logged in.
This works fine with other browsers like Firefox, etc...
Is there something that I need to set in the BrowserFieldConfig or the Brwoserfield2 to make the Browserfield2 to execute the JavaScript and redirect the user to the page?
Thanks in advance,
- Roberto
09-21-2011 12:59 PM
Have you tried wrapping HTML/HEAD/BODY tags around the content?
09-21-2011 01:16 PM
tnell,
Thanks for replying.
Unfortunately, I don't control the HTML that comes back. It's coming directly from Facebook.
I thought about trying to get the raw HTML, extract the URL, and then perform the redirect using a Browserfield Listener or Controller, but I haven't found a way to do that. The document.getChildNodes() returns null.
Thanks,
- Roberto
09-21-2011 01:18 PM
Are you on the same origin?? could you do an ajax call, return the script and then eval() the contents?
09-21-2011 01:47 PM
Tim,
I think I know what you mean, but I don't know how to get a hold of the raw content.
I've been looking at the two parameters passed to the BrowserFieldListener.documentLoaded(Browserfield, Document),but I don't see a way to get the text of the raw content with any of those parameters.
If you know way, please let me know and I can give it try.
Thanks,
- Roberto
09-21-2011 02:50 PM
I'm talking more about moving your code out of Java and into JavaScript... doing the hard work inside the web content. Do you control/own the HTML/CSS that is making the initial request to the server inside BrowserField?
09-21-2011 03:05 PM
Unfortunately, I don't have control of that page. The application I'm building uses WebWorks and the user navigates out of the starting page of Webworks app to the pages of an existing web site. That web site provides the options to login using Facebook.
I do have access to the Browserfield provided by WebWorks and could instantiate other Browserfield objects if needed to.
Is there any other way to make this work? Or get a hold of the HTML content returned?
Thanks,
- Roberto
09-21-2011 03:26 PM
I believe what you are looking for is at the bottom of this page:
09-21-2011 04:25 PM
Thanks fo the link, but that did not work for me. ![]()
The Document object provided by the BrowserField2 in WebWorks is of type:
net.rim.device.apps.internal.browser.olympia.dom.O
This object does not appear to implement the HTMLDoc interface and I get Cast exceptions when I try to cast.
I've tried both org.w3c.dom.html.HTMLDoc (the webworks compile process does not allow it) and org.w3c.dom.html2.HTMLDoc.
Anything else I could try?
Thanks,
- Roberto
09-22-2011 07:25 AM
What I would likely do is create a JavaScript Extension that gets loaded for your desired domain (setup properly as a <feature> in the <access> element for that domain in your config.xml file).
For the sake of simplicity.. let's call this API "foo.setText(string)"
In my extension, I would listen for the BrowserField loaded event and then I would run an "executeScript()" on the BrowserField object that would run the following code
foo.setText(document.toString());
This would fire my "setText" function on my "foo" extension and it wold have the whole document's content as a string.
Also, if you are going this route, make sure that if you pass a handle for the BrowserField into your extension, make sure you keep it as a weak reference so that you don't get any memory leaks.