How do I debug JavaScript in a WebBrowser control?

J

John Brock

I am using Visual Basic 2008 Express to write a Windows Forms
application that displays HTML/JavaScript pages in a WebBrowser
control. (I'm setting the form as the WebBrowser's ObjectForScripting
and calling "window.external.whatever()" from JavaScript when I
want JavaScript to call functions in the app).

Right now it can be very difficult to find bugs in the JavaScript
code. If I set ScriptErrorsSuppressed = False I sometimes get a
helpful popup. Or I can scatter JavaScript alert popups through
the code. But it would be very nice to have a real debugger! So
I'm trying to find out if there are any standard (or even non-standard)
ways to debug JavaScript in this situation.

(Note that I have IE8 installed on my PC. I understand there is
a spiffy new JavaScript debugger that comes with IE8 -- it's part
of the Developer Tools that pop up if I hit F12 while in IE. It
would be very nice to be able to use this to set breakpoints in
pages displayed in the WebBrowser, but there is no obvious way to
do this, as F12 does nothing here).
 
R

Ralph

I am using Visual Basic 2008 Express to write a Windows Forms
application that displays HTML/JavaScript pages in a WebBrowser
control.  (I'm setting the form as the WebBrowser's ObjectForScripting
and calling "window.external.whatever()" from JavaScript when I
want JavaScript to call functions in the app).

Right now it can be very difficult to find bugs in the JavaScript
code.  If I set ScriptErrorsSuppressed = False I sometimes get a
helpful popup.  Or I can scatter JavaScript alert popups through
the code.  But it would be very nice to have a real debugger!  So
I'm trying to find out if there are any standard (or even non-standard)
ways to debug JavaScript in this situation.

(Note that I have IE8 installed on my PC.  I understand there is
a spiffy new JavaScript debugger that comes with IE8 -- it's part
of the Developer Tools that pop up if I hit F12 while in IE.  It
would be very nice to be able to use this to set breakpoints in
pages displayed in the WebBrowser, but there is no obvious way to
do this, as F12 does nothing here).

try putting the following into your javascript code.

debugger;
 
J

John Brock

try putting the following into your javascript code.

debugger;

Thanks for the suggestion. I already tried that though (forgot to
mention it), and it doesn't seem to have any effect, at least not
from within a WebBrowser control.

(Interestingly, uncaught exceptions in my VB.NET code don't cause
the program to terminate when they occur as a result of JavaScript
calling a function in the app, so I have to explicitly catch and
display them if I want to see them. I wonder if that means anything?)
 
S

Scott M.

It's a bit of a hack, but you could insert a JavaScript alert(); within the
document to display pertinent info helpful for debugging.

-Scott
 
J

John Brock

I'm already using alert(), but a real debugger would be extremely
desirable. I'm sure the people doing ASP.NET programming aren't
using alert() -- (which is why I included an ASP.NET newsgroup in
my distribution list) -- but I have no idea if what they are doing
is applicable to me. Maybe if I were using a full version of Visual
Studio, rather than VB Express? But displaying JavaScript in a
WebBrowser control has got to be a fairly common practice, so I'm
really hoping there is something out there I can use.
 
S

Scott M.

When you do ASP .NET, you can use Visual Studio .NET and IE to debug client
side code pretty easily. I just don't think that process is applicable to
WinForms apps with embedded browser controls.

Sorry!

-Scott
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,526
Members
44,997
Latest member
mileyka

Latest Threads

Top