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
670 stars 96 forks source link

ItemSend callback is very slow #4799

Open nivgoldstein opened 1 month ago

nivgoldstein commented 1 month ago

Provide required information needed to triage your issue

Hi, I'm working on a plugin to check emails before sending them. I'm using the item send function

Your Environment

  • Platform [PC desktop, Mac, iOS, Office on the web]: Chrome browser on windows
  • Host [Excel, Word, PowerPoint, etc.]: Outlook on browser
  • Operating System: Windows 11
  • Browser (if using Office on the web): Chrome, and issue was also reproduced on edge.

Expected behavior

To see the log with the item ID and have the email sent within 50-100 milliseconds of clicking the send button.

Current behavior

Currently, it takes 1000-2000 ms to get the item ID and send the email.

Steps to reproduce

  1. Install customAddin.xml
  2. Try to send an email
  3. See that emails take nearly a second to send

addin.xml

<OfficeApp
        xmlns="http://schemas.microsoft.com/office/appforoffice/1.1"
        xmlns:bt="http://schemas.microsoft.com/office/officeappbasictypes/1.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:type="MailApp">
    <Id>332980cc-1e81-40e8-9e69-7cd1b4db3756</Id>
    <Version>1.0.0</Version>
    <ProviderName>ASDF</ProviderName>
    <DefaultLocale>en-US</DefaultLocale>
    <DisplayName DefaultValue="Accidental Data Exposure"/>
    <Description DefaultValue="Accidental Data Exposure"/>
    <Hosts>
        <Host Name="Mailbox"/>
    </Hosts>
    <Requirements>
        <Sets>
            <Set Name="MailBox" MinVersion="1.1"/>
        </Sets>
    </Requirements>
    <FormSettings>
        <Form xsi:type="ItemRead">
            <DesktopSettings>
                <SourceLocation DefaultValue="https://ade-plugin-staging.s3.amazonaws.com/ade/functions.html" />
                <RequestedHeight>100</RequestedHeight>
            </DesktopSettings>
        </Form>
    </FormSettings>
    <Permissions>ReadWriteMailbox</Permissions>
    <Rule xsi:type="RuleCollection" Mode="Or">
        <Rule xsi:type="ItemIs" ItemType="Message" FormType="Read" IncludeSubClasses="true"/>
    </Rule>
    <DisableEntityHighlighting>false</DisableEntityHighlighting>
    <VersionOverrides
            xmlns="http://schemas.microsoft.com/office/mailappversionoverrides"
            xsi:type="VersionOverridesV1_0">
        <VersionOverrides xmlns="http://schemas.microsoft.com/office/mailappversionoverrides/1.1"
                          xsi:type="VersionOverridesV1_1">
            <Hosts>
                <Host xsi:type="MailHost">
                    <DesktopFormFactor>
                        <SupportsSharedFolders>true</SupportsSharedFolders>
                        <FunctionFile resid="function-file-url"/>
                        <ExtensionPoint xsi:type="Events">
                            <Event Type="ItemSend" FunctionExecution="synchronous"
                FunctionName="handleItemSend" />
                        </ExtensionPoint>
                    </DesktopFormFactor>
                </Host>
            </Hosts>
            <Resources>
                <bt:Images>
                </bt:Images>
                <bt:Urls>
          <bt:Url id="function-file-url"
            DefaultValue="https://ade-plugin-staging.s3.amazonaws.com/ade/functions.html" />
                </bt:Urls>
                <bt:ShortStrings>
                    <bt:String id="add-in-label" DefaultValue="Accidental Data Exposure"/>
                </bt:ShortStrings>
            </Resources>
        </VersionOverrides>
    </VersionOverrides>
</OfficeApp>

https://ade-plugin-staging.s3.amazonaws.com/ade/functions.html

<html lang="en">

<head>
    <title>No UI</title>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge">
    <script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js" type="text/javascript"></script>
    <script>
        START_TIME = (new Date()).getTime()

        function timedLog(s) {
            let total_ms = ((new Date()).getTime() - START_TIME);
            console.log(`Timed log (${total_ms}ms) ${s}`);
        }
        timedLog("Start log");

        function handleItemSend(e) {
            timedLog("start handleItemSend");
            const mailboxItem = Office.context.mailbox.item;
            getItemId(mailboxItem).then(itemId => {
                timedLog(`item ID: ${JSON.stringify(itemId)}`)
                e.completed({ allowEvent: true });
                timedLog("Call complete, send email")
            })
        }

        function getAttachments(mailboxItem) {
            return new Office.Promise(function (resolve, reject) {
                mailboxItem.getAttachmentsAsync(function (asyncResult) {
                    if (asyncResult.status === Office.AsyncResultStatus.Failed) {
                        reject(asyncResult.error);
                    } else {
                        resolve(asyncResult.value);
                    }
                });
            });
        }

        function getRecipients(mailboxItem) {
            return new Office.Promise(function (resolve, reject) {
                mailboxItem.to.getAsync(function (asyncResult) {
                    if (asyncResult.status === Office.AsyncResultStatus.Failed) {
                        reject(asyncResult.error);
                    } else {
                        resolve(asyncResult.value);
                    }
                });
            });
        }

        function getBody(mailboxItem) {
            return new Office.Promise(function (resolve, reject) {
                mailboxItem.body.getAsync("text", {}, function (asyncResult) {
                    if (asyncResult.status === Office.AsyncResultStatus.Failed) {
                        reject(asyncResult.error);
                    } else {
                        resolve(asyncResult.value);
                    }
                });
            });
        }

        function getSender(mailboxItem) {
            return new Office.Promise(function (resolve, reject) {
                mailboxItem.from.getAsync(function (asyncResult) {
                    if (asyncResult.status === Office.AsyncResultStatus.Failed) {
                        reject(asyncResult.error);
                    } else {
                        resolve(asyncResult.value);
                    }
                });
            });
        }

        function getSubject(mailboxItem) {
            return new Office.Promise(function (resolve, reject) {
                mailboxItem.subject.getAsync(function (asyncResult) {
                    if (asyncResult.status === Office.AsyncResultStatus.Failed) {
                        reject(asyncResult.error);
                    } else {
                        resolve(asyncResult.value);
                    }
                });
            });
        }

        function getCC(mailboxItem) {
            return new Office.Promise(function (resolve, reject) {
                mailboxItem.cc.getAsync(function (asyncResult) {
                    if (asyncResult.status === Office.AsyncResultStatus.Failed) {
                        reject(asyncResult.error);
                    } else {
                        resolve(asyncResult.value);
                    }
                });
            });
        }

        function getBCC(mailboxItem) {
            return new Office.Promise(function (resolve, reject) {
                mailboxItem.bcc.getAsync(function (asyncResult) {
                    if (asyncResult.status === Office.AsyncResultStatus.Failed) {
                        reject(asyncResult.error);
                    } else {
                        resolve(asyncResult.value);
                    }
                });
            });
        }

        function getItemId(mailboxItem) {
            return new Office.Promise(function (resolve, reject) {
                mailboxItem.saveAsync(function (asyncResult) {
                    if (asyncResult.status === Office.AsyncResultStatus.Failed) {
                        reject(asyncResult.error);
                    } else {
                        resolve(asyncResult.value);
                    }
                });
            });
        }

        Office.initialize = function () {}
        timedLog("Finish loading definitions");
    </script>
</head>

<body>
This page is left blank intentionally.
</body>

</html>

Context

The fact that is takes over a second to send an email is a significant nuisance for the user.

Useful logs

Output into console.log

Timed log (0ms) Start log
Timed log (0ms) Finish loading definitions
Timed log (391ms) start handleItemSend
Timed log (995ms) item ID: "AAMkADA5MDIzNzQ0LTlmYmEtNDVmOC1iNTIwLTkxMjcyYzBhMWVlNABGAAAAAADMU/ir8HBvSquK6lWy8/gXBwCgtFdj9cEHQbDs4NZOjof1AAAAAAEPAACgtFdj9cEHQbDs4NZOjof1AACzcQb0AAA="
Timed log (995ms) Call complete, send email
karamesefatih commented 1 month ago

I have the same issue.Item send event is very slow on mac as well and its even slower with big mails

rajjha-msft commented 3 weeks ago

Thanks for reporting the issue. We have put it in our backlog. Unfortunately, we do not have any timelines to share.

Internal tracking Id: 301685