title: Is there a way to tell if your app is running in Microsoft Teams
body: <p>I have a web app that needs to execute specific code if it is running in Microsoft Teams, however I haven't yet figured out if there is any way to tell if your app is running in teams. Any ideas or insight?</p>
  <p>edit:</p>
  <p>for anyone wondering we ended up using a combination of the two answers below, on app start it will check the url of the app to see if it contains &quot;/teams&quot;. The teams app is told specifically to point to {app_name}/teams, if this case is true it will run the following code block:</p>
  <pre><code>import * as microsoftTeams from '@microsoft/teams-js';
  
  
  if (window.location.pathname.includes('teams')) {
      microsoftTeams.initialize(() =&gt; {
        microsoftTeams.getContext(context =&gt; {
          store.dispatch(teamsDetected(context.hostClientType!));
          try {
            microsoftTeams.settings.registerOnSaveHandler(saveEvent =&gt; {
              microsoftTeams.settings.setSettings({
                websiteUrl: window.location.href,
                contentUrl: `${window.location.href}&amp;teams`,
                entityId: context.entityId,
                suggestedDisplayName: document.title
              });
              saveEvent.notifySuccess();
            });
            microsoftTeams.settings.setValidityState(true);
          } catch (err) {
            console.error('failed to set teams settings')
          }
        });
      });
    }
  </code></pre>