Created By
Yoel Gluschnaider
05/16/2012 4:34am

Subscribers (4)

BugsJavascript API from Android/iPhone WebView does not work

  • Status: Fixed
  • Priority: None
  • Updated: June 20, 2012 at 7:57pm
Latest response from Facebook
Øyvind Sean Kinsey
This issue was resolved with Tuesdays push.
Status changed to Fixed
Eric Osgood
Status changed to New
When using the Javascript API from within a WebView, the following JS exception is raised:
URIError: Domain contained invalid characters.
I found the root cause as well:
There is a RegExp that is ran on "location.hostname" which is an empty string in WebView/UIWebView and the RegExp fails.
The code in the JS SDK (all.js):
function n(o) {
if (typeof o != 'string')
throw new TypeError('The passed argument was of invalid type.');
if (k.test(o))
throw new URIError('The passed argument could not be parsed as a url.');
if (this instanceof n === false)
return new n(o);
var p = o.match(j);
if (!o || !p)
throw new URIError('The passed argument could not be parsed as a url.');
this._protocol = p[4] || location.protocol.replace(/:/, '');
this._domain = p[6] || location.hostname;
this._port = p[8] || (p[6] ? (this._protocol == 'http' ? '80' : '443') : location.port);
this._path = p[9] || '';
this._search = p[11] || '';
this._fragment = p[13] || '';
if (this._path.substring(0, 1) != '/')
this._path = '/' + this._path;
if (!l.test(decodeURIComponent(this._domain.toLowerCase()))) {
i.error('Invalid characters found in domain name: %s', this._domain);
throw new URIError('Domain contained invalid characters.');
}
}
1 person can reproduce this issue by following these steps
Repro