diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3e989d0..6704e96 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,9 @@
+# 1.3.2
+
+Released on Monday, November 23 2026.
+
+- Fixed a document created without navigating (e.g. by `DOMParser` or `XMLHttpRequest`) replacing the page and running its scripts
+
# 1.3.1
Released on Sunday, November 22 2026.
diff --git a/src/AngleSharp.Xml.Docs/package.json b/src/AngleSharp.Xml.Docs/package.json
index ff8e22d..f071f73 100644
--- a/src/AngleSharp.Xml.Docs/package.json
+++ b/src/AngleSharp.Xml.Docs/package.json
@@ -1,6 +1,6 @@
{
"name": "@anglesharp/xml",
- "version": "1.3.1",
+ "version": "1.3.2",
"preview": true,
"description": "The doclet for the AngleSharp.Xml documentation.",
"keywords": [
diff --git a/src/AngleSharp.Xml.Tests/Dom/Acid3Tests.cs b/src/AngleSharp.Xml.Tests/Dom/Acid3Tests.cs
index 76c7819..7a57fbe 100644
--- a/src/AngleSharp.Xml.Tests/Dom/Acid3Tests.cs
+++ b/src/AngleSharp.Xml.Tests/Dom/Acid3Tests.cs
@@ -52,17 +52,5 @@ await context.OpenAsync(res => res
{
}
}
-
- [Test]
- public void ConfigurationNamesTheLibrarySoItsDomExtensionsAreFound()
- {
- var config = Configuration.Default.WithXml().WithXml();
- var libraries = config.Services
- .Where(m => m is not Delegate)
- .Select(m => m.GetType().Assembly)
- .Count(m => m == typeof(XmlParser).Assembly);
-
- Assert.AreEqual(1, libraries);
- }
}
}
diff --git a/src/AngleSharp.Xml.Tests/Dom/XmlDocumentFactories.cs b/src/AngleSharp.Xml.Tests/Dom/XmlDocumentFactories.cs
index 7f93c79..db3a58b 100644
--- a/src/AngleSharp.Xml.Tests/Dom/XmlDocumentFactories.cs
+++ b/src/AngleSharp.Xml.Tests/Dom/XmlDocumentFactories.cs
@@ -1,13 +1,38 @@
namespace AngleSharp.Xml.Tests.Dom
{
using AngleSharp.Dom;
+ using AngleSharp.Io;
using AngleSharp.Xml.Dom;
using NUnit.Framework;
using System;
+ using System.Threading;
+ using System.Threading.Tasks;
[TestFixture]
public class XmlDocumentFactories
{
+ [Test]
+ public async Task DocumentThatIsJustDataDoesNotReplaceThePage()
+ {
+ var navigationDisabled = typeof(CreateDocumentOptions).GetProperty("IsNavigationDisabled");
+
+ if (navigationDisabled is null)
+ {
+ Assert.Ignore("The option is part of AngleSharp 1.10.");
+ }
+
+ var context = BrowsingContext.New(Configuration.Default.WithXml());
+ var page = await context.OpenAsync(res => res.Content("
page").Address("http://localhost/"));
+ var response = VirtualResponse.Create(res => res.Content("").Address("http://localhost/data.xml").Header("Content-Type", "application/xml"));
+ var options = new CreateDocumentOptions(response);
+ navigationDisabled.SetValue(options, true);
+
+ var document = await context.GetService().CreateAsync(context, options, CancellationToken.None);
+
+ Assert.AreEqual("root", document.DocumentElement.LocalName);
+ Assert.AreSame(page, context.Active);
+ }
+
[Test]
public void DeclarationMetadataIsExposed()
{
diff --git a/src/AngleSharp.Xml/XmlConfigurationExtensions.cs b/src/AngleSharp.Xml/XmlConfigurationExtensions.cs
index 8e1e1da..fcadc85 100644
--- a/src/AngleSharp.Xml/XmlConfigurationExtensions.cs
+++ b/src/AngleSharp.Xml/XmlConfigurationExtensions.cs
@@ -38,24 +38,9 @@ public static IConfiguration WithXml(this IConfiguration configuration)
documentFactory.Register(MimeTypeNames.Svg, LoadSvgAsync);
}
- // AngleSharp.Js exposes the DOM extensions of the libraries it finds services of, but
- // only sees the parser once it was created (e.g. createDocument would be missing)
- if (!configuration.Services.OfType().Any())
- {
- configuration = configuration.With(XmlLibrary.Instance);
- }
-
return configuration.WithOnly(ctx => new XmlParser(ctx));
}
- ///
- /// Marks a configuration as using this library.
- ///
- private sealed class XmlLibrary
- {
- public static readonly XmlLibrary Instance = new XmlLibrary();
- }
-
private static Task LoadXmlAsync(IBrowsingContext context, CreateDocumentOptions options, CancellationToken cancellationToken)
{
var document = new XmlDocument(context, options.Source);
@@ -72,13 +57,32 @@ private static async Task LoadAsync(IBrowsingContext context, Documen
{
var parser = context.GetService() ?? throw new InvalidOperationException("The IXmlParser service has been removed. Cannot continue.");
document.Setup(options.Response, options.ContentType, options.ImportAncestor);
- context.NavigateTo(document);
+
+ // a document that is just data (e.g. of DOMParser or XMLHttpRequest) neither replaces the page, nor runs anything
+ if (!IsSet(options, "IsNavigationDisabled"))
+ {
+ context.NavigateTo(document);
+ }
await parser.ParseDocumentAsync(document, cancellationToken).ConfigureAwait(false);
- await RunScriptsAsync(context, document, cancellationToken).ConfigureAwait(false);
+
+ if (!IsSet(options, "IsNavigationDisabled") && !IsSet(options, "IsScriptingDisabled"))
+ {
+ await RunScriptsAsync(context, document, cancellationToken).ConfigureAwait(false);
+ }
+
return document;
}
+ ///
+ /// Reads an option of AngleSharp 1.10 (or later), which is not set with an earlier version.
+ ///
+ private static Boolean IsSet(CreateDocumentOptions options, String name)
+ {
+ var property = typeof(CreateDocumentOptions).GetProperty(name);
+ return property?.GetValue(options) is true;
+ }
+
///
/// Runs the (inline) scripts of the XHTML elements of a document that was navigated to,
/// in tree order once it has been parsed.
diff --git a/src/Directory.Build.props b/src/Directory.Build.props
index 3827f2d..8197532 100644
--- a/src/Directory.Build.props
+++ b/src/Directory.Build.props
@@ -2,7 +2,7 @@
Adds a powerful XML and DTD parser to AngleSharp.
AngleSharp.Xml
- 1.3.1
+ 1.3.2
latest
true
true