When using the built-in browser in Microsoft's new Teams, is there a way to tell whether it is desktop app Teams or browser Teams in the built-in browser?

임 소은 20 Reputation points
2023-09-15T07:12:20.3033333+00:00

In the built-in browser of apps connected to existing Electron Teams, there was an Electron value in window.userAgent to distinguish between browser Teams and app Teams.

However, when connecting to the built-in browser in the new Teams implemented with WebView2, the window.userAgent value is displayed the same as the Edge browser, so it is not possible to distinguish between app Teams and browser Teams.

Is there a way to distinguish between browser Teams and app Teams in WebView2 new Teams?

Microsoft Teams
Microsoft Teams
A Microsoft customizable chat-based workspace.
9,059 questions
Microsoft Teams Development
Microsoft Teams Development
Microsoft Teams: A Microsoft customizable chat-based workspace.Development: The process of researching, productizing, and refining new or existing technologies.
2,841 questions
{count} votes

Accepted answer
  1. Sayali-MSFT 2,266 Reputation points Microsoft Vendor
    2023-09-20T10:48:24.6233333+00:00

    Hi @임 소은- Yes, there is a way to determine whether the built-in browser in Microsoft Teams is being used in the desktop app or in a web browser. You can use the microsoftTeams.getContext method to retrieve the context of the Teams client.

    The microsoftTeams.getContext method returns an object that contains information about the current context, including the hostClientType property. The hostClientType property indicates whether the Teams client is running in the desktop app or in a web browser.

    Here is an example of how you can use the microsoftTeams.getContext method to determine the host client type:

    microsoftTeams.getContext(function(context) {
      var hostClientType = context.hostClientType;
      
      if (hostClientType === "desktop") {
        console.log("Teams is running in the desktop app.");
      } else if (hostClientType === "web") {
        console.log("Teams is running in a web browser.");
      } else {
        console.log("Unable to determine the host client type.");
      }
    });
    

    In the example above, the hostClientType property is checked to determine whether Teams is running in the desktop app or in a web browser. You can then perform different actions or display different content based on the host client type.

    For more information about the microsoftTeams.getContext method and the available properties, you can refer to the Microsoft Teams JavaScript SDK documentation.


0 additional answers

Sort by: Most helpful