Skip to content

Commit c8d1230

Browse files
authored
fix: debug proxy page (#1439)
* update Signed-off-by: Innei <tukon479@gmail.com> * test Signed-off-by: Innei <tukon479@gmail.com> * update Signed-off-by: Innei <tukon479@gmail.com> * update Signed-off-by: Innei <tukon479@gmail.com> * update Signed-off-by: Innei <tukon479@gmail.com> * update Signed-off-by: Innei <tukon479@gmail.com> * test Signed-off-by: Innei <tukon479@gmail.com> * fix Signed-off-by: Innei <tukon479@gmail.com> * update Signed-off-by: Innei <tukon479@gmail.com> --------- Signed-off-by: Innei <tukon479@gmail.com>
1 parent e9afc79 commit c8d1230

File tree

2 files changed

+63
-31
lines changed

2 files changed

+63
-31
lines changed

apps/renderer/__debug_proxy.html

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,21 @@
44
<script type="module">
55
const host = "https://localhost:2233"
66

7-
globalThis["__DEBUG_PROXY__"] = true
8-
9-
fetch(`${host}`)
10-
.then((res) => res.text())
11-
.then((html) => {
12-
const parser = new DOMParser()
13-
const doc = parser.parseFromString(html, "text/html")
14-
document.head.innerHTML = doc.head.innerHTML
15-
document.body.innerHTML = doc.body.innerHTML
16-
17-
const scripts = doc.querySelectorAll("script")
18-
scripts.forEach((script) => {
19-
const $script = document.createElement("script")
20-
$script.type = "module"
21-
$script.crossOrigin = script.crossOrigin
22-
23-
if (script.src) {
24-
$script.src = script.src
25-
} else if (script.innerHTML) {
26-
$script.innerHTML = script.innerHTML
27-
} else {
28-
return
29-
}
30-
31-
document.body.appendChild($script)
32-
})
33-
34-
scripts.forEach((script) => {
35-
script.remove()
36-
})
37-
})
7+
const createRefreshRuntimeScript = `
8+
import RefreshRuntime from "${host}/@react-refresh";
9+
RefreshRuntime.injectIntoGlobalHook(window);
10+
window.$RefreshReg$ = () => {};
11+
window.$RefreshSig$ = () => (type) => type;
12+
window.__vite_plugin_react_preamble_installed__ = true;
13+
`
14+
const $script = document.createElement("script")
15+
$script.innerHTML = createRefreshRuntimeScript
16+
$script.type = "module"
17+
document.head.appendChild($script)
3818
</script>
19+
20+
<title>Debug Proxy</title>
21+
<script type="module" src="./__debug_proxy.ts"></script>
3922
</head>
4023
<body></body>
4124
</html>

apps/renderer/__debug_proxy.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
const host = "https://localhost:2233"
2+
3+
globalThis["__DEBUG_PROXY__"] = true
4+
5+
fetch(`${host}`)
6+
.then((res) => res.text())
7+
.then((html) => {
8+
const parser = new DOMParser()
9+
const doc = parser.parseFromString(html, "text/html")
10+
11+
const scripts = doc.querySelectorAll("script")
12+
13+
scripts.forEach((script) => {
14+
script.remove()
15+
})
16+
17+
// header meta
18+
19+
const $meta = doc.head.querySelectorAll("meta")
20+
$meta.forEach((meta) => {
21+
document.head.append(meta)
22+
})
23+
24+
const $style = doc.head.querySelectorAll("style")
25+
$style.forEach((style) => {
26+
document.head.append(style)
27+
})
28+
29+
document.body.innerHTML = doc.body.innerHTML
30+
31+
scripts.forEach((script) => {
32+
const $script = document.createElement("script")
33+
$script.type = "module"
34+
$script.crossOrigin = script.crossOrigin
35+
36+
if (script.src) {
37+
$script.src = new URL(
38+
script.src.startsWith("http") ? new URL(script.src).pathname : script.src,
39+
host,
40+
).toString()
41+
} else if (script.innerHTML) {
42+
$script.innerHTML = script.innerHTML
43+
} else {
44+
return
45+
}
46+
47+
document.body.append($script)
48+
})
49+
})

0 commit comments

Comments
 (0)