Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't rely on getHighEntropyValues to detect Apple Silicon #732

Open
kkuepper opened this issue Jun 12, 2024 · 2 comments
Open

don't rely on getHighEntropyValues to detect Apple Silicon #732

kkuepper opened this issue Jun 12, 2024 · 2 comments

Comments

@kkuepper
Copy link

kkuepper commented Jun 12, 2024

Is your feature request related to a problem? Please describe.
isAppleSilicon() is not returning the expected result on Firefox and Safari.

Describe the solution you'd like
Instead of relying on getHighEntropyValues, it's testing if WebGL is working as described on StackOverflow

Describe alternatives you've considered
Currently we're using the following code instead of ua-parser-js implementation:

function isAppleSilicon() {
  try {
    // Best guess if the device uses Apple Silicon: https://stackoverflow.com/a/65412357
    const w = document.createElement("canvas").getContext("webgl");
    if (w == null) {
      return false;
    }
    const d = w.getExtension("WEBGL_debug_renderer_info");
    const g = (d && w.getParameter(d.UNMASKED_RENDERER_WEBGL)) || "";
    if (g.match(/Apple/) && !g.match(/Apple GPU/)) {
      return true;
    }

    if (
      // @ts-expect-error - Object is possibly 'null'
      w.getSupportedExtensions().includes("WEBGL_compressed_texture_s3tc_srgb")
    ) {
      return true;
    }
  } catch {
    return false;
  }

  return false;
}

Additional context
I tested the above solution on Safari, Firefox and Chrome on M1 Mac. I didn't test on non-Apple Silicon though.

@SubJunk
Copy link

SubJunk commented Jun 22, 2024

I confirm this bug. This is a screenshot from https://uaparser.dev in Firefox on macOS with M1. The CPU field is empty. It also incorrectly displays the OS version as v10.15 when I am using v14.2.1:

image

@faisalman
Copy link
Owner

Thanks for the report @kkuepper @SubJunk

In the linked StackOverflow answer, the latest comment mentioned that the WEBGL_compressed_texture_s3tc_srgb extension doesn't seem to be missing anymore in his M1.

Thus it leaves us with this only WebGL renderer check:

if (g.match(/Apple/) && !g.match(/Apple GPU/)) {

Is there a chance that it would return true on any Intel-based Apple device? If not, I would be happy to add this check as well to the existing isAppleSilicon().

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

No branches or pull requests

3 participants