The DocumentText property retrieves the HTML
markup for the current document loaded in the browser. This includes
the complete contents of the <html> element, such
as the <head> and <body>
sections, rather than just the visible text.
The text returned will reflect the current state of the document at
the time the function is called. If the page has been dynamically
modified by scripts after it was initially loaded, those changes will
be included. This property should only be checked after navigation has completed.
If called while a page is still loading, the results may be incomplete
or empty. When the content is provided by a local file or string, the
returned HTML will be the original content that was passed to the
control. The returned text is raw HTML and may contain scripts, style
definitions, and markup that are not directly suitable for display in
a plain-text context.
If a blank page is currently being displayed, such as when
navigating to about:blank or by setting the current document
text to an empty string, this property can still return a value.
Internally, the browser creates a blank page using the markup
"<html><head></head><body></body></html>"
and that is what this property will return.
Setting the value of this property replaces the currently displayed
content with the specified HTML or plain text. If the text does not
contain any markup, it will be wrapped in HTML as preformatted text
and displayed using the default monospaced font. If it is an empty
string, the
browser will display a blank page. If the string is very large (over 256 KiB), the
control will first write the text to a local temporary file and then
instruct the browser to navigate to that file. This is done to work around
limitations in the Edge WebView2 control when handling long inline strings.
The temporary file will be automatically deleted when it is no longer
needed.
Important: It is possible to embed markup that references images,
scripts, or other resources located on the Internet. While this is
supported, you should be aware of potential risks when combining local
content with external resources. This can create mixed-content scenarios
and introduce cross-origin or security issues. Applications that render
untrusted content should avoid linking to remote resources and ensure
that the HTML provided is properly validated.