This is an automated email from the ASF dual-hosted git repository.
kenhuuu pushed a commit to branch 3.7-dev
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git
The following commit(s) were added to refs/heads/3.7-dev by this push:
new 38594b92da Fix WebSocket API inconsistency causing "this._ws.on is not
a function" error (#3204)
38594b92da is described below
commit 38594b92da189b1295de5ae869fc185c26b5221c
Author: Huberty Xavier <[email protected]>
AuthorDate: Fri Oct 10 19:18:53 2025 +0200
Fix WebSocket API inconsistency causing "this._ws.on is not a function"
error (#3204)
Conditionally attach 'unexpected-response' listener only for Node.js
WebSocket (ws package)
Preserve existing useGlobalWebSocket logic for legitimate browser/polyfill
scenarios
---
.../javascript/gremlin-javascript/lib/driver/connection.js | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git
a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/connection.js
b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/connection.js
index 8e5d178639..d9570774bb 100644
---
a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/connection.js
+++
b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/connection.js
@@ -163,10 +163,11 @@ class Connection extends EventEmitter {
this._ws.addEventListener('open', this.#handleOpen);
this._ws.addEventListener('error', this.#handleError);
- this._ws.on('unexpected-response', this.#handleUnexpectedResponse);
+ if (!useGlobalWebSocket) {
+ this._ws.on('unexpected-response', this.#handleUnexpectedResponse);
+ }
this._ws.addEventListener('message', this.#handleMessage);
this._ws.addEventListener('close', this.#handleClose);
-
return await this._openPromise;
}
@@ -415,7 +416,11 @@ class Connection extends EventEmitter {
});
this._ws.removeEventListener('open', this.#handleOpen);
this._ws.removeEventListener('error', this.#handleError);
- this._ws.off('unexpected-response', this.#handleUnexpectedResponse);
+ // Only remove unexpected-response listener for Node.js WebSocket (ws
package)
+ // Browser WebSocket does not have this event and .off() method
+ if (this._ws && 'off' in this._ws) {
+ this._ws.off('unexpected-response', this.#handleUnexpectedResponse);
+ }
this._ws.removeEventListener('message', this.#handleMessage);
this._ws.removeEventListener('close', this.#handleClose);
this._openPromise = null;