0

Summary

I have an Outlook on-send add-in that modifies the current message and then calls event.completed({ allowEvent: true }). Right before completing, I post a final message to a Service Worker so it can send usage stats to my server without delaying the send flow.

This works in web browsers and New Outlook on Windows. In Classic Outlook (Win32) and New Outlook on Mac, the function-file iframe is torn down as soon as event.completed is called; because these hosts aren’t fully browser-based, the Service Worker is terminated immediately and the last request never reaches my server.

Environments

Works:

Outlook on the web (Edge/Chrome/Firefox/Safari) New Outlook on Windows Fails:

Classic Outlook (Win32) New Outlook on Mac Repro (minimal)

// function file: onSendHandler
export async function onSendHandler(event) {
  try {
    // 1) Make message edits...
    await doComposeEditsAsync();

    // 2) Ask SW to send non-blocking stats
    navigator.serviceWorker.controller?.postMessage({
      type: 'SEND_STATS',
      payload: {/* small JSON payload */}
    });

    // 3) Immediately allow send to proceed
    event.completed({ allowEvent: true });

    // After this point, in Classic Win32 / New Mac:
    // - function-file iframe is torn down
    // - SW is terminated
    // - 'SEND_STATS' request never completes
  } catch (e) {
    // If edits fail, block send (not the issue here)
    event.completed({ allowEvent: false });
  }
}

// service worker (sketch)
self.addEventListener('message', (evt) => {
  if (evt.data?.type === 'SEND_STATS') {
    evt.waitUntil(fetch('/stats', {
      method: 'POST',
      body: JSON.stringify(evt.data.payload),
      headers: { 'content-type': 'application/json' }
      // keepalive/sendBeacon not available here reliably in affected hosts
    }));
  }
});

Expected

event.completed({ allowEvent: true }) should not immediately kill the environment needed for a brief, non-blocking background request initiated just before completion (or there should be a supported pattern to finish that request reliably).

Actual

On Classic Win32 and New Outlook for Mac, the function-file iframe and Service Worker are shut down instantly upon calling event.completed, so the final request never runs.

Constraint

I must call event.completed before the background stats request completes to avoid delaying message send.

Questions

Is there a supported pattern to ensure a short, non-blocking network call can complete after event.completed in Classic Win32 and New Outlook for Mac? If keeping a Service Worker alive isn’t possible in these hosts, is there an official alternative (e.g., sanctioned background channel, hidden webview/iframe, host-provided telemetry hook, or a keep-alive API) recommended for on-send event handlers? Are there platform differences documented around lifecycle/teardown timing for function files and Service Workers that would explain this behavior? Notes I’m specifically asking whether there’s a way to keep a small, platform-approved background process alive long enough for a final request without blocking send. I’m not attempting to defer or delay event.completed; the send should proceed immediately.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.