node icon indicating copy to clipboard operation
node copied to clipboard

lib: add `navigator.hardwareConcurrency`

Open anonrig opened this issue 1 year ago • 20 comments

I'm following up on an abandoned pull request, and adding authors as the co-author to this pull request.

I've simplified and only added navigator.hardwareConcurrency right now, to receive feedback, understand any blockers before investing more time on it.

Referencing issue: https://github.com/nodejs/node/issues/39540 Follow up of the pull request: https://github.com/nodejs/node/pull/39581

anonrig avatar Apr 28 '23 16:04 anonrig

Review requested:

  • [ ] @nodejs/startup

nodejs-github-bot avatar Apr 28 '23 16:04 nodejs-github-bot

I'm +1 on this now but I'm sure there are details to work through.

jasnell avatar Apr 28 '23 17:04 jasnell

navigator.platform is a deprecated API. If we are adding the Navigator interface we probably should start with something that's not deprecated...The value of navigator.platform is also unspecified, I wonder how useful this could be if we are still returning something different from what browsers do (and then browsers also disagree among themselves).

joyeecheung avatar Apr 28 '23 23:04 joyeecheung

If we don't do navigator.platform (which is fine) ... let's start with navigator.userAgent, which is defined as part of the WinterCG minimal (https://common-min-api.proposal.wintercg.org/)

jasnell avatar Apr 28 '23 23:04 jasnell

navigator.platform isn't deprecated in the spec, only on MDN. I'm pretty sure it's only deprecated there to discourage people from using it (see the note). Also +1 on starting with or adding userAgent.

KhafraDev avatar Apr 28 '23 23:04 KhafraDev

I'll update this pull request with userAgent.

anonrig avatar Apr 29 '23 00:04 anonrig

As I said in the original PR and in multiple related issues, I still think most of the Navigator interface makes little sense for Node.js. It's part of the HTML spec and only exposed there on the window object, which happens to correspond to the global scope.

tniessen avatar Apr 29 '23 11:04 tniessen

I don't think we should be adding navigator to Node.js. The majorjty of its API are very browser specific that does not match Node.js use case.

I don't have any issues in the readonly properties or navigator, but I'm failing to understand the use case of only limiting to those.

@mcollina I didn't understand. Are you blocking this PR because it includes navigator or because of navigator.platform? Will you unblock if it only included navigator.userAgent stated in the WinterCG Minimum Common Web Platform API?

anonrig avatar May 01 '23 16:05 anonrig

I would not block navigator.userAgent

mcollina avatar May 02 '23 10:05 mcollina

The HTML spec https://html.spec.whatwg.org/multipage/system-state.html#client-identification states that:

Warning: Any information in this API that varies from user to user can be used to profile the user. In fact, if enough such information is available, a user can actually be uniquely identified. For this reason, user agent implementers are strongly urged to include as little information in this API as possible.

Is there any use case for Node.js to implement a less precise API when more accurate APIs are available to retrieve this information?

legendecas avatar May 04 '23 06:05 legendecas

MDN documentation say:

A Navigator object can be retrieved using the read-only window.navigator property.

IMHO Node does not have a window object, so it should not provide a Navigator object via globalThis.

sosoba avatar Jun 02 '23 07:06 sosoba

window is synonymous with globalThis, globalThis.navigator is the same as window.navigator with a few more characters.

KhafraDev avatar Jun 02 '23 13:06 KhafraDev

@mcollina:

I don't think we should add navigator to Node.js

I rarely disagree with Matteo but in this case I have to ;-) There are several APIs exposed via navigator that are or could be relevant to Node.js, for instance:

  • navigator.hardwareConcurrency
  • navigator.locks
  • navigator.userAgent
  • navigator.userAgentData
  • navigator.sendBeacon()
  • navigator.gpu

One could fairly easily come up with very valid use cases for these in Node.js.

jasnell avatar Jun 03 '23 17:06 jasnell

I converted the pull request to use a less debatable attribute, in order to introduce navigator object. Appreciate reviewing it again @mcollina and @nodejs/tsc

anonrig avatar Jun 03 '23 17:06 anonrig

@nodejs/tsc I've added a tsc-agenda label, to ask for concensus regarding navigator global class, and later resolve or close this pull request.

anonrig avatar Jun 12 '23 18:06 anonrig

Is there any expectation that if one part of the api is included that other parts will be as well?

mhdawson avatar Jun 21 '23 15:06 mhdawson

I was thinking that if we land this, we should (of course) do it in a semver major, but also mark it as experimental to signal that we might remove it if it causes breakage. (Removing it otherwise would also be semver major.) I know this gets into the whole "experimental features that aren't behind a flag aren't really experimental" discussion, but I want to signal that we might remove it in a patch or minor release, and labeling it experimental seems to be the way to do that.

@cjihrig noted that Deno already has navigator so using the presence of navigator to detect if you're running in a browser doesn't work if you support Deno. That mitigates my concern about adding navigator breaking code for people who use its presence to detect if they are in a browser or not.

@MoLow mentioned that we should definitely run CITGM before landing this (which we are supposed to do for all semver major PRs) and I certainly agree with that.

Trott avatar Jun 21 '23 15:06 Trott

I was thinking that if we land this, we should (of course) do it in a semver major, but also mark it as experimental to signal that we might remove it if it causes breakage.

And let’s please start using the experimental stages for all new experimental features: https://nodejs.org/api/documentation.html#stability-index. That would better inform users how we feel about the API.

If it’s a low stage, that might suggest we should add a flag or at least a warning.

GeoffreyBooth avatar Jun 21 '23 16:06 GeoffreyBooth

CITGM: https://ci.nodejs.org/view/Node.js-citgm/job/citgm-smoker/3175/

anonrig avatar Jun 21 '23 17:06 anonrig

CI: https://ci.nodejs.org/job/node-test-pull-request/52329/

nodejs-github-bot avatar Jun 21 '23 19:06 nodejs-github-bot

@aduh95 do you have any suggestions for the build errors?

anonrig avatar Jun 24 '23 00:06 anonrig

CI: https://ci.nodejs.org/job/node-test-pull-request/52436/

nodejs-github-bot avatar Jun 24 '23 20:06 nodejs-github-bot

CI: https://ci.nodejs.org/job/node-test-pull-request/52442/

nodejs-github-bot avatar Jun 24 '23 22:06 nodejs-github-bot

CI: https://ci.nodejs.org/job/node-test-pull-request/52443/

nodejs-github-bot avatar Jun 24 '23 23:06 nodejs-github-bot

@nodejs/platform-windows Can you help me identify the issue behind the failing tests on node-test-commit-windows-fanned?

anonrig avatar Jun 25 '23 22:06 anonrig

CI: https://ci.nodejs.org/job/node-test-pull-request/52529/

nodejs-github-bot avatar Jun 27 '23 21:06 nodejs-github-bot

Dear reviewers, appreciate a review to land this pull request. cc @mcollina @ronag

anonrig avatar Jun 28 '23 15:06 anonrig

@nodejs/tsc ping

anonrig avatar Jul 03 '23 16:07 anonrig

Landed in b40f0c30743aaecd57071f7be305df43e1083817

nodejs-github-bot avatar Jul 04 '23 22:07 nodejs-github-bot

The https://github.com/nodejs/node/labels/notable-change label has been added by @anonrig.

Please suggest a text for the release notes if you'd like to include a more detailed summary, then proceed to update the PR description with the text or a link to the notable change suggested text comment.

github-actions[bot] avatar Oct 16 '23 16:10 github-actions[bot]