Detailed Guide on How to Use TypeScript with Dynamics 365 - Part 3: Debugging TypeScript within Dynamics 365
As a Dynamics 365 Developer, it is quite exciting to use TypeScript within the system. By default, Dynamics don’t support TypeScript. Let’s see how we can sidestep this. In the previous posts, we've seen how to set up the environment, and deploy the code to Dynamics, Now we'll take a look at how we can debug our code within Dynamics 365.
Debugging TypeScript within Dynamics 365
We will use Fiddler. Install Fiddler from https://www.telerik.com/download/fiddler. Run Fiddler. Ensure that File > Capture Traffic is checked. If this is turned off, no traffic will be captured.
From the menu select Tools > Options. In the opened window select HTTPS tab and tick Decrypt HTTPS traffic mark. It will prompt to Trust the Fiddler Root certificate. Click Yes to it and each subsequent dialogue. This allows Fiddler to decrypt the HTTPS traffic between the browser and the server so that it can intercept it, log and respond with a different file where needed.
From the menu select Rules > Performance > Disable Caching. This will make sure no caching of files happening and files will be downloaded each time page is refreshed to pick up the latest version.
To do this we use a Fiddler extension called Imposter. Download and Install Imposter from https://github.com/gotdibbs/Imposter.Fiddler. This will add the Imposter tab in the Fiddler.
Select Imposter > Profiles > Add New. Enter a meaningful name for Profile Name. In the Base URL field, enter a fragment of the URL that you want Fiddler to keep an eye on to swap files for. In our case, this will be /WebResources/zvt_/. In the Local Directory field, enter the base path on your file system that Fiddler should try to use to look for matching files. Additionally, you can provide some overrides for specific files that won’t match the Base URL. Click Save.
From the Imposter menu, navigate to Profiles, then select your profile name, then click Enable.
Note: you can turn on as many profiles as you'd like. This is very comfortable while working with multiple instances.
Clear your browser's cache and navigate to a web resource in Dynamics 365. You should see your local files being served up in the browser.
Now you can debug your TypeScript code in Developer Tools(F12) or directly in your IDE. You can make changes in your TypeScript code and test it in the browser without deploying it into Dynamics 365. This is very powerful and can save us a lot of time.
This is the last(at this moment!) part of my blog posts on how to use TypeScript with Dynamics 365. Hope you enjoyed it!
Wish you a Happy Coding!