IBrowserContext Interface#
Represents an isolated browser context with its own cookies, cache, and storage.
public interface IBrowserContext : System.IAsyncDisposable
Implements System.IAsyncDisposable
Properties#
Browser Property#
Gets the browser that owns this context.
Motus.Abstractions.IBrowser Browser { get; }
Property Value#
Pages Property#
Gets all pages in the context.
System.Collections.Generic.IReadOnlyList<Motus.Abstractions.IPage> Pages { get; }
Property Value#
System.Collections.Generic.IReadOnlyList<IPage>
Tracing Property#
Gets the tracing controller for this context.
Motus.Abstractions.ITracing Tracing { get; }
Property Value#
Methods#
AddCookiesAsync(IEnumerable<Cookie>) Method#
Adds cookies to the context.
System.Threading.Tasks.Task AddCookiesAsync(System.Collections.Generic.IEnumerable<Motus.Abstractions.Cookie> cookies);
Parameters#
cookies System.Collections.Generic.IEnumerable<Cookie>
The cookies to add.
Returns#
AddInitScriptAsync(string) Method#
Adds an initialization script to run in every page created in this context.
System.Threading.Tasks.Task AddInitScriptAsync(string script);
Parameters#
script System.String
The script content.
Returns#
ClearCookiesAsync() Method#
Clears all cookies in the context.
System.Threading.Tasks.Task ClearCookiesAsync();
Returns#
ClearPermissionsAsync() Method#
Clears all permission overrides.
System.Threading.Tasks.Task ClearPermissionsAsync();
Returns#
CloseAsync() Method#
Closes the context and all its pages.
System.Threading.Tasks.Task CloseAsync();
Returns#
CookiesAsync(IEnumerable<string>) Method#
Returns all cookies in the context, optionally filtered by URL.
System.Threading.Tasks.Task<System.Collections.Generic.IReadOnlyList<Motus.Abstractions.Cookie>> CookiesAsync(System.Collections.Generic.IEnumerable<string>? urls=null);
Parameters#
urls System.Collections.Generic.IEnumerable<System.String>
URLs to filter cookies by.
Returns#
System.Threading.Tasks.Task<System.Collections.Generic.IReadOnlyList<Cookie>>
The cookies.
ExposeBindingAsync(string, Func<object[],Task<object>>) Method#
Exposes a .NET function to be called from JavaScript in all pages.
System.Threading.Tasks.Task ExposeBindingAsync(string name, System.Func<object?[],System.Threading.Tasks.Task<object?>> callback);
Parameters#
name System.String
The function name to expose.
callback System.Func<System.Object[],System.Threading.Tasks.Task<System.Object>>
The callback to invoke.
Returns#
GetPluginContext() Method#
Gets the plugin context for registering extensions at runtime.
Motus.Abstractions.IPluginContext GetPluginContext();
Returns#
GrantPermissionsAsync(IEnumerable<string>, string) Method#
Grants the specified permissions to the context.
System.Threading.Tasks.Task GrantPermissionsAsync(System.Collections.Generic.IEnumerable<string> permissions, string? origin=null);
Parameters#
permissions System.Collections.Generic.IEnumerable<System.String>
The permissions to grant (e.g. "geolocation", "notifications").
origin System.String
Optional origin to grant permissions for.
Returns#
NewPageAsync() Method#
Creates a new page in this context.
System.Threading.Tasks.Task<Motus.Abstractions.IPage> NewPageAsync();
Returns#
System.Threading.Tasks.Task<IPage>
The new page.
RouteAsync(string, Func<IRoute,Task>) Method#
Registers a route handler for requests matching the URL pattern.
System.Threading.Tasks.Task RouteAsync(string urlPattern, System.Func<Motus.Abstractions.IRoute,System.Threading.Tasks.Task> handler);
Parameters#
urlPattern System.String
The URL pattern to match.
handler System.Func<IRoute,System.Threading.Tasks.Task>
The route handler.
Returns#
SetExtraHTTPHeadersAsync(IDictionary<string,string>) Method#
Sets extra HTTP headers for all requests in this context.
System.Threading.Tasks.Task SetExtraHTTPHeadersAsync(System.Collections.Generic.IDictionary<string,string> headers);
Parameters#
headers System.Collections.Generic.IDictionary<System.String,System.String>
The headers to set.
Returns#
SetGeolocationAsync(Geolocation) Method#
Sets the geolocation for the context.
System.Threading.Tasks.Task SetGeolocationAsync(Motus.Abstractions.Geolocation? geolocation);
Parameters#
geolocation Geolocation
The geolocation to set, or null to clear.
Returns#
SetOfflineAsync(bool) Method#
Sets whether the context is offline.
System.Threading.Tasks.Task SetOfflineAsync(bool offline);
Parameters#
offline System.Boolean
Whether to emulate offline mode.
Returns#
StorageStateAsync(string) Method#
Returns the storage state for this context.
System.Threading.Tasks.Task<Motus.Abstractions.StorageState> StorageStateAsync(string? path=null);
Parameters#
path System.String
Optional path to save the storage state to.
Returns#
System.Threading.Tasks.Task<StorageState>
The storage state.
UnrouteAsync(string, Func<IRoute,Task>) Method#
Removes a previously registered route handler.
System.Threading.Tasks.Task UnrouteAsync(string urlPattern, System.Func<Motus.Abstractions.IRoute,System.Threading.Tasks.Task>? handler=null);
Parameters#
urlPattern System.String
The URL pattern to unregister.
handler System.Func<IRoute,System.Threading.Tasks.Task>
The handler to remove. If null, removes all handlers for the pattern.
Returns#
Events#
Close Event#
Raised when the context is closed.
event EventHandler? Close;
Event Type#
Page Event#
Raised when a new page is created in the context.
event EventHandler<IPage>? Page;