Skip to content

External CSS not working from <link> #140

@cyraid

Description

@cyraid

Bug Report

Prerequisites

  • Can you reproduce the problem in a MWE?
  • Are you running the latest version of AngleSharp? (of AngleSharp.Css yes, but since it only accepts certain versions of AngleSharp, technically no, not of AngleSharp, but yes of AngleSharp.Css)
  • Did you check the FAQs to see if that helps you? (am not aware of an AngleSharp.Css FAQ)
  • Are you reporting to the correct repository? (there are multiple AngleSharp libraries, e.g., AngleSharp.Css for CSS support)
  • Did you perform a search in the issues?

Description

    var config = Configuration.Default
      .WithRenderDevice(
        new DefaultRenderDevice {
          DeviceWidth = 1920,
          DeviceHeight = 1080
        })
      .WithDefaultLoader(
        new LoaderOptions() {
          IsNavigationDisabled = true,
          IsResourceLoadingEnabled = true
        })
      .WithCss();

    var context = BrowsingContext.New(config);
    var doc = await context.OpenAsync(req => req.Content(@"""
      <html>
        <head><link href=""https://some/tested/url.css"" rel=""stylesheet""></head>
        <body><label>HI</label></body>
      </html>
    """));

    /*var style = doc.CreateElement<IHtmlStyleElement>();
    style.TextContent = File.ReadAllText("some/actual/file.css");

    doc.Head?.AppendElement(style);*/

    var window = doc.DefaultView;
    var tree = window.Render();
    var label = tree.Find(doc.QuerySelector("label"));

    await label.DownloadResources();

    Console.WriteLine($"min-width: {window.GetComputedStyle(label.Ref as HtmlElement).GetMinWidth()}");

The css file has:

label, .test {
  min-width: 50px;
  border: 1px solid green;
}

If you uncomment the adding IHtmlStyleElement, it will work (injecting style directly), but when using the <link> it won't get processed.

Steps to Reproduce

Use code above.

Expected behavior: GetMinWidth() should return "50px" like it does when I add an IHtmlStyleElement directly.

Actual behavior: GetMinWidth() returns ""

Environment details: Windows 11, .NET 7

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions