Skip to content

Commit

Permalink
Add latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanMagnan committed Dec 2, 2021
1 parent c41452a commit def26b2
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/HtmlAgilityPack.Shared/HtmlWeb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,10 @@ public partial class HtmlWeb

#region Properties

/// <summary>Gets or sets the automatic decompression.</summary>
/// <value>The automatic decompression.</value>
public DecompressionMethods AutomaticDecompression { get; set; }

/// <summary>
/// Gets or Sets a value indicating if document encoding must be automatically detected.
/// </summary>
Expand Down Expand Up @@ -1553,6 +1557,8 @@ private HttpStatusCode Get(Uri uri, string method, string path, HtmlDocument doc
req = WebRequest.Create(uri) as HttpWebRequest;
req.Method = method;
req.UserAgent = UserAgent;
req.AutomaticDecompression = AutomaticDecompression;

if (CaptureRedirect)
{
req.AllowAutoRedirect = false;
Expand Down Expand Up @@ -2517,6 +2523,17 @@ public HtmlDocument LoadFromBrowser(string url, Func<object, bool> isBrowserScri
var scripErrorSuppressedProperty = webBrowserType.GetProperty("ScriptErrorsSuppressed");
scripErrorSuppressedProperty.SetValue(webBrowser, true, null);

// disable popup
{
var newWindowEvent = webBrowser.GetType().GetEvent("NewWindow");
if(newWindowEvent != null)
{
var newWindowHandler = this.GetType().GetMethod("Web_NewWindow", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
Delegate newWindowDelegate = Delegate.CreateDelegate(newWindowEvent.EventHandlerType, null, newWindowHandler);
newWindowEvent.AddEventHandler(webBrowser, newWindowDelegate);
}
}

var navigateMethod = webBrowserType.GetMethod("Navigate", new Type[] {typeof(Uri)});
navigateMethod.Invoke(webBrowser, new object[] {uri});

Expand Down Expand Up @@ -2563,6 +2580,17 @@ public HtmlDocument LoadFromBrowser(string url, Func<object, bool> isBrowserScri

return doc;
}

private void Web_NewWindow(object sender, object e)
{
// we don't want a dynamic reference so we do it via reflection
var cancelProperty = e.GetType().GetProperty("Cancel");
if(cancelProperty != null)
{
cancelProperty.SetValue(e, true, null);
}
}

#endif

#endregion
Expand Down

0 comments on commit def26b2

Please sign in to comment.