-->

How to specify exact version of Office.js used?

2019-02-20 10:30发布

问题:

We're running an Outlook add-in and it looks like Microsoft have updated the version of Office.js from 16.00 to 16.01: outlook:{ios:"16.00",mac:"16.00",web:"16.01",win32:"16.02"} (via https://appsforoffice.microsoft.com/lib/1.1/hosted/office.js)

One of the changes looks to be additional verification to the abstraction of postMessage ensuring that the domain (including subdomain) of the child / parent are the same.

Because we host our add-in and central auth server on different subdomains and as a result, all our OAuth flows are broken in Outlook for the web.

outlook-web-16.01.js:18 Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('https://outlook.domain.com') does not match the recipient window's origin ('https://auth.domain.com')

Outlook on Desktop (both MacOS and Windows) are unaffected.

We already whitelist the domains in our manifest file:

<AppDomains>
  <AppDomain>https://outlook.domain.com</AppDomain>
  <AppDomain>https://outlook-staging.domain.com</AppDomain>
  <AppDomain>https://auth.domain.com</AppDomain>
</AppDomains>

Is it possible to manually specify the version of Office.js that is loaded in each platform so we can upgrade at our own pace and avoid breaking changes like these?

回答1:

For this specific error, you need to add your subdomains to the appdomain/appdomains section in your manifest. See:

https://dev.office.com/reference/add-ins/manifest/appdomains https://dev.office.com/reference/add-ins/manifest/appdomain

Major version changes, i.e. 16.00 -> 16.01, in general cannot be specified, and should not be rolled back to. If a host (OWA client or Outlook) is expecting a certain version (16.01) forcing it to use 16.00 would result in unexpected behavior (most likely apis just returning errors).

If you wanted to be more resilient to the changes we make to those files (i.e. changes we make to 16.01) you could pull the files off appsforoffice and selfhost them. But this is not supported/recommended. This means that any bug fixes or improvements we made to those files would be missed.