Possible to get string content of passed in function?

Jan 31, 2014 at 10:03 PM
Edited Jan 31, 2014 at 10:04 PM
We are building a bridge between CEF and C#. The C# console app is driven by javascript code. Used to basically drive a headless browser. So far clerscript has been a great tool. I was wondering if it is possible to pull the string content of a passed in JavaScript function...so I can then inject that back into the headless browser.

For example in my C# class I would have this code
    public void execute(dynamic function)
    {
        //Parse function into string and inject back into CEF Browser frame
    }
And the script driving all this looks like this
...
...
    page.open(address, function(status) { 

      if(status != "success")
      {
        console.log("Load failed");
        chromejs.exit(2);
      }

      // TRYING TO MAKE THIS PART WORK
      page.execute(function() {
        return document.title;
      });

      page.render("test.png");
      chromejs.exit();  
    });
Coordinator
Feb 1, 2014 at 11:06 AM
Greetings!

I was wondering if it is possible to pull the string content of a passed in JavaScript function

Do you mean the function's JavaScript source code? If so, then you can use JavaScript's Function.prototype.toString():
public void execute(dynamic function) {
    string sourceCode = function.toString();
    Console.WriteLine(sourceCode);
}
Cheers!