Description of the issue:
I’m a developer, and I confirm this is a bug because I’ve tested on both chrome and firefox, all are working fine, but on brave it’s broken, the issue is that when I developed websocket in local, brave browser throw unknown errors, please check below reproduce step for detailed explanation.
How can this issue be reproduced?
- add local custom domain name:
edit file /System32/drivers/etc/host, add this line:
127.0.0.1 test.local
- host websocket js client using nginx:
config nginx.conf:
server {
listen 80;
location / {
alias "PATH TO INDEX.HTML/";
}
}
index.html:
<!DOCTYPE html>
<script>
let socket = new WebSocket("ws://127.0.0.1:8089");
socket.onopen = function(e) {
alert("[open] Connection established");
alert("Sending to server");
socket.send("My name is LiuYue");
};
socket.onmessage = function(event) {
alert(`[message] Data received from server: ${event.data}`);
};
socket.onclose = function(event) {
if (event.wasClean) {
alert(`[close] Connection closed cleanly, code=${event.code} reason=${event.reason}`);
} else {
alert('[close] Connection died');
}
};
socket.onerror = function(error) {
alert(`[error] ${error.message}`);
};
</script>
- start websocket server using nodejs:
index.js:
// Node.js WebSocket server script
const http = require('http');
const WebSocketServer = require('websocket').server;
const server = http.createServer();
server.listen(8089);
const wsServer = new WebSocketServer({
httpServer: server
});
wsServer.on('request', function(request) {
const connection = request.accept(null, request.origin);
connection.on('message', function(message) {
console.log('Received Message:', message.utf8Data);
connection.sendUTF('Hi this is WebSocket server!');
});
connection.on('close', function(reasonCode, description) {
console.log('Client has disconnected.');
});
});
npm install http
npm install websocket
nodejs index.js
- access http://test.local
Expected result:
expected: connection successful
actually happened: Data: Unknown reason, Length: N/A
Brave Version( check About Brave
):
Version 1.20.97 Chromium: 88.0.4324.96 (Official Build) dev (64-bit)
Additional Information:
as I said it works fine both on firefox and chrome, but not on brave, you can refer to the screenshots:
hope brave can be more developer friendly, so I don’t need to switch back to chrome, thanks