Skip to content

Commit 7f43ba8

Browse files
fix(ui): Improve terminal data channel handling for cross-browser compatibility (#210)
- Add support for different binary data types (ArrayBuffer and Blob) - Implement FileReader for converting Blob data in Firefox - Send initial terminal size on data channel open
1 parent b499482 commit 7f43ba8

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

ui/src/components/Terminal.tsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,23 @@ function Terminal({
8484
if (readyState !== "open") return;
8585

8686
const abortController = new AbortController();
87+
const binaryType = dataChannel.binaryType;
8788
dataChannel.addEventListener(
8889
"message",
8990
e => {
90-
instance?.write(new Uint8Array(e.data));
91+
// Handle binary data differently based on browser implementation
92+
// Firefox sends data as blobs, chrome sends data as arraybuffer
93+
if (binaryType === "arraybuffer") {
94+
instance?.write(new Uint8Array(e.data));
95+
} else if (binaryType === "blob") {
96+
const reader = new FileReader();
97+
reader.onload = () => {
98+
if (!instance) return;
99+
if (!reader.result) return;
100+
instance.write(new Uint8Array(reader.result as ArrayBuffer));
101+
};
102+
reader.readAsArrayBuffer(e.data);
103+
}
91104
},
92105
{ signal: abortController.signal },
93106
);
@@ -106,6 +119,11 @@ function Terminal({
106119
}
107120
});
108121

122+
// Send initial terminal size
123+
if (dataChannel.readyState === "open") {
124+
dataChannel.send(JSON.stringify({ rows: instance?.rows, cols: instance?.cols }));
125+
}
126+
109127
return () => {
110128
abortController.abort();
111129
onDataHandler?.dispose();

0 commit comments

Comments
 (0)