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
648 stars 92 forks source link

Adding event handler for dialog messages fails in Outlook for Mac #349

Closed richnew10 closed 2 years ago

richnew10 commented 5 years ago

Expected Behavior

STR:

  1. Add-in page opens a dialog and registers a handler.
window.Office.context.ui.displayDialogAsync(uri, options, (result: Office.AsyncResult) => {
  const dialog = result.value;
  dialog.addEventHandler(Office.EventType.DialogEventReceived, (ev: any) => {
    onClose();   // Simple function defined elsewhere.
  });

  dialog.addEventHandler(Office.EventType.DialogMessageReceived, (m: string) => {
    handleMessage(dialog, m);   // Simple function defined elsewhere.
  });
});
  1. Dialog page sends back.
window.Office.context.ui.messageParent("{'action': 'foo'}");

Expected: handleMessage is called.

Actual: handleMessage is not called. Using Vorlon I find that Outlook logs "messages received cannot be handlered" when adding the event handler.

onClose is successfully called, so events are being delivered to the add-in.

This seems exactly like:

and similar to:

Context

This makes it impossible to send responses from a dialog, limiting us to only those things that can be accomplished after closing the dialog.

Your Environment

Outlook 16.16.5, Mac 10.13.6.

kbrandl commented 5 years ago

@richnew10 thanks for reporting this and sorry to hear that you've run into this problem. @exextoc can you please look into this?

macOutlookExtensibility commented 5 years ago

Thanks for raising it. Please provide the code for us to help in debugging.

richnew10 commented 5 years ago

Please provide the code for us to help in debugging.

I'd love to, but I'm encountering this in a closed-source product.

Are you able to reproduce with the snippets I provided above?

From my research, this looks like a failure to parse the message envelope that's constructed here and parsed here, or to invoke the handler a few lines below. As far as I can tell none of my code related to message handling gets to run, and my payload is a small string representation of valid JSON, which should be fine.

jargil commented 5 years ago

@richnew10 - I just tried with a very similar script to yours and it worked just fine:

Office.context.ui.displayDialogAsync(someUrl, {height:40,width:40}, function(result){ const dialog = result.value; if(result.status == Office.AsyncResultStatus.Failed) {console.log('error');} dialog.addEventHandler(Office.EventType.DialogMessageReceived, function(m){ console.log('message received'); console.log(m); }); });

And then from the dialog used pretty much your snippet. Granted I'm using a newer version of Outlook and also a newer macOS version 10.14, but we haven't made any recent changes around this code that would make it fail in the build versions that you're using.

Is there any way you can help identify more details to help us debug? Perhaps can you try building a small example where you can consistenly reproduce this problem and share it with us?

richnew10 commented 5 years ago

I suspect that a newer Outlook and a newer WebKit, plus 3 months, could make a difference. I will attempt another repro next time I cycle around to this area of the code.

djpereira commented 5 years ago

I'm on macOS 10.14.4 and Outlook 16.24, and I can reproduce this issue. Everything works well on Safari, FireFox, Edge, IE11 and outlook for Windows, but outlook for mac is not triggering DialogMessageReceived when we call Office.context.ui.messageParent at least for our app.

If we do very simple app, it works well, but not with our app.

From the dialog I see Office.onReady and the global Office.context.ui.messageParent object is there, the data is just not going thru.

djpereira commented 5 years ago

In our case, we discovered that only for Outlook on macOS, both the function file and the dialog need to be exactly in the same domain, including any subdomains (and even in the same port).

richnew10 commented 5 years ago

When I reported that was indeed the case — the only difference between the main page (not a function file) and the dialog was the path changing from /outlook/ to /outlook/signin.

m-pd commented 4 years ago

This is still an issue with Outlook for Mac version 16.16.12. It's a serious blocker. Any road map to fix this?

ChayaChechik commented 4 years ago

Having the same issue with outlook on the web. This is a major issue - any updates re fixing this?

m-pd commented 4 years ago

I resolved this issue by redirecting the task pane to be in the same domain as the dialog.

ChayaChechik commented 4 years ago

The issue I'm having persists, even thought I have the taskpane and dialog page on the same domain. The only way it works is with an iframe. However, for most cases I would need a proper page not an iFrame. https://stackoverflow.com/questions/58606436/outlook-add-in-dialog-api-eventhandler-not-firing/58607606#58607606

macOutlookExtensibility commented 4 years ago

@m-pd , are you unblocked on Mac?

ghost commented 4 years ago

This issue has been automatically marked as stale because it is marked as needing author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. Thank you for your interest in Office Add-ins!

ghost commented 4 years ago

This issue has been closed due to inactivity. Please comment if you still need assistance and we'll re-open the issue.

abimaelmartell commented 4 years ago

I'm having this same issue on Excel, is there a fix for this yet?

abdidaudpropel commented 3 years ago

I am facing the same issue on Mac 10.15.5 and Excel 16.38. The same code works in Excel Online and Excel windows.

Office.context.ui.messageParent does nothing and displayDialogAsync's callback is not triggered. Additionally, only on mac Office.context.ui.closeContainer through undefined error (called by the dialog after office is initialized)

Hamdan85 commented 3 years ago

Cmon guys, how this is closed? It's not working yet.

abimaelmartell commented 3 years ago

It seems like displayDialogAsync mutates the options object, so in order to get this working you need to send a new object every time.

const options = { height: 100, width: 100 };

// this will result on event handler not triggering
Office.context.ui.displayDialogAsync(url, options, cb);

// this works
Office.context.ui.displayDialogAsync(url, { ...options }, cb);

Seems like an issue on the library, but this seems to work ok.

Hamdan85 commented 3 years ago

I just do it once, and it opens the window in mac but not in windows.

But in mac, it doesn't receive events back (call back triggers this message: "messages received cannot be handlered")

It seems that there are also an error in edge which prevents us from knowing the opener window. Do you know anything about that?

using this:

Office.context.ui.messageParent(JSON.stringify({ authenticationCode }));

only triggers this in the parentWindow:

messages received cannot be handlered. Message:{"dialogMessage":{"messageType":0,"messageContent":"{\"authenticationCode\":\"uHeTqFx6pKHxAUSZcsoipNdp2t0cvbyIjLid_o6w5e0\"}"}}

PS: in windows, as before, displayDialogAsync simply doesn't open anything

exextoc commented 3 years ago

@abdidaudpropel Is this issue happening in Outlook Mac new UI or old UI? @Hamdan85 Do you mean you are seeing issue in Outlook windows client also? Can you share the Outlook client version? Have you tried the workaround suggested by @abimaelmartell ?

Hamdan85 commented 3 years ago

I discovered the issue here. THe problem is that the documentation doesn't says anything about the URL argument necessarily need to be absolute and outlook on mac behaving differently.

On mac it opens the dialog but the parent cant receive messages back. On windows, it just don't do anything.

Changing it to absolute URL fixed my issues. Just add this to the documentation.

ghost commented 3 years ago

This issue has been automatically marked as stale because it is marked as needing author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. Thank you for your interest in Office Add-ins!

ghost commented 3 years ago

This issue has been closed due to inactivity. Please comment if you still need assistance and we'll re-open the issue.

masha-mariya4 commented 2 years ago

issue is still reproduced for mac!

exextoc commented 2 years ago

Hey @masha-mariya4 ,

The document has been updated to read that the dialog URL provided must be an absolute URL with the hostname and protocol present. Are you seeing an issue despite providing the absolute URL for the dialog?

masha-mariya4 commented 2 years ago

Hey again @exextoc !) I uses absolute URL for it. Maybe the reason that I run the add-in on my local web server (localhost) and dialog URL has different domain? Although I added it in list

exextoc commented 2 years ago

Hey @masha-mariya4 ,

The fact that you're on localhost should not be an issue if you have added the dialog URL domain to the AppDomains. Can you reproduce this only on Mac (on both old and new UI?), or is it the same for you on OWA too?

masha-mariya4 commented 2 years ago

unfortunetely I don't have an opportunity to test it on OWA now, but the research in github issues tells me that it's only mac issue)

exextoc commented 2 years ago

@masha-mariya4 Could you please provide us sample code along with the manifest or an add-in endpoint so that we can reproduce it in house?

chadhobson commented 2 years ago

@exextoc There's several examples above so please stop asking for them and just fix the problem. You can follow your very own tutorial (https://docs.microsoft.com/en-us/office/dev/add-ins/quickstarts/outlook-quickstart?tabs=yeomangenerator) and get the exact same result that everyone here has gotten.

Regardless, I will also chime in and confirm it does NOT work on Mac. Works fine on Windows, though.

So, please drop the stalling and get to fixing your broken software. This issue is over 2.5 years old and STILL persists.

jargil commented 2 years ago

Hey all. I'm sorry to hear you're having problems with the Dialog API on Mac. I've tried reproducing this in multiple ways and I'm not seeing any problems with the API, so getting your samples is very useful for us in order to understand if there's a particular use case where things are breaking for the Mac platform. We really appreciate your input and help here!

Anyway, I created a very simple Script Lab gist that uses the Dialog API, it shows two buttons, one that pops the Dialog and one that calls messageParent to log a message in the Task Pane, could you try to see if things work for you? Gist: https://gist.github.com/jargil/5cefdc755f804be003ad2e119dcf8afc

Once you install and import the gist into Script Lab Code, you should then open the Run pane and you'll see something like this: image

  1. If you click "Display Dialog" the dialog should show, there will be a Type Error reported about an undefined object in the Dialog, please ignore that.
  2. Now if you click "Call Parent" in the dialog, you should see the log appears in the original Task Pane, like this: image

If you see the log it means everything worked as expected. If you can see this working, but your own sample still doesn't work, then please share your sample so that we can try to understand what's going on.

Thank you!

Link to Script Lab for Outlook: https://appsource.microsoft.com/en-us/product/office/WA200001603 Script Lab docs: https://docs.microsoft.com/en-us/office/dev/add-ins/overview/explore-with-script-lab

exextoc commented 2 years ago

Hello @masha-mariya4 , @chadhobson

We regret the inconvenience caused. We are still not able to reproduce it from our end. And if it is not reproducible for us, we can't fix it.

Please help us understand the situation better

We are looking into this bug on priority, please help us with the above information.

Thanks

ghost commented 2 years ago

This issue has been automatically marked as stale because it is marked as needing author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. Thank you for your interest in Office Add-ins!

ghost commented 2 years ago

This issue has been closed due to inactivity. Please comment if you still need assistance and we'll re-open the issue.