OfficeDev / office-js

A repo and NPM package for Office.js, corresponding to a copy of what gets published to the official "evergreen" Office.js CDN, at https://appsforoffice.microsoft.com/lib/1/hosted/office.js.
https://learn.microsoft.com/javascript/api/overview
Other
657 stars 93 forks source link

Office js is causing issues in MSTeams App initialization #2310

Closed lazycipher closed 2 years ago

lazycipher commented 2 years ago

Provide required information needed to triage your issue

I've a webapp with ReactJS which has a few screens for outlook while a few for msteams.

Your Environment

Expected behavior

MSTeams App should be running fine without any hinderance to it even if same web app us being used at Outlook and MSTeams.

Current behavior

Web app doesn't load and API call gets cancelled.

Steps to reproduce

  1. Load OfficeJS
  2. Load MSTeams SDK
  3. MSTeams Pages won't open

Context

I'm trying to create a single webapp and embed both for Outlook Addin and MSTeams App.

Useful logs

Screenshot 2021-12-14 at 5 28 52 PM Screenshot 2021-12-14 at 5 31 31 PM

After Removing the JS script for office, the app loads correctly.

This is the codeblock. I just remove the middle script and it works fine for MSTeams.

<script type="text/javascript">
      // Office js deletes window.history.pushState and window.history.replaceState. Cache them and restore them
      window._historyCache = {
        replaceState: window.history.replaceState,
        pushState: window.history.pushState
      };
    </script>

    <script
      src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js"
      type="text/javascript"
    ></script>

    <script type="text/javascript">
      // Office js deletes window.history.pushState and window.history.replaceState. Restore them
      window.history.replaceState = window._historyCache.replaceState;
      window.history.pushState = window._historyCache.pushState;
    </script>

Thank you for taking the time to report an issue. Our triage team will respond to you in less than 72 hours. Normally, response time is <10 hours Monday through Friday. We do not triage on weekends.

exextoc commented 2 years ago

office.js is not intended to be loaded inside a Teams app. Only within Word / Excel / PPT and Outlook add-ins.

What scenario do you need to load Office.Js in your teams app?

lazycipher commented 2 years ago

@exextoc, I've a single web app that I want to use in both Outlook and Teams app.

exextoc commented 2 years ago

Office.js isn't intended to be loaded outside of Office Apps. Perhaps there is a way you can prevent it from loading in teams? Or have the manifest in each file point to different HTML that loads different JS libraries depending on the app that hosts it.

lazycipher commented 2 years ago

@exextoc, Since I'm using ReactJS, there's a single html file which loads when the web app initialises.

exextoc commented 2 years ago

At this point you are probably better of having separate web apps that load in Outlook and Teams.

exextoc commented 2 years ago

This feature isn't implemented yet. We track Outlook add-in feature requests on our Tech Community Page. Please submit your request there and choose the appropriate label(s). Feature requests on Tech Community are considered, when we go through our planning process.

http://aka.ms/M365dev-suggestions