Server Site Events (SSE) connection abort with firefox - javascript

I wrote a little Chat using SSE for loading new messages.
It is working fine with Chrome, Safari and Opera while Firefox closes the connection after a few retries.
I'am using retry: 2000 (2s). Sometimes firefox is doing up to 10 events, sometimes only 1 or 2. I know from my serverstats, that more then 80% of my users are using firefox, so I need this working on firefox.
I'm using the latest version of firefox and I added a console.log() after every EventListener I'm using ('message', 'open', 'close').
Does anyone have an idea what to do?
Thanks a lot

think I solved the problem:
First I opend the EventSource in a function :
function chat_read() {
if(typeof(EventSource) !== "undefined") {
var source;
source = new EventSource('?link=chat_stream');
}
Now I tried to initialize the variable 'source' global (outside the function) and it is working now.
var source;
function chat_read() {
if(typeof(EventSource) !== "undefined") {
source = new EventSource('?link=chat_stream');
}
Beside this I wrote a function which is looking for the SSE 'open' event still firering and if it is not, it will restart the SSE.

Related

Can't get Web Audio API to work with iOS 11 Safari

So iOS 11 Safari was supposed to add support for the Web Audio API, but it still doesn't seem to work with this javascript code:
//called on page load
get_user_media = get_user_media || navigator.webkitGetUserMedia;
get_user_media = get_user_media || navigator.mozGetUserMedia;
get_user_media.call(navigator, { "audio": true }, use_stream, function () { });
function use_stream(stream){
var audio_context = new AudioContext();
var microphone = audio_context.createMediaStreamSource(stream);
window.source = microphone; // Workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=934512
var script_processor = audio_context.createScriptProcessor(1024, 1, 1);
script_processor.connect(audio_context.destination);
microphone.connect(script_processor);
//do more stuff which involves processing the data from user's microphone...
}
I copy pasted most of this code, so I only have a cursory understanding of it. I know that it's supposed to (and does, on other browsers) capture the user's microphone for further processing. I know that the code breaks on the var audio_context = new AudioContext(); line (as in, no code after that is run), but don't have any error messages cause I don't have a mac which is required to debug iOS Safari (apple die already >_<) Anyone know what's going on and/or how to fix it?
e: forgot to mention that I looked it up and apparently I need the keyword "webkit" before using Web Audio API in Safari, but making it var audio_context = new webkitAudioContext(); doesn't work either
#TomW was on the right track - basically the webkitAudioContext is suspended unless it's created in direct response to the user's tap (before you get the stream).
See my answer at https://stackoverflow.com/a/46534088/933879 for more details and a working example.
Nothing works on mobile save to home screen apps. I issued a bug report to Apple developer. Got a response that it was a duplicate ( which means they know..no clue if or when they will actually fix it).

PayPal lightbox won't open in iPhone safari/web app; 'win.location' undefined

(works fine in Chrome on the iPhone)
I get this error:
TypeError: 'undefined' is not an object (evaluating 'win.location') in dg.js line 3
And the lightbox does not open.
The code in question inside PayPal's dg.js is:
startFlow: function (url) {
var win = that._render();
if (win.location) {
win.location = url;
} else {
win.src = url;
}
}
So does mobile Safari not understand that._render()? How do I get around this?
If it matters, I'm using Adaptive Payments, calling it like so:
var dg = new PAYPAL.apps.DGFlow({
trigger: null,
expType: 'light'
});
dg.startFlow('https://www.paypal.com/webapps/adaptivepayment/flow/pay?expType=light&payKey=' +data.paykey);
I don't have any problems getting the payKey & the entire payflow works on desktops and in mobile browsers other than Safari (it works on desktop Safari). It also does not work when our site is run as an iOS web app, which I assume is just a shell for Safari anyway.
I can explain why you are seeing this error.
Safari on iOS only allows a window to be opened as a result of a user click/touch event.
The DGFlow._render() function executes:
window.open('', "PPDG");
which returns null if triggered by anything other than a user click/touch event.
I am guessing you are issuing an XMLHttpRequest to generate a PayRequest/PayKey on the server and then in the onsuccess callback you are calling DGFlow.startFlow().
The solution is two split the process into two steps:
When the user is ready to checkout, issue the call to the server to
generate the pay key.
Then, present the user with a button to Checkout with PayPal and when that is clicked, call DGFlow.startFlow()
Found a couple of ways to get around this...location.replace with the PayPal URL or using your own lightbox. I used easybox.
// Replace
dg.startFlow('https://www.paypal.com/webapps/adaptivepayment/flow/pay?expType=light&payKey=' +data.paykey);
// with
var RUNNING_AS_WEB_APP = (window.navigator.standalone == true ? true : false);
if (RUNNING_AS_WEB_APP === false) {
dg.startFlow('https://www.paypal.com/webapps/adaptivepayment/flow/pay?expType=light&payKey=' +data.paykey);
} else {
location.replace('https://www.paypal.com/webapps/adaptivepayment/flow/pay?expType=light&payKey=' +data.paykey);
// Or, lightbox option:
// $.easybox([{url: 'https://www.paypal.com/webapps/adaptivepayment/flow/pay?expType=light&payKey=' +data.paykey, width: 320, height: 480}]);
}
Try using the mini browser experience where expType=mini. Seems to work better than the lightbox on mobile devices.
Adaptive Payments without modal box or popups?

smartcard-insert/remove not fired

I am trying to use the Mozilla crypto object in JavaScript.
Here is my rather simple code in JavaScript:
$(document).ready(function() {
// Handler for .ready() called
register();
});
function onSmartCardChange() {
// window.location.reload();
console.log('insert-remove');
}
function register() {
window.crypto.enableSmartCardEvents = true;
document.addEventListener("smartcard-insert", onSmartCardChange, false);
document.addEventListener("smartcard-remove", onSmartCardChange, false);
console.log('version='+window.crypto.version);
}
The version of the crypto object is written in the console window.
But an event is not fired whenever I plug/unplug my USB gadget.
In ControlPanel/Device manager the smart card seems OK. I also installed Charismatics and Cryptovision software.
Why do not I get an event when I insert/remove the USB gadget?
Is it possible that something is wrong with my setup?
Thanks,
donescamillo#gmail.com
I had some luck. I added the device in Firefox/Tools/Options/encryption/SecurityDevices. Now When I restart Firefox, plug the reader, start Firefox, unplug reader, I get an event. In any other case (plugging in reader again, starting Firefox without reader and plugging reader in) I do not get an event.
Could the problem be in the DLL specified when I added the reader to Firefox?
Thank you
donescamillo#gmail.com

web-socket.js and WebSocket

I am trying to do a web socket implementaton for browser. Firefox, Chrome works great, but when i try in IE, it creates the socket object but never calls the timer.
WebSocket = function(url, protocol, proxyHost, proxyPort, headers) {
var self = this;
self.__id = WebSocket.__nextId++;
WebSocket.__instances[self.__id] = self;
self.readyState = WebSocket.CONNECTING;
self.bufferedAmount = 0;
self.__events = {};
// Uses setTimeout() to make sure __createFlash() runs after the caller sets ws.onopen etc.
// Otherwise, when onopen fires immediately, onopen is called before it is set.
setTimeout(function() {
WebSocket.__addTask(function() {
WebSocket.__flash.create(
self.__id, url, protocol, proxyHost || null, proxyPort || 0, headers || null);
});
}, 0);
};
What could be the reason ?
What version of IE are you talking about ?
What websocket library are you using ?
Web sockets are not supported by older version of IE. I think you need to use long polling instead of websockets for those older browsers...
If your using this : https://github.com/gimite/web-socket-js
It's stated in the Documentation :
It should work on: Google Chrome 4 or
later (just uses native
implementation) Firefox 3.x, 4.x,
Internet Explorer 8, 9 + Flash Player
10 or later It may or may not work on
other browsers such as Safari, Opera
or IE 6. Patch for these browsers are
appreciated, but I will not work on
fixing issues specific to these
browsers by myself.

IE 8/9 Crashes and Freezes with a message saying "A problem with this webpage caused Internet Explorer to close and reopen the tab?"

I am using Ajax via ICallbackEventHandler in ASP.NET, what happens on the page is that a recursive call is made back to the server every 1000ms using ajax. Here is the code that makes a ajax callback every 1 second:
setTimeout("MessageServerRequest(tempLastDate);", 1000);
function MessageServerRequest(param)
{
WebForm_DoCallback('ChannelControl1','getmessage~' + param,MessageServerResponse,null,null,true);
}
function MessageServerResponse(param, context)
{
if (param.length > 0) {
var splitParam = param.split("~");
var id = splitParam[0];
var messagesHtml = splitParam[1];
var lastDate = splitParam[2];
tempLastDate = lastDate;
$('#' + id).prepend(messagesHtml);
}
setTimeout("MessageServerRequest(tempLastDate);", 1000);
}
What this does is that it gets all the latest messages from the database and returns the new messages back to the client.
Now when i removed the recursive call, IE didnt crash, but the thing is that when i use Mozilla, Safari or Opera everything works fine with the recursive call being used.
I dont understand why its working for all other browsers and not IE 8/9
System Info
Windows 7 ultimate
32 bit
visual studio 2006
IE9, even didnt work with IE8 but i upgraded to IE9
Can anyone help me with this issue please, i would be greatful?
Thanks

Categories