2 Feb 2018

Quick testing JavaScript on Viewer (.NET)

Friday is a good day to try something new, right? At this previous post I showed how to run JavaScript code on a Viewer hosted on our .NET desktop app. Now let's move it a bit further, can we run write code and run it on the fly? Sure! 

First, note that on your browser console you still can type code and run then, which is a powerful tool for testing small pieces of code. So this post if for another scenario where you really want to type or load a full .js full. 

Let's see it in action before anything else:

To make it work we need the  .EvaluateScriptAsync() from the other post and a place where we can type our code, so I decided to use ScintillaNET package (NuGet) to edit the code. The UI is almost a direct copy & paste from their sample, with some small changes: the bottom Run button (or Ctrl+R) and the text box with results. The code also integrates with the Cefsharp browser to run the code. 

Get the full source code at this github repo, see integration points from lines 20 to 85 at this file.

Enjoyed the sample tool? Suggestions? 

Related Article

Posted By

Augusto Goncalves

Developer Advocate at Autodesk since 2008, working with both desktop and web/cloud apps using top technologies, like C#, JavaScript, NodeJS and any other that can solve problems and improve workflows. See my samples on Github and follow me on Twitter for updates.