Skip to content

Automatically detect Tauri v1/v2 #16142

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

Closed
rodolfoBee opened this issue Apr 28, 2025 · 8 comments
Closed

Automatically detect Tauri v1/v2 #16142

rodolfoBee opened this issue Apr 28, 2025 · 8 comments

Comments

@rodolfoBee
Copy link
Member

Problem Statement

When using Sentry within a Tauri application, what gets detected from the user agent is somewhat misleading, e.g. Ubuntu/Safari. While not exactly false, since it is using gtk-webkit, it is not telling the whole story, so I think it would be a nice feature to detect the tauri version and platform instead.

Solution Brainstorm

To detect Tauri v1, you just have to look if window.TAURI is present; for v2, it is window.TAURI_INTERNALS. Tauri v1 supports Linux/Ubuntu, MacOS X and Windows. Tauri v2 additionally supports Android and iOS.

So instead of Ubuntu/Safari, it would be great to see Ubuntu/Tauri in the future.

Original request from Zendesk.

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Apr 28, 2025
@mydea
Copy link
Member

mydea commented Apr 28, 2025

So which "field" should become Tauri? The browser? is there a version?

@timfish
Copy link
Collaborator

timfish commented Apr 29, 2025

My guess is that the web views used across each platform result in a user agent that results in a strange browser or device to be listed.

For example the web view in Tauri on macOS results in the client being listed as something like "Apple Mail". This is probably caused by whatever library Sentry uses for user agent parsing.

@alex-crabnebula
Copy link

Tauri should be the browser, since it actual engine is apparent from the combination (Ubuntu = webkit-gtk, MacOS = webkit, Windows = blink-edge). A future version might ship with a Servo engine, but that is still WIP.

Unfortunately, the information from my mail was pasted directly into markdown, so the information was mangled. The properties are window.__TAURI__ and window.__TAURI_INTERNALS__.

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Apr 30, 2025
@timfish
Copy link
Collaborator

timfish commented Apr 30, 2025

Can you get a Tauri version from window.__TAURI__ or window.__TAURI_INTERNALS__?

@timfish
Copy link
Collaborator

timfish commented Apr 30, 2025

You can currently inject this data into events via beforeSend:

Sentry.init({
  dsn: '__DSN__',
  beforeSend(event) {
    if('__TAURI__' in window || '__TAURI_INTERNALS__' in window) {
      event.contexts = {
        ...event.contexts,
        runtime: {
          name: 'Tauri',
          // You might be able to set a version or other data here
          // version: (window.__TAURI__ || window__TAURI_INTERNALS__).tauriVersion,
        },
      };
      // You might need to remove the User-Agent header so Sentry doesn't auto detect the browser
      // This might break platform detection though, needs testing... 🤔
      if (event?.request?.headers?.['User-Agent']) {
        delete event.request.headers['User-Agent'];
      }
    }
    return event;
  },
});

@alex-crabnebula
Copy link

That is indeed a nice workaround. I guess a default behavior would be nice.

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Apr 30, 2025
@AbhiPrasad
Copy link
Member

I think we should write up a quick guide somewhere about adding tauri related tags (maybe GH discussion), and reference that in our docs, but I wouldn't make an SDK change to do this until we invest in a first-class Tauri SDK (which is a while away).

Going to close this issue as a result.

@AbhiPrasad AbhiPrasad closed this as not planned Won't fix, can't repro, duplicate, stale May 1, 2025
@alex-crabnebula
Copy link

Mentioning this in the docs is a solution, too. Thank you. I don't think we need a specialized Tauri SDK, since we can use both the JS and the Rust APIs all right. The ability to detect tauri is also solely interesting for isomorphic apps that run the same code within tauri and on the web.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

No branches or pull requests

5 participants