i'm using visual studio c# 2010 web browser.
webbrowser 1 navigates link:
when reaches page, loads , freezes.
i don't think there wrong web page because chrome, firefox, , regular ie9 don't freeze @ all.
only web browser in c# program freezes when navigates link.
how prevent freezing? web page seems calling html data site.
i tried adding code program
this.webbrowser1.scripterrorssuppressed = true;
and changed registry values of web browser use internet explorer version 9 , far these 2 did not work.
this code i'm using
using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.windows.forms; namespace windowsformsapplication1 { public partial class form1 : form { public form1() { initializecomponent(); webbrowser1.scripterrorssuppressed = true; } private void button1_click(object sender, eventargs e) { webbrowser1.navigate("http://www.costco.com/iogear-wireless-1080p-hdmi-transmitter-and-receiver-3d-compatible-2x-hdmi-ports.product.100011675.html"); } private void webbrowser1_documentcompleted(object sender, webbrowserdocumentcompletedeventargs e) { } } }
the issue not webbrowser control per se, how particular website trying execute javascript gets stuck in loop.
compare , contrast:
1) change url http://google.com. works fine.
2) now. add event handler navigating event. like:
this.webbrowser1.navigating += new system.windows.forms.webbrowsernavigatingeventhandler(this.webbrowser1_navigating);
and
private void webbrowser1_navigating(object sender, webbrowsernavigatingeventargs e) { console.writeline("navigating to: " + e.url); }
you see there javascript function trying redirect page. here's shows in console output (goes on indefinitely):
navigating to: javascript:void((function(){document.open();document.domain='costco.com';document.write('<!doctype html>');document.close();})()) navigating to: about:blank navigating to: javascript:void((function(){document.open();document.domain='costco.com';document.write('<!doctype html>');document.close();})()) navigating to: about:blank navigating to: javascript:void((function(){document.open();document.domain='costco.com';document.write('<!doctype html>');document.close();})()) navigating to: about:blank navigating to: javascript:void((function(){document.open();document.domain='costco.com';document.write('<!doctype html>');document.close();})())
which makes webbrowser control unusable.
edit: ok, 1 stab @ workaround (this terrible, it's frustrating weird redirect loop happening in webbrowser control's browser).
if block navigating event being called before navigating event has completed, loads page , not freeze, , links appear work. goes this:
private void webbrowser1_navigated(object sender, webbrowsernavigatedeventargs e) { console.writeline("navigated to: " + e.url); isnavigating = false; webbrowser1.allownavigation = true; } bool isnavigating = false; private void webbrowser1_navigating(object sender, webbrowsernavigatingeventargs e) { if (isnavigating && e.url.tostring().contains("javascript:void((function(){document.open();document.domain='costco.com'")) { webbrowser1.stop(); webbrowser1.allownavigation = false; return; } isnavigating = true; console.writeline("navigating to: " + e.url); }