Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

External CSS not working from <link> #140

Closed
3 of 5 tasks
cyraid opened this issue Apr 19, 2023 · 1 comment
Closed
3 of 5 tasks

External CSS not working from <link> #140

cyraid opened this issue Apr 19, 2023 · 1 comment
Labels
Milestone

Comments

@cyraid
Copy link

cyraid commented Apr 19, 2023

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

@cyraid cyraid added the bug label Apr 19, 2023
@FlorianRappl FlorianRappl added this to the v1.0 milestone Jun 14, 2023
@FlorianRappl
Copy link
Contributor

I think this is a duplicate of #133.

I've added a test to validate that implementation and with the next preview / 1.0.0 this just works fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants