Table of Contents

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 IBrowsingContext

The current context.

target string

The 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 IBrowsingContext

The current context.

target string

The 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 IBrowsingContext

The current context.

commandId string

The 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 IBrowsingContext

The current context.

url Url

The 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 IBrowsingContext

The 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 IBrowsingContext

The 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 IBrowsingContext

The current context.

language string

The 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 IBrowsingContext

The 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 IBrowsingContext

The 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 IBrowsingContext

The 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 IBrowsingContext

The 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 IBrowsingContext

The 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 IBrowsingContext

The browsing context to use.

url Url

The 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 IBrowsingContext

The 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 IBrowsingContext

The current context.

type string

The 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 IBrowsingContext

The current context.

type string

The 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 IBrowsingContext

The current context.

language string

The 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 IBrowsingContext

The current context.

type string

The 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 IBrowsingContext

The current context.

eventName string

The name of the event to fire.

data T

The 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 IBrowsingContext

The 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 IBrowsingContext

The browsing context to use.

document IDocument

The 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 IBrowsingContext

The browsing context to use.

url Url

The URL to load.

cancel CancellationToken

The cancellation token.

Returns

Task<IDocument>

The task that creates the document.

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 IBrowsingContext

The browsing context to use.

request DocumentRequest

The request to issue.

cancel CancellationToken

The cancellation token.

Returns

Task<IDocument>

The task that creates the document.

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 IBrowsingContext

The browsing context to use.

response IResponse

The response to examine.

cancel CancellationToken

The cancellation token.

Returns

Task<IDocument>

The task that creates the document.

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 IBrowsingContext

The browsing context to use.

request Action<VirtualResponse>

Callback with the response to setup.

cancel CancellationToken

The cancellation token.

Returns

Task<IDocument>

The task that creates the document.

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 IBrowsingContext

The browsing context to use.

address string

The address to load.

cancellation CancellationToken

The cancellation token (optional)

Returns

Task<IDocument>

The task that creates the document.

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 IBrowsingContext

The browsing context to use.

url string

The optional base URL of the document. By default "http://localhost/".

cancellation CancellationToken

The cancellation token (optional)

Returns

Task<IDocument>

The new, yet empty, document.

ResolveTargetContext(IBrowsingContext, string?)

Resolves the given target context.

public static IBrowsingContext ResolveTargetContext(this IBrowsingContext context, string? target)

Parameters

context IBrowsingContext

The current context.

target string

The 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 IBrowsingContext

The current context.

url Url

The URL of the cookie.

value string

The 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 IBrowsingContext

The current context.

ex Exception

The exception to notify.