I am making an Outlook add-in with UI-Less LaunchEvent
-based parts. In order to run on Windows, I have to use Outlook's Javascript runtime, so I have to make do without window
or document
.
At some point I have to fetch some data from the add-in's server. I tried using both Fetch and XHR to no avail.
Naive example with Fetch:
fetch("/JsonData").then(r => r.json());
However, this results in a TypeError: Network request failed
. Additionally, I am using Wireshark, and I see no request sent to the server.
Note that:
- I am in a Javascript-only runtime, so no
window
ordocument
- I have no control over the server root URL so I cannot hardcode it
- I have tried several tricks based on Javascript's stacktrace to get the current JS file URL, without success (best I got was
code
as the file URL using this snippet)
How can I use a relative URL to retrieve data from my server? This is such a common thing to do that I am sure there is a way to do it, just not the way I am doing it.
EDIT It appears that marking the add-in for debugging allows Fetch to work as expected with the exact same statement as above, even when no debugger is attached. This means enabling add-in debbugging changes something in the runtime that allows Fetch to target the add-in's own server.