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

Event OnMessageSend - Debug not work #2999

Closed MorrisPenasso closed 1 year ago

MorrisPenasso commented 1 year ago

Provide required information needed to triage your issue

I developing a Outlook Addin on Typescript and with old event "onSend" it work but i can't deploy on AppSource. So i use "OnMessageSend" event. When i try to start debugger, is not attached.

Your Environment

Expected behavior

I would like to use debugger on visual studio code before email is sended.

Current behavior

Below there are the steps:

Link to live example(s)

Below, my code:

Useful logs

hapalacios commented 1 year ago

I have a similar issue. I thought I was my setup but since last month I am not able to debug the "onMessageSendHandler" as well. I receive this window message when I setup the regedit key, and start the debugger following all the steps mentioned on the documentation, but the debugger doesn't do anything. image

Environment:

Same scenario explained above , the only difference it's that my backend it's setup on .NET and I call the endpoints on the base route https://localhost:44306.

In my case I am just trying to execute different endpoints when you hit "Send" inside the launcheevent.js. E.g. GET, POST, etc.

And to avoid syntax errors I tested before all these endpoints from the (1) add-in codebase, (2) Scrip-lab and (3) Postman and all worked fine. This issue only happens inside onMessageSendHandler, on the launchevent.js file.

image

I think this is a CORS issue related to the way we setup the back-end in .NET. I am receiving a "Network request failed" on the catch {} and this usually happens when we don't setup our URL in the CORS config key on our backend. I ran similar example on Script-lab, and I fix it just adding the script lab URL to my backend CORS config key. E.g. image

Note: Also, I tried what was mentioned on other chats to add the microsoft-officeaddins-allowed inside the .wellknow folder. But this doesn't fixed the problem as well.

How I can add the launchevent.js or bundle.js files to my CORS config URLs when running this on dev-enviroment - localhost:3000, or there is any workaround for this?

hapalacios commented 1 year ago

Hi Office dev team, any updates in any of these issues?

davidchesnut commented 1 year ago

Hi @MorrisPenasso and @hapalacios, thanks for letting us know about this issue. @exextoc can you please help resolve this issue? Thanks!

exextoc commented 1 year ago

Can you please verify if the steps mentioned in documentation - https://learn.microsoft.com/en-us/office/dev/add-ins/outlook/debug-autolaunch#attach-visual-studio-code are followed.

MorrisPenasso commented 1 year ago

I followed only steps mentioned in documentation.

exextoc commented 1 year ago

@MorrisPenasso Is the OnMessageSend event working as expected? Please confirm if my understanding is correct. The launch event works fine but it doesn't stop at breakpoint.

MorrisPenasso commented 1 year ago

Exactly. On my example, with the istruction "event.completed({allowEvent: true})", the email is sended. But it doesn't stop at breakpoint.

hapalacios commented 1 year ago

Exactly the same for me @exextoc. I have two scenarios: 1) If I don't add any endpoint call on launchevent.js, the email it's sent and doesn't stop at the breakpoint. 2) If I add a endpoint call like the one explained on my example above, the email it's not sent, and I receive a "Network request failed" on the catch {} . Also in this example the debugger doesn't stop at the breakpoint.

hapalacios commented 1 year ago

Can you please verify if the steps mentioned in documentation - https://learn.microsoft.com/en-us/office/dev/add-ins/outlook/debug-autolaunch#attach-visual-studio-code are followed.

I also followed these steps.

hapalacios commented 1 year ago

Hi @exextoc . Any updates on any of these issues? I am delaying this kind of functionality from my current release plan. Right now, I am not suffering a big impact, but in one week, if I am not able to call endpoints and run the debugger inside the launcheenevent.js file I will need to look to other solutions.

MorrisPenasso commented 1 year ago

There are other methods ? I would like to debug my launchevent.ts for understand how to import another typescript modules.

hapalacios commented 1 year ago

I will not recommend to do imports inside launchevent.js. That practice it's not recommended on the documentation. Not sure if this is what you are looking for?

If you are looking into testing more events you have a list here: https://learn.microsoft.com/en-us/office/dev/add-ins/outlook/autolaunch?tabs=xmlmanifest

MorrisPenasso commented 1 year ago

My typescript modules is used for work with custom actions behind a buttons and when i send an email/appointment. I can't repeat the code for using behind button and for events. The debug is important in my case.

MorrisPenasso commented 1 year ago

Any updates???

hapalacios commented 1 year ago

@exextoc any updates on these issues?

exextoc commented 1 year ago

@MorrisPenasso and @hapalacios, in your launch.json file, can you replace 9229 with 9223 and see if that works?

MorrisPenasso commented 1 year ago

Perfect! It works!!!

MorrisPenasso commented 1 year ago

@exextoc thanks for your help!!

hapalacios commented 1 year ago

@exextoc I was already using 9223 on my previous testing. The debugger it's working when adding breakpoints on the "onMessageComposeHandler" but not for the "onMessageSendHandler". I am going to do a little bit more of testing with simpler functions tomorrow.

hapalacios commented 1 year ago

@exextoc I can confirm onMessageSendHandler breakpoints work for simple functions, but not for complex functions that includes:

  1. Endpoints - e.g. fetch GET.POST - OR
  2. intervals

I am going to continue testing later today. BTW did you check the other issue I reported on my first couple of messages above, related to CORS for the bundle.js file. Right now, I am receiving network error.

exextoc commented 1 year ago

@hapalacios Can you open separate issues so that we can them track differently? @MorrisPenasso I'm glad the port change addressed this for you. We are going to update our documentation to reflect this.

hapalacios commented 1 year ago

Sure @exextoc . I will create two simple scenarios and remove the extra complexity so you can test as well.

kostia-lev commented 1 year ago

@hapalacios Was you able to send fetch request from launchevent.js? For me it does not work in Outlook 365, network request failed and debugger endpoints are not hit as well

martinguenther commented 7 months ago

This might be an issue related to CORS or the well-known URI. See https://github.com/OfficeDev/office-js/issues/3907#issuecomment-2023138415