Donald Ness created CB-9399:
-------------------------------
Summary: User agent parse error with XHR_NO_PAYLOAD in
pokeNativeViaXhr in Chrome
Key: CB-9399
URL: https://issues.apache.org/jira/browse/CB-9399
Project: Apache Cordova
Issue Type: Bug
Components: CordovaJS
Affects Versions: 5.1.1
Environment: Running cordova app in chrome browser
Reporter: Donald Ness
function pokeNativeViaXhr() {
// This prevents sending an XHR when there is already one being sent.
// This should happen only in rare circumstances (refer to unit tests).
if (execXhr && execXhr.readyState != 4) {
execXhr = null;
}
// Re-using the XHR improves exec() performance by about 10%.
execXhr = execXhr || new XMLHttpRequest();
// Changing this to a GET will make the XHR reach the URIProtocol on 4.2.
// For some reason it still doesn't work though...
// Add a timestamp to the query param to prevent caching.
execXhr.open('HEAD', "/!gap_exec?" + (+new Date()), true);
if (!vcHeaderValue) {
vcHeaderValue = /.*\((.*)\)$/.exec(navigator.userAgent)[1];
}
execXhr.setRequestHeader('vc', vcHeaderValue);
execXhr.setRequestHeader('rc', ++requestCount);
if (shouldBundleCommandJson()) {
execXhr.setRequestHeader('cmds', iOSExec.nativeFetchMessages());
}
execXhr.send(null);
}
This function fails at the line:
vcHeaderValue = /.*\((.*)\)$/.exec(navigator.userAgent)[1];
Notice the $? This tries to match parenthesis at only the end of the user agent
string.
On chrome:
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML,
like Gecko) Chrome/43.0.2357.134 Safari/537.36"
So since no parenthesis are matched at the end of the string, a null exception
is thrown trying to access null[1].
For iOS, it works, at least on new versions of iOS because the user agent
string is:
"Mozilla/5.0 (iPhone; CPU iPhone OS 8_4 like Mac OS X) AppleWebKit/600.1.4
(KHTML, like Gecko) Mobile/12H141 (2071227104)"
Is there any identifier that could work for Chrome, too?
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]