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

On-Send Add-in fails in Old Outlook #3783

Closed John-Dawson closed 1 year ago

John-Dawson commented 1 year ago

We have an Outlook Add-in that is working fine in Outlook Web and in "New" Outlook, but fails in "Old" Outlook

Your Environment

OS Name Microsoft Windows 10 Enterprise N, Version 10.0.19045 Build 19045 Microsoft® Outlook® for Microsoft 365 MSO (Version 2309 Build 16.0.16827.20166) 64-bit

Expected behavior

Should work the same in Outlook Web and Outlook Desktop, both Old and New

Current behavior

App is initiated, but never completes; an "... add-in is taking longer than expected" message appears - with exit option; eventually (~5m) App is timed-out - per standard behaviour for Smart Alerts

Steps to reproduce

AFAIK, although the Add-in is triggered OK, it fails almost immediately, perhaps in Office.OnReady or Office.context.mailbox.item.body.getAsync

Link to live example(s)

Desktop App only

Provide additional details

This issue arose when we moved to use Smart Alerts i.e. prior to this, the Add-in did work in Old Outlook

Context

Terminal issue, as many customers are still on Old Outlook

Useful logs

Logging configured: C:\Users\\AppData\Local\Temp\OfficeAddins.log.txt

You can see a couple of console.log() entries in here, which tell me that a) the Add-In was successfully initiated b) it got into the "FunctionName" (checkEmail) defined in "LaunchEvent" in the Manifest, but doesn't get much further ... I can't see any obvious error in the log ...

27/10/2023 11:57:49 Verbose Runtime [Console] [Log] MailboxHostExecuteApi invoked!
27/10/2023 11:57:49 Verbose Runtime [Console] [Log] MailboxHostExecuteApi invoked!
27/10/2023 11:57:49 Verbose Runtime [Console] [Log] MailboxHostExecuteApi invoked!
27/10/2023 11:57:55 Verbose Runtime [Console] [Log] Platform Bundle - Office exists!
27/10/2023 11:57:55 Verbose Runtime [Console] [Log] Platform Bundle - Office.actions exists!
27/10/2023 11:57:55 Verbose Runtime [Console] [Log] Platform Bundle - Office.actions.associate exists!
27/10/2023 11:57:55 Verbose Runtime [Console] [Log] Outlook Batch JS loaded!
27/10/2023 11:57:55 Verbose Runtime [Console] [Log] Outlook LaunchEvent JS loaded!
27/10/2023 11:57:55 Verbose Runtime [Console] [Log] 'On-Send:', '3.16.1a'
27/10/2023 11:57:55 Verbose Runtime [Console] [Log] InvokeMailboxCreateOM was invoked!["{\"hostVersion\":\"16.0.16827.20166\", \"itemType\":4, \"permissionLevel\":3, \"userEmailAddress\":\"john.dawson@cloudassist.ie\", \"userDisplayName\":\"John Dawson | CloudAssist\", \"userProfileType\":\"office365\", \"userTimeZone\":\"GMT Standard Time\", \"conversationId\":\"AAQkADhiOGQxZWRkLWQ1ODItNGZjZC1hNWIyLWM5ZmUxZjM1MWM1NgAQAKub3INzDeRIiyLb7Hc4nb4=\", \"ewsUrl\":\"https://outlook.office365.com/EWS/Exchange.asmx\", \"restUrl\":\"https://outlook.office.com/api\", \"itemNumber\":1073741829, \"roamingSettings\":\"{}\", \"extensionPointType\":8, \"enableBetaAPIs\":false, \"displayLanguage\":\"en-US\", \"contentLanguage\":\"en-IE\", \"officeVersion\":\"16.0.16827.20166\", \"requirementSets\":\"{\\"Mailbox\\":\\"1.13\\",\\"OutlookTelemetry\\":\\"1.2\\",\\"IdentityAPI\\":\\"1.3\\"}\", \"isFromSharedFolder\":false, \"shouldRunNewCodeForFlags\":1, \"nativeFlights\":{\"Ripcord_7935469\":true}}"]
27/10/2023 11:57:55 Verbose Runtime [Console] [Log] SDX Control is ready!
27/10/2023 11:57:55 Verbose Runtime [Console] [Log] 'checkEmail', { _x: 0, _y: 0, _z: null, _A: null }
27/10/2023 11:57:55 Verbose Runtime [Console] [Log] RunLaunchEventHandlerFunctionWithData was invoked with funcName = checkEmail
27/10/2023 11:57:55 Verbose Runtime [Console] [Log] MailboxHostExecuteApi invoked!
27/10/2023 11:57:55 Verbose Runtime [Console] [Log] MailboxHostExecuteApi invoked!
27/10/2023 11:57:55 Verbose Runtime [Console] [Log] MailboxHostExecuteApi invoked!
27/10/2023 11:57:55 Verbose Runtime [Console] [Log] MailboxHostExecuteApi invoked!
27/10/2023 11:57:55 Verbose Runtime [Console] [Log] MailboxHostExecuteApi invoked!
27/10/2023 11:57:55 Verbose Runtime [Console] [Log] MailboxHostExecuteApi invoked!
27/10/2023 11:57:56 Verbose Runtime [Console] [Log] MailboxHostExecuteApi invoked!

25/10/2023 12:34:50 Verbose Runtime [Console] [Log] MailboxHostExecuteApi invoked! <----------- many instances logged

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.

ioxFR commented 1 year ago

Hello,

Got same issue for our customer. Our addin doing actions on events mail send and appointment send. Once we click on send button, message appear that addin is working on and after few minutes a dialog appear to inform that failed with a button to send later or send now.

We also not expecting this issue on outlook on web & new outlook (which is based on outlook on web...)

One precision, in our side we got the problem only with all MSO versions only

We using these events `

            <LaunchEvent Type="OnMessageSend" FunctionName="onMessageSendHandler" SendMode="PromptUser" />
            <LaunchEvent Type="OnMessageRecipientsChanged" FunctionName="onMessageRecipientsChangedHandler"/>`

And we doing the associate as documented and working well on all versions except MSO versions.

And it's look like a problem to handle the event.completed and not a problem on the associate i think.

Thanks for helping us, Valentin

John-Dawson commented 1 year ago

Thanks for feedback; in our case I don't think it's a problem with event.completed - I commented it out to check this, and still fails, per above, in "Old" Outlook. As mentioned, I think it fails earlier ...

John-Dawson commented 1 year ago

As a work-around, I'm now detecting the Outlook Version, and if it's not the "New" Outlook, I exit the Add-In immediately, and let the Email Send; this prevents any User disruption, but is still unsatisfactory, as the Add-In is not executed

I have found that the Old Outlook is failing (i.e. hangs and times-out) on certain JS constructs e.g. URLSearchParams & DOMParser and probably many others too, so I was wondering could I not use Babel to circumvent this? But how? I'm already using @babel/preset-env, but perhaps my Babel environment is not correctly setup??

ioxFR commented 1 year ago

Hi @John-Dawson ,

This is a huge workaround 🗡️ My investigations clearly indicate this is not coming from certains JS function. I already tested with an empty on mail send event that is just doing an event completed and it's failing.

I think this is coming from an update probably for some specific version which do not interpret the event return.

Apparently, another issue for the same this is opened, and indicate that the problem is solved from 2309 version which is published on the current channel. I will test it probably tomorrow to see if it solve the problem... Hope so...

timwan10 commented 1 year ago

I have found that the Old Outlook is failing (i.e. hangs and times-out) on certain JS constructs e.g. URLSearchParams & DOMParser and probably many others too, so I was wondering could I not use Babel to circumvent this? But how? I'm already using @babel/preset-env, but perhaps my Babel environment is not correctly setup??

This is likely what the cause is. Old Outlook uses the JavaScript-only runtime. (https://learn.microsoft.com/en-us/office/dev/add-ins/testing/runtimes) Whereas Outlook on the Web and New Outlook use browser runtime. As a result some things are not available on the JS Runtime. (including everything with the DOM or UI). Also of note it only supports ECMAScript2016 (see https://learn.microsoft.com/en-us/office/dev/add-ins/outlook/autolaunch?tabs=xmlmanifest#check-manifest-and-javascript-requirements)

I would have thought any errors would come though in the runtime logging you mentioned (https://learn.microsoft.com/en-us/office/dev/add-ins/testing/runtime-logging) But I don't see anything in your logs to indicate the error.

You may want to live debug the event based add-in to find out what is going on: (https://learn.microsoft.com/en-us/office/dev/add-ins/outlook/debug-autolaunch?tabs=windows).

It is likely some call or function that is causing the issue.

John-Dawson commented 1 year ago

Thankfully, I have now found the solution to this issue, or rather a few issues, as follows

  1. It is necessary to use Babel, with "@babel/preset-env" - probably to address the runtime issue. as described by @timwan10
  2. I also found just two JS features that didn't work, which it was possible to work-around
    • "window.location", which I'm using to access a parameter passed to the App, in the manifest: URLSearchParams(window.location.search)
    • DOMBrowser, which I'm using to find links in the Email Body
    • There may well be other JS features that could cause trouble in this context; these are only the ones that affected this App

We have two Apps, an On-Send (where the above problem lay) and a Taskpane App - these share a lot of functionality; interestingly, the Taskpane App worked fine i.e. without the transformations described above; this presumably suggests that the Taskpane uses a different runtime to the On-Send?

The runtime logging was essential to track down these issues ... but it does indeed look like the MS error log is not catching these errors, as a sort of binary chop approach was needed to find the exact location of the error(s)

Thanks all above for feedback ... hope this helps someone else too ...

John-Dawson commented 1 year ago

Per previous entry, above