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
671 stars 95 forks source link

How to handle event based activation in Windows Outlook add-in using modern JS ecosystem #3730

Closed Jareh88 closed 3 months ago

Jareh88 commented 1 year ago

Overview

Context

Steps Taken So Far (non-exhaustive list, these are the most recent/relevant)

Things we're considering (but looking for other/better options)

Questions

Let us know if you require any more details, we'll provide what we can. Many thanks in advance.

omar-pk commented 1 year ago

We are dealing with similar issues with event based activation support for old/classic Outlook on Windows. I think a lot of the challenges come from the ECMA2016 (or earlier) restriction. The MS documentation you linked in your description overview specifically states to avoid async/awaits and ternary operators, despite these being in spec for for ECMA2016. It's unclear what is truly supported. What method are you currently using to convert your modern JS?

Jareh88 commented 1 year ago

I believe async/await were introduced in ECMA2017. Ternary/conditional operators I believe have been in a lot longer but things like the nullish coalescing operator were introduced much later, which could be why they're recommending we avoid.

We're currently using Vite to compile our typescript/modern JS to ECMA2016 or earlier. The entry points then refer to those compiled files.

bas-eenhoorn commented 1 year ago

Yeah you just cant use certain things. For example, you can not use window.location.href, as location does not exist. There is nothing to do about that other than to not use newer functions.

You can not use async and await, you cant use tenery?.operations. You must be careful when using any method, and really check if they are available. You should just write a wrapper for the XmlHttpRequest class. And for example, if we used [].include() in our script, which is not available in this older version, we just write a replacement method for it like: function _includes(source, value) { [identical implementation] }

Its annoying, I know. Our Event-Based Activation script is around 1800 lines at the moment, because we had to copy paste A LOT of duplicate code, because you cant load other scripts/libraries. So we needed to copy and paste all methhods we needed in EBA from our Outlook Office js wrapper, some common javascript libraries, etc.

Nothing to do about it. Just be secure.

hello-chenchen commented 5 months ago

i don't know why Windows Classic Outlook have so much limitation on event-based? but there is no limitation in On Send: https://learn.microsoft.com/en-us/office/dev/add-ins/outlook/outlook-on-send-addins?tabs=windows And i raise an feature request to remove these limitation: https://feedbackportal.microsoft.com/feedback/idea/867e188d-77fd-ee11-a73d-6045bd841c15

Adrian-MSFT commented 3 months ago

My suggestion for this is to use tools like webpack to transpile the code into ECMA2016 or earlier to avoid these unsupported cases. If you'd like to submit a feature request, 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.