Vika
Vika

Reputation: 429

Save log to a string

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));
}

Upvotes: 0

Views: 46

Answers (2)

emluk
emluk

Reputation: 372

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; 
    });
}

Upvotes: 1

YungDeiza
YungDeiza

Reputation: 4530

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);
   });
}

Upvotes: 3

Related Questions