diff --git a/src/bun.js/bindings/ZigGlobalObject.cpp b/src/bun.js/bindings/ZigGlobalObject.cpp index 6398fb7a09c0e..a75c3f821f316 100644 --- a/src/bun.js/bindings/ZigGlobalObject.cpp +++ b/src/bun.js/bindings/ZigGlobalObject.cpp @@ -3075,11 +3075,21 @@ void GlobalObject::finishCreation(VM& vm) JSC::Identifier userAgentIdentifier = JSC::Identifier::fromString(init.vm, "userAgent"_s); JSC::Identifier hardwareConcurrencyIdentifier = JSC::Identifier::fromString(init.vm, "hardwareConcurrency"_s); - JSC::JSObject* obj = JSC::constructEmptyObject(init.owner, init.owner->objectPrototype(), 3); + JSC::JSObject* obj = JSC::constructEmptyObject(init.owner, init.owner->objectPrototype(), 4); obj->putDirect(init.vm, userAgentIdentifier, JSC::jsString(init.vm, str)); obj->putDirect(init.vm, init.vm.propertyNames->toStringTagSymbol, jsNontrivialString(init.vm, "Navigator"_s), JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::ReadOnly); +// https://developer.mozilla.org/en-US/docs/Web/API/Navigator/platform +// https://github.com/oven-sh/bun/issues/4588 +#if OS(DARWIN) + obj->putDirect(init.vm, JSC::Identifier::fromString(init.vm, "platform"_s), JSC::jsString(init.vm, "MacIntel"_s)); +#elif OS(WINDOWS) + obj->putDirect(init.vm, JSC::Identifier::fromString(init.vm, "platform"_s), JSC::jsString(init.vm, "Win32"_s)); +#else if OS(LINUX) + obj->putDirect(init.vm, JSC::Identifier::fromString(init.vm, "platform"_s), JSC::jsString(init.vm, "Linux x86_64"_s)); +#endif + obj->putDirect(init.vm, hardwareConcurrencyIdentifier, JSC::jsNumber(cpuCount)); init.set( obj); diff --git a/test/js/web/web-globals.test.js b/test/js/web/web-globals.test.js index 9b4c860067a66..5e666f2087fbb 100644 --- a/test/js/web/web-globals.test.js +++ b/test/js/web/web-globals.test.js @@ -224,4 +224,11 @@ test("navigator", () => { const userAgent = `Bun/${version}`; expect(navigator.hardwareConcurrency > 0).toBe(true); expect(navigator.userAgent).toBe(userAgent); + if (process.platform === "darwin") { + expect(navigator.platform).toBe("MacIntel"); + } else if (process.platform === "win32") { + expect(navigator.platform).toBe("Win32"); + } else if (process.platform === "linux") { + expect(navigator.platform).toBe("Linux"); + } });