Fix disconnect crash when screen doesn't exist

The function removeChild throws an exception when the element specified
doesn't exist. This can happen when opening the websocket throws an
exception during connect. Fixes issue #979
This commit is contained in:
Samuel Mannehed 2017-12-12 18:25:20 +01:00
parent 7f1049c0ee
commit b245ec7038
1 changed files with 10 additions and 1 deletions

View File

@ -433,7 +433,16 @@ RFB.prototype = {
this._mouse.ungrab(); this._mouse.ungrab();
this._sock.close(); this._sock.close();
this._print_stats(); this._print_stats();
try {
this._target.removeChild(this._screen); this._target.removeChild(this._screen);
} catch (e) {
if (e.name === 'NotFoundError') {
// Some cases where the initial connection fails
// can disconnect before the _screen is created
} else {
throw e;
}
}
clearTimeout(this._resizeTimeout); clearTimeout(this._resizeTimeout);
Log.Debug("<< RFB.disconnect"); Log.Debug("<< RFB.disconnect");
}, },