Skip to content

Commit 9111005

Browse files
committed
fix: terminal serialization and isolation
1 parent 3ceac25 commit 9111005

9 files changed

Lines changed: 496 additions & 129 deletions

File tree

‎bun.lock‎

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,8 @@
8686
"overrides": {
8787
"@types/bun": "catalog:",
8888
"@types/node": "catalog:"
89+
},
90+
"patchedDependencies": {
91+
8992
}
9093
}

‎packages/desktop/bunfig.toml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[test]
2+
preload = ["./happydom.ts"]

‎packages/desktop/happydom.ts‎

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import { GlobalRegistrator } from "@happy-dom/global-registrator"
2+
3+
GlobalRegistrator.register()
4+
5+
const originalGetContext = HTMLCanvasElement.prototype.getContext
6+
// @ts-expect-error - we're overriding with a simplified mock
7+
HTMLCanvasElement.prototype.getContext = function (contextType: string, _options?: unknown) {
8+
if (contextType === "2d") {
9+
return {
10+
canvas: this,
11+
fillStyle: "#000000",
12+
strokeStyle: "#000000",
13+
font: "12px monospace",
14+
textAlign: "start",
15+
textBaseline: "alphabetic",
16+
globalAlpha: 1,
17+
globalCompositeOperation: "source-over",
18+
imageSmoothingEnabled: true,
19+
lineWidth: 1,
20+
lineCap: "butt",
21+
lineJoin: "miter",
22+
miterLimit: 10,
23+
shadowBlur: 0,
24+
shadowColor: "rgba(0, 0, 0, 0)",
25+
shadowOffsetX: 0,
26+
shadowOffsetY: 0,
27+
fillRect: () => {},
28+
strokeRect: () => {},
29+
clearRect: () => {},
30+
fillText: () => {},
31+
strokeText: () => {},
32+
measureText: (text: string) => ({ width: text.length * 8 }),
33+
drawImage: () => {},
34+
save: () => {},
35+
restore: () => {},
36+
scale: () => {},
37+
rotate: () => {},
38+
translate: () => {},
39+
transform: () => {},
40+
setTransform: () => {},
41+
resetTransform: () => {},
42+
createLinearGradient: () => ({ addColorStop: () => {} }),
43+
createRadialGradient: () => ({ addColorStop: () => {} }),
44+
createPattern: () => null,
45+
beginPath: () => {},
46+
closePath: () => {},
47+
moveTo: () => {},
48+
lineTo: () => {},
49+
bezierCurveTo: () => {},
50+
quadraticCurveTo: () => {},
51+
arc: () => {},
52+
arcTo: () => {},
53+
ellipse: () => {},
54+
rect: () => {},
55+
fill: () => {},
56+
stroke: () => {},
57+
clip: () => {},
58+
isPointInPath: () => false,
59+
isPointInStroke: () => false,
60+
getTransform: () => ({}),
61+
getImageData: () => ({
62+
data: new Uint8ClampedArray(0),
63+
width: 0,
64+
height: 0,
65+
}),
66+
putImageData: () => {},
67+
createImageData: () => ({
68+
data: new Uint8ClampedArray(0),
69+
width: 0,
70+
height: 0,
71+
}),
72+
} as unknown as CanvasRenderingContext2D
73+
}
74+
return originalGetContext.call(this, contextType as "2d", _options)
75+
}

‎packages/desktop/package.json‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
},
1717
"license": "MIT",
1818
"devDependencies": {
19+
"@happy-dom/global-registrator": "20.0.11",
1920
"@tailwindcss/vite": "catalog:",
2021
"@tsconfig/bun": "1.0.9",
22+
"@types/bun": "catalog:",
2123
"@types/luxon": "catalog:",
2224
"@types/node": "catalog:",
2325
"@typescript/native-preview": "catalog:",

0 commit comments

Comments
 (0)