Skip to content

Commit 830e1c5

Browse files
authored
Merge pull request #618 from MiyamuraMiyako/main
Check webui.js load hostname and connect to it.
2 parents ffb235a + 90b077b commit 830e1c5

File tree

3 files changed

+738
-700
lines changed

3 files changed

+738
-700
lines changed

bridge/webui.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,12 @@ class WebuiBridge {
537537
}
538538
}
539539
}
540+
#getScriptUrl() {
541+
const scripts = Array.from(document.scripts)
542+
.filter(s => s.src !== null && s.src.startsWith('http') && s.src.endsWith('webui.js'))
543+
.map(s => s.src);
544+
return scripts.length === 0 ? null : new URL(scripts[0]);
545+
}
540546
#callPromise(fn: string, ...args: DataTypes[]) {
541547
--this.#callPromiseID[0];
542548
const callId = this.#toUint16(this.#callPromiseID[0]);
@@ -609,7 +615,8 @@ class WebuiBridge {
609615
this.#ws.close();
610616
}
611617
this.#TokenAccepted = false;
612-
const host = window.location.hostname;
618+
const scriptUrl = this.#getScriptUrl();
619+
const host = scriptUrl !== null ? scriptUrl.hostname : window.location.hostname;
613620
const url = this.#secure ? ('wss://' + host) : ('ws://' + host);
614621
this.#ws = new WebSocket(`${url}:${this.#port}/_webui_ws_connect`);
615622
this.#ws.binaryType = 'arraybuffer';

0 commit comments

Comments
 (0)