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>
This commit is contained in:
Innei 2024-11-06 20:09:10 +08:00 committed by GitHub
parent e9afc7944f
commit c8d1230be7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 63 additions and 31 deletions

View File

@ -4,38 +4,21 @@
<script type="module">
const host = "https://localhost:2233"
globalThis["__DEBUG_PROXY__"] = true
fetch(`${host}`)
.then((res) => res.text())
.then((html) => {
const parser = new DOMParser()
const doc = parser.parseFromString(html, "text/html")
document.head.innerHTML = doc.head.innerHTML
document.body.innerHTML = doc.body.innerHTML
const scripts = doc.querySelectorAll("script")
scripts.forEach((script) => {
const $script = document.createElement("script")
$script.type = "module"
$script.crossOrigin = script.crossOrigin
if (script.src) {
$script.src = script.src
} else if (script.innerHTML) {
$script.innerHTML = script.innerHTML
} else {
return
}
document.body.appendChild($script)
})
scripts.forEach((script) => {
script.remove()
})
})
const createRefreshRuntimeScript = `
import RefreshRuntime from "${host}/@react-refresh";
RefreshRuntime.injectIntoGlobalHook(window);
window.$RefreshReg$ = () => {};
window.$RefreshSig$ = () => (type) => type;
window.__vite_plugin_react_preamble_installed__ = true;
`
const $script = document.createElement("script")
$script.innerHTML = createRefreshRuntimeScript
$script.type = "module"
document.head.appendChild($script)
</script>
<title>Debug Proxy</title>
<script type="module" src="./__debug_proxy.ts"></script>
</head>
<body></body>
</html>

View File

@ -0,0 +1,49 @@
const host = "https://localhost:2233"
globalThis["__DEBUG_PROXY__"] = true
fetch(`${host}`)
.then((res) => res.text())
.then((html) => {
const parser = new DOMParser()
const doc = parser.parseFromString(html, "text/html")
const scripts = doc.querySelectorAll("script")
scripts.forEach((script) => {
script.remove()
})
// header meta
const $meta = doc.head.querySelectorAll("meta")
$meta.forEach((meta) => {
document.head.append(meta)
})
const $style = doc.head.querySelectorAll("style")
$style.forEach((style) => {
document.head.append(style)
})
document.body.innerHTML = doc.body.innerHTML
scripts.forEach((script) => {
const $script = document.createElement("script")
$script.type = "module"
$script.crossOrigin = script.crossOrigin
if (script.src) {
$script.src = new URL(
script.src.startsWith("http") ? new URL(script.src).pathname : script.src,
host,
).toString()
} else if (script.innerHTML) {
$script.innerHTML = script.innerHTML
} else {
return
}
document.body.append($script)
})
})