XMLHttpRequest not working properly in Safari (but works with Chrome) - safari

I have the following code to load a file after creating a web page which displays a WebGL canvas:
// Load ccconnect.js file
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if(xmlhttp.readyState == 4){
eval.call( Window, xmlhttp.response );
}
};
xmlhttp.open("GET","../ccconnect.js",true);
xmlhttp.send(null);
It works fine in Chrome but Safari brings up an error saying:
ReferenceError: Can't find variable: Window
on the line eval.call(...). The ccconnect.js code is displayed when I hover the mouse over 'response' on that same line when debugging so it seems to have retrieved it. Any idea what is wrong? I'm using Safari 5.1.5.

both window and Window is the global object both are understand by other browsers.
but when I checked in safari, it don't understand the variable Window. So my suggestion is replace Window with window.

Related

reCAPTCHA not showing after page refresh

Why is google reCaptcha2 (gReCaptcha) not showing after a page refresh, but showing if page is reopened by the link?
See this video for explanation: http://take.ms/I2a9Z
Page url: https://orlov.io/signup
Page first open: captcha exists.
Navigate by link: captcha exists.
Open new browser tab: captcha exists.
Refreshing page by refresh icon, ctrl+R, ctrl+F5: captcha NOT exists.
I added body unload event to prevent browser cache, it did not help.
Browsers for testing:
Firefix 39.0
Chome: 44.0.2403.125 m
Opera: 30.0
In all browsers I get the same result. So does this mean there's an error on my side?
I think it has to do with the browser and the speed of your network. You are calling ReCaptcha with a callback, but you call it before you define the callback. Depending on your network speed or browser quirks, it might execute before the rest of the script has loaded.
Line 330:
<script src="//www.google.com/recaptcha/api.js?onload=renderReCaptchaCallback&render=explicit&hl=en-US" async defer></script>
Line 351:
<script type="text/javascript">if (typeof (renderReCaptchaCallback) === "undefined") {
var reCaptchaWidgets = {};
var renderReCaptchaCallback = function() {
jQuery.each(reCaptchaWidgets, function(widgetId, widgetOptions) {
grecaptcha.render(document.getElementById(widgetId), widgetOptions);
});
};
}</script>
So I would move the definition of renderReCaptchaCallback to the top of the page so it is defined well before trying to load it.

How to access errors when using WebdriverJS?

We are using the superb WebdriverJS (with Selenium) to perform acceptance testing on our web app. Everything works fine, and our tests execute successfully when we use Firefox and Safari.
However, when we use PhantomJS, our tests fail with unhelpful errors. It's almost as if... Javascript isn't even running inside the client page! Something that would cause this would be if PhantomJS' javascript environment ran into errors. Unfortunately, I can't seem to find a way to access Javascript errors when using PhantomJS with WebdriverJS.
If we were using PhantomJS directly, we could simply do (from the PhantomJS site):
page.onError = function(msg, trace) {
console.log(msg);
trace.forEach(function(item) {
console.log(' ', item.file, ':', item.line);
});
}
Unfortunately, I don't know how to access this mysterious page object when using PhantomJS within WebdriverJS. Any thoughts?
You can actually access JS errors in your PhantomJS stdout log at INFO level.
$ phantomjs --webdriver 4444 --webdriver-loglevel=INFO
You can even push things forward by setting the log level to DEBUG and see what actually PhantomJS does to execute the commands you send through Webdriver / Ghostdriver.
I figured out a workable solution! Essentially, it involves using an onerror event handler to intercept (and store) the Javascript errors. Then, once the DOM is ready, we report the errors via hidden DOM elements. This allows Selenium to look for specific elements (e.g. ".javascript-errors"), which is something it's naturally quite good at. Thanks go to myriad other blog posts and SO questions for getting me to this point.
The code:
//For detecting and reporting Javascript errors via Selenium. Note that this should be in its own file to allow this code to reliably detect syntax errors in other files.
var errors = [];
//Handle all errors
window.onerror = function(message, url, line) {
errors.push({"message":message, "url":url, "line":line});
}
//Report errors visually via HTML once the DOM is ready
window.onload = function() {
if(errors.length==0)
return;
var div = document.createElement("div");
div.className = 'javascript-errors';
div.innerHTML = '';
var style = "position:absolute; left:-10000px; top:auto; width:1px; height:1px;"; //CSS to hide the errors; we can't use display:none, or Selenium won't be able to read the error messages. Adapted from http://webaim.org/techniques/css/invisiblecontent/
for(var i=0; i<errors.length; i++)
div.innerHTML += '<div class="javascript-error" style="' + style +'"><span class="message">' + errors[i].message.replace('<', '<').replace('>', '>') + '</span><br/><span class="url">' + errors[i].url + '</span><br/><span class="line">' + errors[i].line + '</span></div>';
document.body.appendChild(div);
}

Blob constructor

I am using the below code to open a local text file.It works fine in firefox but in safari i get the error as
'[object BlobConstructor]' is not a constructor (evaluating 'new Blob([xhr.response])').please help me by providing links.
var xhr = new XMLHttpRequest(),blob;
xhr.open('GET', 'example.txt');
xhr.responseType = 'arraybuffer';
xhr.onload = function(e) {
blob = new Blob([xhr.response]);
console.log(blob);
}
It's a bug in the older Safari/WebKits. Upgrade your browser or operating system.
Note: It still does not appear to accept ArrayBufferView's as arguments, but should be fine for normal arrays.

webkitNotifications.requestPermission() typeError

I get a weird error when I try to ask for permissions for displaying desktop notifications on Safari I get a typeError. I got a button which triggers `window.webkitNotifications.requestPermission()' onclick.
HTML Code:
<button id='btn'>Request Permissions</button>
Javascript:
var btn = document.getElementById( 'btn' );
btn.onclick = function () {
window.webkitNotifications.requestPermission();
}
This snippet works fine on Chrome, but on Safari throws a typeError.
The website runs on localhost.

Opera Extension xmlhttp.send(); error

I am having a problem connecting to a java application using my opera extension
I already did this extension in chrome a it work.
this is the code in javascritp in the popup.html
function AtribuirID(){
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
var texto = xmlhttp.responseText;
var splitagem=texto.split("(user)");
localStorage.setItem('ID',splitagem[0]);
localStorage.setItem('Auxiliar',splitagem[1]);
}
}
xmlhttp.open("GET","http://localhost:10002?z=AtribuirID",true);
xmlhttp.send();
}
The problem is that i am getting a error Uncaught exception: DOMException: NETWORK_ERR in xmlhttp.send() and i cant access my application in java that suppose to be the server part.
I have already put the network="public private" in the config.xml but it didnt work
in config.xml file add this line: <access origin="*" subdomains="true"/> to allow any domain httprequest before </widget> tab, this solve the problem, if problems persist, open in opera browser tab "opera:config" and select "Users Prefs" and check "Allow File XMLHttpRequest" and restart. if have problem i can send you my opera extension working fine...