2

Is there any possibility to read local variable from javascript in c# WebBrowser component? In standard web browser like Chrome I have access to local variables by debugger (Google Developer Tools) and then I can bring variable to global scope like this:

window.myGlovalVar = myLocalVar;

What possibilities I have in my case?

0

1 Answer 1

2

You still can use Visual Studio Debugger to debug JavaScript in a custom application hosting the WebBrowser control, as described here.

Another option is to type and execute WebBrowser.InvokeScript (WPF) or WebBrowser.Document.InvokeScript (WinForms) directly from the debugger's QuickWatch window.

E.g., set a variable:

webBrowser.InvokeScript("execScript", "window.myGlovalVar = myLocalVar")

Query it later (will return the value myLocalVar remembered above):

webBrowser.InvokeScript("eval", "window.myGlovalVar")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.