Safari 10.1中的WebSocket API似乎具有最大數量的二進制數據,它可以緩衝,然後發送的下一條消息會得到錯誤「WebSocket連接失敗:無法發送WebSocket幀」。如何解決Safari 10.1錯誤「無法發送WebSocket幀」?
Safari然後關閉與代碼1006(CLOSE_ABNORMAL)的連接。
的WebSockets是supposed to report the bufferedAmount
- 但Safari瀏覽器始終報告0
後,直到發生錯誤,連接被關閉。
我試着只是在每條消息之間做一個setTimeout 100ms,而且這似乎適用於小數據塊的情況,但是當我發送我的關閉JSON消息時,它看起來很脆,大塊仍然會出錯,即使有更長的延遲。
您可以see the bug in action here - 「Play Sample」按鈕在Safari 10.03中運行,但10.1中出現錯誤。 (Code that handles the WebSocket connection.)
有關如何解決此問題的任何想法?或甚至是什麼限制?我知道Safari是開源的,但我不確定在哪裏尋找。
更新:這裏有一個簡單的例子:
// this fails in Safari 10.1 but works in 10.03 (and other browsers)
var ws = new WebSocket('wss://echo.websocket.org');
ws.onerror = function(evt) {
// Not sure why, but error events seem to have no useful information
// The console, however, will have the following error:
// WebSocket connection to 'wss://echo.websocket.org/' failed: Failed to send WebSocket frame.
console.log("WebSocket error - see console for message");
}
ws.onclose = function(evt) {
console.log(`WebSocket closed with code: ${evt.code}, reason: ${evt.reason}`);
}
ws.onopen = function() {
console.log('sending first binary message');
ws.send(new Uint8Array(23085));
console.log('bufferedAmount is ' + ws.bufferedAmount);
// this gets the error
console.log('sending second binary message');
ws.send(new Uint8Array(23085));
console.log('bufferedAmount is ' + ws.bufferedAmount);
console.log('sending third binary message');
ws.send(new Uint8Array(23085));
console.log('bufferedAmount is ' + ws.bufferedAmount);
ws.close();
}
https://jsfiddle.net/yta2mjuf/2/
第二條消息得到一個錯誤關閉連接,第三個消息後,bufferedAmount
是23093.
我在這裏提交了一個關於WebKit的bug:https://bugs.webkit.org/show_bug.cgi?id=170463 –
我們遇到了同樣的問題。我們的門檻似乎是UInt8Array的緩衝區(23085);更大的東西,我們看到相同的錯誤。 (我們也看到bufferedAmount總是報告0)。對不起現在不能有更多的幫助 - 不知道這是一個Safari錯誤還是一些新的安全問題。 – MikeB
同樣在我們身邊,等待修復... –