();
foreach (var script in scripts)
{
if (cspDeclared) continue;
if (script.HasAttribute("src") && (script.HasAttribute("defer") || script.HasAttribute("async"))) { deferred.Add(script); continue; }
if (!RunScript(script)) break;
DrainResources();
}
foreach (var script in deferred) { if (!RunScript(script)) break; DrainResources(); }
dom!.CompleteLoading(); CaptureEventOutput(); DrainResources(); InvalidateDocument();
return CurrentPage = RenderCurrent(pageDiagnostics.ToString().TrimEnd('\n'));
}
private BrowserPage RenderCurrent(string diagnostics)
{
var text = HtmlTextRenderer.Render(document!, currentAddress!, limits);
if (diagnostics.Length != 0)
{
if (diagnostics.Length + text.Length + 12 > limits.MaximumOutputCharacters)
throw new BrowserLimitException("The page and script output exceed their character limit.");
text += "\n\nConsole:\n" + diagnostics;
}
var title = string.IsNullOrWhiteSpace(document!.Title) ? currentAddress!.Host : document.Title;
if (string.IsNullOrWhiteSpace(title)) title = "XFESystem";
return new(currentAddress!.AbsoluteUri, BoundedText.Safe(title, 256), text);
}
private static Uri NormalizeAddress(string address)
{
var text = address.Trim();
if (text.Length is 0 or > 2_048) throw new ArgumentException("Enter a URL of at most 2048 characters.");
if (text.Any(char.IsControl)) throw new ArgumentException("The URL contains control characters.");
if (!text.Contains(':')) text = "https://" + text;
if (!Uri.TryCreate(text, UriKind.Absolute, out var target)) throw new ArgumentException("The URL is invalid.");
return target;
}
internal static void ValidateWebAddress(Uri address)
{
if (!address.IsAbsoluteUri || address.Scheme is not ("http" or "https") ||
string.IsNullOrEmpty(address.Host) || !string.IsNullOrEmpty(address.UserInfo))
throw new NotSupportedException("Only HTTP and HTTPS URLs without embedded credentials are supported.");
}
public const string StartPage = """
XFESystem Browser
XFESystem | XFEstudio
HTML + JavaScript
JavaScript pending
Self-developed CSS layout, external scripts and browser events.
Open official Monaco Editor
C# editor with website highlighting
Markdown with website CSS and scripts
HTTP/HTTPS 需要当前平台提供网络适配器。
""";
}