samedi 26 juillet 2014

JavaScript - détecter la version de Chrome sans utiliser window.navigator.appVersion - Stack Overflow




EDIT: The question has become irrelevant as I discovered the setRequestHeader technique works on both v18 and v19. The poster on http://code.google.com/p/chromium/issues/detail?id=123150#c39 appears to be incorrect saying this method does not work on v18 - it does. I will update with this answer in 8 hrs when I am allowed!




I am using a Chrome extension which is an automatic testing tool. It has overridden user agent (by command line when starting chrome) so I can no longer see the version of chrome by using appVersion.


Is there some other way to detect the chrome version in Javascript?


Background: I am using xmlhttp to request a page protected by Basic Auth.


I must now take different action depending on v18 or v19+ as Google removed embedded basic auth in a URL at v19 (see http://code.google.com/p/chromium/issues/detail?id=123150#c39).


This is an automatic script so I will not be there to enter username or password, but they are both known to the script.


if (v18_or_earlier)
{
xmlhttp.open("POST", url, true, http_basic_username, http_basic_password) ;
}
else //v19+
{
xmlhttp.open("POST", get_upload_url(), true);
var auth_header = "Basic " + Base64.encode(http_basic_username + ":" + http_basic_password) ;
xmlhttp.setRequestHeader("Authorization", auth_header) ;
}
xmlhttp.send(post_body) ;



Would something like this work?


<script>  
function chrome_version( version ) {
if ( version < 18) {
xmlhttp.open("POST", get_upload_url(), true);
var auth_header = "Basic " + Base64.encode(http_basic_username + ":" + http_basic_password) ;
xmlhttp.setRequestHeader("Authorization", auth_header) ;
} else {
# Maybe do framebusting or...
xmlhttp.open("POST", url, true, http_basic_username, http_basic_password) ;
}
}
</script>
<iframe src="http://user:pass@example.org"
onload="chrome_version(18)"
onerror="chrome_version(19)">
</iframe>




EDIT: The question has become irrelevant as I discovered the setRequestHeader technique works on both v18 and v19. The poster on http://code.google.com/p/chromium/issues/detail?id=123150#c39 appears to be incorrect saying this method does not work on v18 - it does. I will update with this answer in 8 hrs when I am allowed!




I am using a Chrome extension which is an automatic testing tool. It has overridden user agent (by command line when starting chrome) so I can no longer see the version of chrome by using appVersion.


Is there some other way to detect the chrome version in Javascript?


Background: I am using xmlhttp to request a page protected by Basic Auth.


I must now take different action depending on v18 or v19+ as Google removed embedded basic auth in a URL at v19 (see http://code.google.com/p/chromium/issues/detail?id=123150#c39).


This is an automatic script so I will not be there to enter username or password, but they are both known to the script.


if (v18_or_earlier)
{
xmlhttp.open("POST", url, true, http_basic_username, http_basic_password) ;
}
else //v19+
{
xmlhttp.open("POST", get_upload_url(), true);
var auth_header = "Basic " + Base64.encode(http_basic_username + ":" + http_basic_password) ;
xmlhttp.setRequestHeader("Authorization", auth_header) ;
}
xmlhttp.send(post_body) ;


Would something like this work?


<script>  
function chrome_version( version ) {
if ( version < 18) {
xmlhttp.open("POST", get_upload_url(), true);
var auth_header = "Basic " + Base64.encode(http_basic_username + ":" + http_basic_password) ;
xmlhttp.setRequestHeader("Authorization", auth_header) ;
} else {
# Maybe do framebusting or...
xmlhttp.open("POST", url, true, http_basic_username, http_basic_password) ;
}
}
</script>
<iframe src="http://user:pass@example.org"
onload="chrome_version(18)"
onerror="chrome_version(19)">
</iframe>

0 commentaires:

Enregistrer un commentaire