Save log to a string

Viewed 37

I am debugging a webpage inside Unity that gets printed to a console. How do I copy the debug message into a string?

public string message; //print to this string

void SomeFunction(){
web.ExecuteJavaScript ("document.querySelector('iframe')).click();", s => Debug.Log (s));
}
2 Answers

You just need to assign s to the target string:

public string message; //print to this string

void SomeFunction() {
   web.ExecuteJavaScript ("document.querySelector('iframe')).click();", s => {
      message = s;
      Debug.Log (s);
   });
}

This should do the trick

public string message; //print to this string

void SomeFunction(){
    web.ExecuteJavaScript ("document.querySelector('iframe')).click();", 
    s => {
       Debug.Log (s);
       message = s; 
    });
}
Related