With SPFx 1.7 preview release, I know we can access Teams Context information in SharePoint Framework web part but not from SharePoint Framework extensions. I looked at ApplicationCustomizerContext class but didn't find any reference. Wondering if Teams context information is available in SharePoint Framework extensions?


Interestingly I found the way to get Teams Context information in SPFx extension. Follow the below steps to do it:

  1. Do "npm install @microsoft/teams-js --save" in your SPFx extension project.

  2. In your .ts file or if you using React, then inside your target component, import microsoftTeams names as 'Import * as microsoftTeams from '@microsoft/teams-js'.

  3. In your code, use below code:

        try {
            microsoftTeams.getContext(tContext => {
                console.log('Inside Teams:'+tContext.teamName);
                this.setState({ ShowBanner: false });
        } catch (error) {
            console.error("Exception while getting Teams context:" + error);
  • Amazing, thanks for this :D
    – BennKingy
    Jan 14 '21 at 10:44
  • is this correct way ? . however code is working
    – InfoÁsith
    May 21 '21 at 11:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.