Skip to content

Commit 1eccd22

Browse files
authored
Fix WebSocket error handling
2 parents 83d0582 + 1ae1e8f commit 1eccd22

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

lib/chrome.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ class Chrome extends EventEmitter {
253253
// make sure to complete all the unresolved callbacks
254254
const err = new Error('WebSocket connection closed');
255255
for (const callback of Object.values(this._callbacks)) {
256-
callback(true, err);
256+
callback(err);
257257
}
258258
this._callbacks = {};
259259
}

test/send.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,17 @@ describe('sending a command', () => {
8181
});
8282
it('should catch WebSocket errors after command send', (done) => {
8383
Chrome((chrome) => {
84-
let result;
85-
chrome.Page.enable((err, res)=>{
86-
result = res;
87-
});
88-
chrome.close(()=>{
89-
assert(result instanceof Error);
90-
assert(result.message === 'WebSocket connection closed');
84+
chrome.Runtime.evaluate({
85+
expression: 'new Promise(_ => _)',
86+
awaitPromise: true
87+
}, (error, response) => {
88+
assert(error instanceof Error);
89+
assert(!error.request);
90+
assert(!error.response);
91+
assert(!response);
9192
done();
9293
});
94+
chrome.close();
9395
});
9496
});
9597
describe('without a callback', () => {

0 commit comments

Comments
 (0)