Class BrowsingContextExtensions
- Namespace
- AngleSharp
- Assembly
- AngleSharp.dll
A set of extensions for the browsing context.
public static class BrowsingContextExtensions
- Inheritance
-
BrowsingContextExtensions
- Inherited Members
Methods
CreateChildFor(IBrowsingContext, string?)
Creates the specified target browsing context.
public static IBrowsingContext CreateChildFor(this IBrowsingContext context, string? target)
Parameters
context
IBrowsingContextThe current context.
target
stringThe specified target name.
Returns
- IBrowsingContext
The new context.
FindChildFor(IBrowsingContext, string)
Gets the specified target browsing context.
public static IBrowsingContext? FindChildFor(this IBrowsingContext context, string target)
Parameters
context
IBrowsingContextThe current context.
target
stringThe specified target name.
Returns
- IBrowsingContext
The available context, or null, if the context does not exist yet.
GetCommand(IBrowsingContext, string)
Tries to get the command with the given name.
public static ICommand? GetCommand(this IBrowsingContext context, string commandId)
Parameters
context
IBrowsingContextThe current context.
commandId
stringThe command to get.
Returns
- ICommand
The command if any.
GetCookie(IBrowsingContext, Url)
Gets the cookie for the given URL, if any.
public static string GetCookie(this IBrowsingContext context, Url url)
Parameters
context
IBrowsingContextThe current context.
url
UrlThe URL of the cookie.
Returns
- string
The cookie or the empty string.
GetCssStyling(IBrowsingContext)
Tries to get the CSS styling service, if available.
public static IStylingService? GetCssStyling(this IBrowsingContext context)
Parameters
context
IBrowsingContextThe current context.
Returns
- IStylingService
The CSS styling service if any.
GetCulture(IBrowsingContext)
Gets the culture info associated with the current context.
public static CultureInfo GetCulture(this IBrowsingContext context)
Parameters
context
IBrowsingContextThe current context.
Returns
- CultureInfo
The culture info assigned to the context.
GetCultureFrom(IBrowsingContext, string)
Gets the culture from the language string (or the current culture).
public static CultureInfo GetCultureFrom(this IBrowsingContext context, string language)
Parameters
context
IBrowsingContextThe current context.
language
stringThe ISO culture name.
Returns
- CultureInfo
The culture info representing the language or the current culture.
GetDefaultEncoding(IBrowsingContext)
Gets the default encoding to use as initial guess.
public static Encoding GetDefaultEncoding(this IBrowsingContext context)
Parameters
context
IBrowsingContextThe current context.
Returns
- Encoding
The encoding from the provider or UTF-8.
GetDownloads<T>(IBrowsingContext)
Checks if the context is waiting for tasks from originator of type T to finish downloading.
public static IEnumerable<Task> GetDownloads<T>(this IBrowsingContext context) where T : INode
Parameters
context
IBrowsingContextThe context to use.
Returns
- IEnumerable<Task>
Enumerable of awaitable tasks.
Type Parameters
T
GetFactory<TFactory>(IBrowsingContext)
Gets a factory service instance. Exactly one has to be available.
public static TFactory GetFactory<TFactory>(this IBrowsingContext context) where TFactory : class
Parameters
context
IBrowsingContextThe current context.
Returns
- TFactory
The factory instance.
Type Parameters
TFactory
The type of the factory service.
GetJsScripting(IBrowsingContext)
Tries to get the JavaScript service, if available.
public static IScriptingService? GetJsScripting(this IBrowsingContext context)
Parameters
context
IBrowsingContextThe current context.
Returns
- IScriptingService
The JavaScript scripting service, if any.
GetLanguage(IBrowsingContext)
Gets the language of the current context.
public static string GetLanguage(this IBrowsingContext context)
Parameters
context
IBrowsingContextThe current context.
Returns
- string
The ISO name of the culture.
GetNavigationHandler(IBrowsingContext, Url)
Gets the navigation handler that supports the provided protocol.
public static INavigationHandler? GetNavigationHandler(this IBrowsingContext context, Url url)
Parameters
context
IBrowsingContextThe browsing context to use.
url
UrlThe URL to navigate to.
Returns
- INavigationHandler
The found navigation handler, if any.
GetProvider<TProvider>(IBrowsingContext)
Gets a provider service instance. At most one has to be available.
public static TProvider? GetProvider<TProvider>(this IBrowsingContext context) where TProvider : class
Parameters
context
IBrowsingContextThe current context.
Returns
- TProvider
The provider instance or null.
Type Parameters
TProvider
The type of the provider service.
GetResourceService<TResource>(IBrowsingContext, string)
Gets a resource service. Multiple resource services may be registered, so the one that matches the given mime-type will be returned, if any.
public static IResourceService<TResource>? GetResourceService<TResource>(this IBrowsingContext context, string type) where TResource : IResourceInfo
Parameters
context
IBrowsingContextThe current context.
type
stringThe mime-type of the resource.
Returns
- IResourceService<TResource>
The service instance or null.
Type Parameters
TResource
The type of the resource service.
GetScripting(IBrowsingContext, string)
Tries to get the scripting service for the given mime-type.
public static IScriptingService? GetScripting(this IBrowsingContext context, string type)
Parameters
context
IBrowsingContextThe current context.
type
stringThe type of the scripting language.
Returns
- IScriptingService
The scripting service, if any.
GetSpellCheck(IBrowsingContext, string)
Gets the spell check service for the given language, if any.
public static ISpellCheckService? GetSpellCheck(this IBrowsingContext context, string language)
Parameters
context
IBrowsingContextThe current context.
language
stringThe language of the spellchecker.
Returns
- ISpellCheckService
The spell check service, if any.
GetStyling(IBrowsingContext, string)
Tries to get the styling service for the given mime-type.
public static IStylingService? GetStyling(this IBrowsingContext context, string type)
Parameters
context
IBrowsingContextThe current context.
type
stringThe type of the style engine.
Returns
- IStylingService
The styling service if any.
InteractAsync<T>(IBrowsingContext, string, T)
Fires an interactive event at the given context.
public static Task InteractAsync<T>(this IBrowsingContext context, string eventName, T data)
Parameters
context
IBrowsingContextThe current context.
eventName
stringThe name of the event to fire.
data
TThe data to transport.
Returns
- Task
The task with the response to the event.
Type Parameters
T
The type of interactivity payload.
IsScripting(IBrowsingContext)
Gets if the context allows scripting or not.
public static bool IsScripting(this IBrowsingContext context)
Parameters
context
IBrowsingContextThe current context.
Returns
- bool
True if a scripting provider is available, otherwise false.
NavigateTo(IBrowsingContext, IDocument)
Navigates to the given document. Includes the document in the session history and sets it as the active document.
public static void NavigateTo(this IBrowsingContext context, IDocument document)
Parameters
context
IBrowsingContextThe browsing context to use.
document
IDocumentThe new document.
OpenAsync(IBrowsingContext, Url, CancellationToken)
Opens a new document loaded from the provided url asynchronously in the given context.
public static Task<IDocument> OpenAsync(this IBrowsingContext context, Url url, CancellationToken cancel = default)
Parameters
context
IBrowsingContextThe browsing context to use.
url
UrlThe URL to load.
cancel
CancellationTokenThe cancellation token.
Returns
OpenAsync(IBrowsingContext, DocumentRequest, CancellationToken)
Opens a new document loaded from the specified request asynchronously in the given context.
public static Task<IDocument> OpenAsync(this IBrowsingContext context, DocumentRequest request, CancellationToken cancel = default)
Parameters
context
IBrowsingContextThe browsing context to use.
request
DocumentRequestThe request to issue.
cancel
CancellationTokenThe cancellation token.
Returns
OpenAsync(IBrowsingContext, IResponse, CancellationToken)
Opens a new document created from the response asynchronously in the given context.
public static Task<IDocument> OpenAsync(this IBrowsingContext context, IResponse response, CancellationToken cancel = default)
Parameters
context
IBrowsingContextThe browsing context to use.
response
IResponseThe response to examine.
cancel
CancellationTokenThe cancellation token.
Returns
OpenAsync(IBrowsingContext, Action<VirtualResponse>, CancellationToken)
Opens a new document loaded from a virtual response that can be filled via the provided callback.
public static Task<IDocument> OpenAsync(this IBrowsingContext context, Action<VirtualResponse> request, CancellationToken cancel = default)
Parameters
context
IBrowsingContextThe browsing context to use.
request
Action<VirtualResponse>Callback with the response to setup.
cancel
CancellationTokenThe cancellation token.
Returns
OpenAsync(IBrowsingContext, string, CancellationToken)
Opens a new document loaded from the provided address asynchronously in the given context.
public static Task<IDocument> OpenAsync(this IBrowsingContext context, string address, CancellationToken cancellation = default)
Parameters
context
IBrowsingContextThe browsing context to use.
address
stringThe address to load.
cancellation
CancellationTokenThe cancellation token (optional)
Returns
OpenNewAsync(IBrowsingContext, string?, CancellationToken)
Opens a new document without any content in the given context.
public static Task<IDocument> OpenNewAsync(this IBrowsingContext context, string? url = null, CancellationToken cancellation = default)
Parameters
context
IBrowsingContextThe browsing context to use.
url
stringThe optional base URL of the document. By default "http://localhost/".
cancellation
CancellationTokenThe cancellation token (optional)
Returns
ResolveTargetContext(IBrowsingContext, string?)
Resolves the given target context.
public static IBrowsingContext ResolveTargetContext(this IBrowsingContext context, string? target)
Parameters
context
IBrowsingContextThe current context.
target
stringThe desired target frame.
Returns
- IBrowsingContext
The target context.
SetCookie(IBrowsingContext, Url, string)
Sets the cookie for the given URL.
public static void SetCookie(this IBrowsingContext context, Url url, string value)
Parameters
context
IBrowsingContextThe current context.
url
UrlThe URL of the cookie.
value
stringThe cookie value to set.
TrackError(IBrowsingContext, Exception)
Notifies the context of an exception that was handled internally.
public static void TrackError(this IBrowsingContext context, Exception ex)
Parameters
context
IBrowsingContextThe current context.
ex
ExceptionThe exception to notify.