diff --git a/core/parcel-runtime/src/utils/0-patch-module.ts b/core/parcel-runtime/src/utils/0-patch-module.ts index 6153b0be3..a08883f8f 100644 --- a/core/parcel-runtime/src/utils/0-patch-module.ts +++ b/core/parcel-runtime/src/utils/0-patch-module.ts @@ -59,6 +59,14 @@ export function getHostname() { return runtimeData.host } +export function getSocketHostname() { + if (!runtimeData.host || runtimeData.host === "0.0.0.0") { + return "localhost"; + } + + return runtimeData.host +} + export function getPort() { return runtimeData.port || location.port } diff --git a/core/parcel-runtime/src/utils/inject-socket.ts b/core/parcel-runtime/src/utils/inject-socket.ts index 571383f95..d5d9f26ef 100644 --- a/core/parcel-runtime/src/utils/inject-socket.ts +++ b/core/parcel-runtime/src/utils/inject-socket.ts @@ -2,10 +2,10 @@ import { type BuildSocketEvent } from "@plasmo/framework-shared/build-socket/eve import { eLog, iLog, wLog } from "@plasmo/utils/logging" import type { HmrAsset, HmrMessage } from "../types" -import { getHostname, getPort, runtimeData } from "./0-patch-module" +import { getSocketHostname, getPort, runtimeData } from "./0-patch-module" function getBaseSocketUri(port = getPort()) { - const hostname = getHostname() + const hostname = getSocketHostname() const protocol = runtimeData.secure || (location.protocol === "https:" &&