How to check if running in Teams #74
-
I would assume the TeamsJS SDK would have some sort of Are we running inside Teams function, but the Blazor sample just uses the following javascript code: // Come from here: https://github.com/wictorwilen/msteams-react-base-component/blob/master/src/useTeams.ts
export function inTeams() {
if (
(window.parent === window.self && window.nativeInterface) ||
window.navigator.userAgent.includes("Teams/") ||
window.name === "embedded-page-container" ||
window.name === "extension-tab-frame"
) {
return true;
}
return false;
} Is this the recommended way to check if the app is running in Teams or not? Reason I'm asking, we see a lot more use cases where Team apps are loaded in SharePoint or at Office.com in the sidebar. Will all those other app loading options also result in |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
It does indeed. You can use the |
Beta Was this translation helpful? Give feedback.
If I'm not mistaken, when you try to get Teams context outside of Teams, it will give you null which indicates that you're not running inside of Teams.
isSupported
is meant for checking capabilities, like sending emails, chat messages etc, which is the recommended way to determine the behavior inside your app because the functionality of the host could change in the future.