AngleSharp / AngleSharp.Js

:angel: Extends AngleSharp with a .NET-based JavaScript engine.
https://anglesharp.github.io
MIT License
103 stars 22 forks source link

Failed to run JavaScript #80

Closed ShivrajY closed 2 years ago

ShivrajY commented 2 years ago

Bug Report

Prerequisites

Description

AngleSharp couldn't parse Javascript. Page shows "You need to enable JavaScript to run this app."

Steps to Reproduce

using AngleSharp;
using AngleSharp.Js;
using AngleSharp.Io;
using AngleSharp.Dom;
using AngleSharp.Css;

var r = new DefaultHttpRequester("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:100.0) Gecko/20100101 Firefox/100.0", req =>
            {
                req.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8";
                req.AutomaticDecompression = System.Net.DecompressionMethods.All;
                req.CookieContainer = new System.Net.CookieContainer();
                req.AllowAutoRedirect = true;
            });

var config = Configuration.Default
    .WithEventLoop()
    .WithJs()
    .WithRequester(r)
    .WithDefaultLoader(new LoaderOptions { IsResourceLoadingEnabled = true })
    .WithCss();

var context = BrowsingContext.New(config);

var url = "https://aperturedata.io/";

var doc = await context.OpenAsync(url).WaitUntilAvailable();

var html = doc.ToHtml();
Console.WriteLine(html);
var x = html?.ToLowerInvariant().Contains("contact");
Console.WriteLine(x);

Expected behavior: [What you expected to happen] It should show true, as word "Contact" is present in the Dom text.

Actual behavior: [What actually happened] Didn't run JavaScript.

Environment details: [OS, .NET Runtime, ...] .Net 6.0, Macbook M1 Pro

Possible Solution

Like to see workaround like manually calling javascript function using AngleSharp [Optionally, share your idea to fix the issue]