Microsoft Tech Community Live:  Microsoft Teams Edition
November 09, 2021, 08:00 AM - 12:00 PM (PST)

Detection of whether react app is running in Teams or Web browser?

%3CLINGO-SUB%20id%3D%22lingo-sub-2165871%22%20slang%3D%22en-US%22%3ERe%3A%20Detection%20of%20whether%20react%20app%20is%20running%20in%20Teams%20or%20Web%20browser%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2165871%22%20slang%3D%22en-US%22%3E%3CP%3ESorry%20for%20the%20last%20line.%3C%2FP%3E%3CP%3EIt%20was%20not%20intended%20to%20be%20posted%20here.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2165231%22%20slang%3D%22en-US%22%3EDetection%20of%20whether%20react%20app%20is%20running%20in%20Teams%20or%20Web%20browser%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2165231%22%20slang%3D%22en-US%22%3E%3CP%3ECurrently%2C%20I'm%20trying%20to%20get%20context%20using%20getContext()%20and%20trying%20to%20decide%20whether%20it's%20running%20in%20Teams%20or%20Browser.%3CBR%20%2F%3EIs%20there%20any%20other%20better%20way%20to%20move%20ahead%20with%20this%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2165231%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3Edeveloper%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EDevices%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMicrosoft%20Teams%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2172702%22%20slang%3D%22en-US%22%3ERe%3A%20Detection%20of%20whether%20react%20app%20is%20running%20in%20Teams%20or%20Web%20browser%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2172702%22%20slang%3D%22en-US%22%3EYes%2C%20get%20context%20will%20work%20on%20browser.%20Are%20you%20facing%20any%20issue%3F%20Could%20you%20please%20share%20more%20details%3F%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2172724%22%20slang%3D%22en-US%22%3ERe%3A%20Detection%20of%20whether%20react%20app%20is%20running%20in%20Teams%20or%20Web%20browser%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2172724%22%20slang%3D%22en-US%22%3E%3CP%3EActually%2C%20the%20callback%20inside%20getContext()%20is%20not%20being%20executed%20when%20the%20website%20is%20being%20opened%20in%20the%20browser.%20Please%20see%20this%20once%20-%26gt%3B%20%3CA%20href%3D%22https%3A%2F%2Fstackblitz.com%2Fedit%2Freact-cuadoi%3Ffile%3Dsrc%252FApp.js%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fstackblitz.com%2Fedit%2Freact-cuadoi%3Ffile%3Dsrc%252FApp.js%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2173345%22%20slang%3D%22en-US%22%3ERe%3A%20Detection%20of%20whether%20react%20app%20is%20running%20in%20Teams%20or%20Web%20browser%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2173345%22%20slang%3D%22en-US%22%3EWhere%20did%20you%20assign%20the%20value%20to%20the%20teamscontext%20variable%3F%20Could%20you%20please%20try%20printing%20the%20context%20directly%20using%20console%20and%20check%20in%20dev%20dev%20tools%3F%3C%2FLINGO-BODY%3E
New Contributor

Currently, I'm trying to get context using getContext() and trying to decide whether it's running in Teams or Browser.
Is there any other better way to move ahead with this?

3 Replies
Yes, get context will work on browser. Are you facing any issue? Could you please share more details?

Actually, the callback inside getContext() is not being executed when the website is being opened in the browser. Please see this once -> https://stackblitz.com/edit/react-cuadoi?file=src%2FApp.js

Where did you assign the value to the teamscontext variable? Could you please try printing the context directly using console and check in dev dev tools?