Skip to content

Conversation

@sigmaSd
Copy link
Contributor

@sigmaSd sigmaSd commented Sep 20, 2025

Fix #24117

This seems not like the correct approach ( importing node), but its the easiest way and I thought maybe its a good start for instructions on how to add this

I just copied https://github.com/nodejs/node/blob/main/lib/internal/navigator.js#L41

Also there seems to be a test here https://github.com/denoland/node_test/blob/main/test/parallel/test-navigator.js#L35 how do I activate it ?

@Hajime-san
Copy link
Contributor

Hajime-san commented Sep 21, 2025

I think it needs to be consistent with Deno.build.os, setting aside compatibility with Node.js.

os:
| "darwin"
| "linux"
| "android"
| "windows"
| "freebsd"
| "netbsd"
| "aix"
| "solaris"
| "illumos";

@sigmaSd
Copy link
Contributor Author

sigmaSd commented Sep 21, 2025

But the spec names them differently (what node does) https://developer.mozilla.org/en-US/docs/Web/API/Navigator/platform#value

@sigmaSd
Copy link
Contributor Author

sigmaSd commented Sep 21, 2025

Though I guess the spec says "for example" so maybe its ok with Deno values ?

@Hajime-san
Copy link
Contributor

Yeah, it's better to use values ​​that match other runtimes.
You can use core.build instead of node:process.

build: core.build,

https://github.com/denoland/deno_core/blob/2770aa8f18800b0a4a997954e9482205764fea97/core/00_infra.js#L58-L78

Copy link
Contributor

@iuioiua iuioiua left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do types need to be adjusted somewhere too?

* @param {string} platform
* @returns {string}
*/
function getNavigatorPlatform(arch, platform) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use a switch statement?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@sigmaSd
Copy link
Contributor Author

sigmaSd commented Sep 21, 2025

I updated the code to use core.build

I'm not sure what other changes are needed

@bartlomieju bartlomieju added this to the 2.6.0 milestone Sep 23, 2025
@bartlomieju
Copy link
Member

I updated the code to use core.build

I'm not sure what other changes are needed

I'll make sure this is landed before 2.6.

@bartlomieju
Copy link
Member

@sigmaSd could you please rebase this one so it can get landed?

Copilot AI review requested due to automatic review settings November 17, 2025 09:22
Copilot finished reviewing on behalf of sigmaSd November 17, 2025 09:24
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for the navigator.platform property to Deno's runtime, addressing issue #24117. The implementation follows browser conventions by returning platform-specific strings that match modern browser behavior.

  • Implements getNavigatorPlatform() function that maps Deno's OS/architecture to browser-compatible platform strings
  • Adds navigator.platform property getter with proper Web IDL branding
  • Includes the new property in Navigator's custom inspect output

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


default:
return `${StringPrototypeToUpperCase(platform[0])}${
StringPrototypeSlice(platform, 1)
Copy link

Copilot AI Nov 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StringPrototypeSlice is used on line 57 but is not imported from primordials. Add it to the destructuring assignment on line 13:

const {
  ObjectDefineProperties,
  ObjectPrototypeIsPrototypeOf,
  SymbolFor,
  StringPrototypeToUpperCase,
  StringPrototypeSlice,
} = primordials;

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot open a new pull request to apply changes based on this feedback

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why a separate pr?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just pressed the implement change button thought it will just change the code

I'll update this

Comment on lines +55 to +58
default:
return `${StringPrototypeToUpperCase(platform[0])}${
StringPrototypeSlice(platform, 1)
} ${arch}`;
Copy link

Copilot AI Nov 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default case doesn't check if platform is empty before accessing platform[0], which could cause an error. Additionally, openbsd and android are valid OS values in Deno (found in repo/ext/fs/30_fs.js) but are not explicitly handled and would fall through to the default case. Consider adding explicit cases for these OSes:

case "openbsd":
  return `OpenBSD ${arch}`;

case "android":
  return `Linux ${arch}`; // Android typically reports as Linux
Suggested change
default:
return `${StringPrototypeToUpperCase(platform[0])}${
StringPrototypeSlice(platform, 1)
} ${arch}`;
case "openbsd":
return `OpenBSD ${arch}`;
case "android":
return `Linux ${arch}`; // Android typically reports as Linux
default:
if (typeof platform === "string" && platform.length > 0) {
return `${StringPrototypeToUpperCase(platform[0])}${
StringPrototypeSlice(platform, 1)
} ${arch}`;
} else {
return arch || "Unknown";
}

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems logical but I just copy pasted the node implementation, should I apply this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, platform is never an empty string. if it is, we dont support that system anyways

@coderabbitai
Copy link

coderabbitai bot commented Nov 19, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Adds a Navigator.platform getter that returns a platform string computed from runtime architecture and OS via a new getNavigatorPlatform(arch, platform) helper and a memoized value. Updates Navigator inspection to include the new platform key. Introduces a unit test verifying navigator.platform across Linux, macOS, and Windows, and adds the corresponding test entry to the node compatibility test configuration.

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: add navigator.platform' clearly and directly describes the main change—adding a new Navigator.platform property to Deno.
Description check ✅ Passed The description references the linked issue #24117 and explains the implementation approach, though it raises concerns about the initial method (importing Node) that were later addressed.
Linked Issues check ✅ Passed The PR successfully implements navigator.platform support in Deno, fulfilling the primary objective from issue #24117 to enable cross-runtime platform detection.
Out of Scope Changes check ✅ Passed All changes are in-scope: runtime implementation, TypeScript declarations, unit tests, and node compatibility test configuration all directly support adding navigator.platform.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d4aacce and be5c875.

📒 Files selected for processing (2)
  • cli/tsc/dts/lib.dom.d.ts (1 hunks)
  • tests/unit/globals_test.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/unit/globals_test.ts
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx,js}: For JavaScript runtime debugging, enable V8 inspector with --inspect-brk flag and connect Chrome DevTools to chrome://inspect
Use console.log() for debug prints in JavaScript runtime code

Files:

  • cli/tsc/dts/lib.dom.d.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: lint debug windows-x86_64
  • GitHub Check: test debug linux-aarch64
  • GitHub Check: test debug linux-x86_64
  • GitHub Check: test debug windows-x86_64
  • GitHub Check: test release linux-x86_64
  • GitHub Check: test debug macos-x86_64
  • GitHub Check: test debug macos-aarch64
  • GitHub Check: lint debug linux-x86_64
  • GitHub Check: lint debug macos-x86_64
  • GitHub Check: build libs
🔇 Additional comments (1)
cli/tsc/dts/lib.dom.d.ts (1)

21424-21429: LGTM!

The type declaration follows the established pattern in this file and correctly matches the Web API specification for Navigator.platform. The JSDoc documentation with MDN reference is properly formatted.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
runtime/js/98_global_scope_window.js (1)

25-61: getNavigatorPlatform logic and memoization look sound; consider clearer naming

The platform computation mirrors established runtime behavior for major OSes (darwinMacIntel, windowsWin32, etc.) and uses memoizeLazy consistently with userAgent and language. Using core.build.arch and core.build.os is in line with the earlier review guidance to avoid importing Node internals, and the function always returns a string, so caching with a null sentinel is safe.

As a minor readability tweak, both the parameter platform in getNavigatorPlatform(arch, platform) and the top-level const platform = memoizeLazy(...) are named identically, which can be a bit confusing when scanning the file. Renaming one of them (e.g., os / osName in the helper, or navigatorPlatform for the memoized value) would make it easier to distinguish between the OS identifier and the computed navigator.platform string.

-function getNavigatorPlatform(arch, platform) {
-  switch (platform) {
+function getNavigatorPlatform(arch, osName) {
+  switch (osName) {
@@
-    default:
-      return `${StringPrototypeToUpperCase(platform[0])}${
-        StringPrototypeSlice(platform, 1)
-      } ${arch}`;
+    default:
+      return `${StringPrototypeToUpperCase(osName[0])}${
+        StringPrototypeSlice(osName, 1)
+      } ${arch}`;
   }
 }
@@
-const platform = memoizeLazy(() =>
-  getNavigatorPlatform(core.build.arch, core.build.os)
-);
+const navigatorPlatform = memoizeLazy(() =>
+  getNavigatorPlatform(core.build.arch, core.build.os)
+);

(plus updating the getter below to call navigatorPlatform() instead of platform()).

Also applies to: 101-103

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8c61416 and b03d091.

📒 Files selected for processing (1)
  • runtime/js/98_global_scope_window.js (5 hunks)
🔇 Additional comments (3)
runtime/js/98_global_scope_window.js (3)

13-15: Primordials additions correctly cover new string operations

Importing StringPrototypeToUpperCase and StringPrototypeSlice from primordials matches how other helpers in this file are sourced and resolves the prior missing-import concern cleanly. No issues from a correctness or style perspective.


78-78: Including "platform" in the custom inspect keys is consistent

Adding "platform" to the filtered inspect proxy keys keeps navigator’s developer-facing representation in sync with the new property, matching how hardwareConcurrency, userAgent, and language are exposed.


153-161: Navigator.platform getter wiring matches existing patterns; ensure type defs align

The new platform descriptor is consistent with the other navigator properties: branded via webidl.assertBranded, enumerable, configurable, and backed by the memoized function. This should integrate cleanly with the rest of the runtime initialization.

One follow-up to double-check outside this file: make sure the corresponding TypeScript/lib definitions for Navigator (e.g., in lib.deno.ns.d.ts or related Web IDL bindings) now include platform: string, so users get proper typing and cross-runtime parity.

@sigmaSd
Copy link
Contributor Author

sigmaSd commented Nov 19, 2025

It seems like I need to update a test , but its not clear to me where exactly I need to make the change

@bartlomieju
Copy link
Member

Errors raised here, make no sense. I think cache is broken or this PR is getting assigned to a specific runner

@bartlomieju
Copy link
Member

Also there seems to be a test here https://github.com/denoland/node_test/blob/main/test/parallel/test-navigator.js#L35 how do I activate it ?

@sigmaSd you need to specify it in tests/node_compat/config.toml. It would be nice to have a small unit test too - eg. in tests/unit/globals_test.js.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
tests/unit/globals_test.ts (1)

236-252: navigatorPlatformExists test is good; consider asserting on other OSes too

The OS-specific expectations for Linux, macOS, and Windows look correct and align with the new navigator.platform behavior. One small improvement: on other Deno.build.os values this test currently does nothing, so regressions there would go unnoticed. You could add a default branch that at least asserts typeof navigator.platform === "string" (or similar) to keep the test meaningful if more platforms are supported later.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b03d091 and 9f1f37c.

📒 Files selected for processing (2)
  • tests/node_compat/config.toml (1 hunks)
  • tests/unit/globals_test.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx,js}: For JavaScript runtime debugging, enable V8 inspector with --inspect-brk flag and connect Chrome DevTools to chrome://inspect
Use console.log() for debug prints in JavaScript runtime code

Files:

  • tests/unit/globals_test.ts
🧬 Code graph analysis (1)
tests/unit/globals_test.ts (1)
runtime/js/98_global_scope_window.js (1)
  • navigator (86-86)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: test release linux-x86_64
  • GitHub Check: test debug macos-x86_64
  • GitHub Check: test debug linux-aarch64
  • GitHub Check: test debug linux-x86_64
  • GitHub Check: test debug windows-x86_64
  • GitHub Check: test debug macos-aarch64
  • GitHub Check: lint debug windows-x86_64
  • GitHub Check: lint debug macos-x86_64
  • GitHub Check: lint debug linux-x86_64
  • GitHub Check: build libs
🔇 Additional comments (1)
tests/node_compat/config.toml (1)

770-770: Node-compat navigator test correctly enabled

Adding "parallel/test-navigator.js" = {} here is the right way to wire the Node navigator test into the compat suite; placement and config look consistent with surrounding entries.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
tests/unit/globals_test.ts (1)

237-255: Handle future Deno.build.os values explicitly in the test

The test covers Linux/macOS/Windows, but if Deno.build.os ever gains another value, this test will silently do nothing. Adding a default branch will make sure new platforms are intentionally handled.

 Deno.test(function navigatorPlatformExists() {
   switch (Deno.build.os) {
@@
     case "windows": {
       // deno-lint-ignore no-undef
       assertEquals(navigator.platform, "Win32");
       break;
     }
+    default: {
+      throw new Error(`Unhandled Deno.build.os: ${Deno.build.os}`);
+    }
   }
 });
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9f1f37c and d4aacce.

📒 Files selected for processing (1)
  • tests/unit/globals_test.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx,js}: For JavaScript runtime debugging, enable V8 inspector with --inspect-brk flag and connect Chrome DevTools to chrome://inspect
Use console.log() for debug prints in JavaScript runtime code

Files:

  • tests/unit/globals_test.ts
🧬 Code graph analysis (1)
tests/unit/globals_test.ts (1)
runtime/js/98_global_scope_window.js (1)
  • navigator (86-86)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: test release linux-x86_64
  • GitHub Check: test debug linux-x86_64
  • GitHub Check: test debug linux-aarch64
  • GitHub Check: test debug macos-aarch64
  • GitHub Check: test debug macos-x86_64
  • GitHub Check: test debug windows-x86_64
  • GitHub Check: lint debug windows-x86_64
  • GitHub Check: build libs
  • GitHub Check: lint debug macos-x86_64
  • GitHub Check: lint debug linux-x86_64

@sigmaSd
Copy link
Contributor Author

sigmaSd commented Dec 5, 2025

I added platform type to lib.dom but it still error in type checking saying it doesn't exist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add navigator.platform

5 participants