pub struct NewContextBuilder<'a> { /* private fields */ }Expand description
Builder for creating a new browser context with options.
Implementations§
Source§impl<'a> NewContextBuilder<'a>
impl<'a> NewContextBuilder<'a>
Sourcepub fn storage_state_path(self, path: impl Into<PathBuf>) -> Self
pub fn storage_state_path(self, path: impl Into<PathBuf>) -> Self
Set storage state from a file path.
Sourcepub fn storage_state(self, state: StorageState) -> Self
pub fn storage_state(self, state: StorageState) -> Self
Set storage state from an object.
Sourcepub fn geolocation(self, latitude: f64, longitude: f64) -> Self
pub fn geolocation(self, latitude: f64, longitude: f64) -> Self
Set geolocation.
Sourcepub fn geolocation_with_accuracy(
self,
latitude: f64,
longitude: f64,
accuracy: f64,
) -> Self
pub fn geolocation_with_accuracy( self, latitude: f64, longitude: f64, accuracy: f64, ) -> Self
Set geolocation with accuracy.
Sourcepub fn permissions(self, permissions: Vec<Permission>) -> Self
pub fn permissions(self, permissions: Vec<Permission>) -> Self
Grant permissions.
Sourcepub fn http_credentials(
self,
username: impl Into<String>,
password: impl Into<String>,
) -> Self
pub fn http_credentials( self, username: impl Into<String>, password: impl Into<String>, ) -> Self
Set HTTP credentials.
Sourcepub fn extra_http_headers(self, headers: HashMap<String, String>) -> Self
pub fn extra_http_headers(self, headers: HashMap<String, String>) -> Self
Set extra HTTP headers.
Sourcepub fn header(self, name: impl Into<String>, value: impl Into<String>) -> Self
pub fn header(self, name: impl Into<String>, value: impl Into<String>) -> Self
Add an extra HTTP header.
Sourcepub fn default_timeout(self, timeout: Duration) -> Self
pub fn default_timeout(self, timeout: Duration) -> Self
Set default timeout.
Set default navigation timeout.
Sourcepub fn timezone_id(self, timezone_id: impl Into<String>) -> Self
pub fn timezone_id(self, timezone_id: impl Into<String>) -> Self
Set timezone.
Sourcepub fn user_agent(self, user_agent: impl Into<String>) -> Self
pub fn user_agent(self, user_agent: impl Into<String>) -> Self
Set user agent.
Sourcepub fn color_scheme(self, color_scheme: ColorScheme) -> Self
pub fn color_scheme(self, color_scheme: ColorScheme) -> Self
Set color scheme.
Sourcepub fn reduced_motion(self, reduced_motion: ReducedMotion) -> Self
pub fn reduced_motion(self, reduced_motion: ReducedMotion) -> Self
Set reduced motion preference.
Sourcepub fn forced_colors(self, forced_colors: ForcedColors) -> Self
pub fn forced_colors(self, forced_colors: ForcedColors) -> Self
Set forced colors preference.
Sourcepub fn device_scale_factor(self, scale_factor: f64) -> Self
pub fn device_scale_factor(self, scale_factor: f64) -> Self
Set device scale factor (device pixel ratio).
Sourcepub fn device(self, device: DeviceDescriptor) -> Self
pub fn device(self, device: DeviceDescriptor) -> Self
Apply a device descriptor to configure the context.
This sets viewport, user agent, device scale factor, touch, and mobile mode based on the device descriptor.
§Example
use viewpoint_core::{Browser, devices};
let browser = Browser::launch().headless(true).launch().await?;
let context = browser.new_context_builder()
.device(devices::IPHONE_13)
.build()
.await?;Sourcepub fn record_video(self, options: VideoOptions) -> Self
pub fn record_video(self, options: VideoOptions) -> Self
Enable video recording for pages in this context.
Videos are recorded for each page and saved to the specified directory.
§Example
ⓘ
use viewpoint_core::{Browser, VideoOptions};
let browser = Browser::launch().headless(true).launch().await?;
let context = browser.new_context_builder()
.record_video(VideoOptions::new("./videos"))
.build()
.await?;Sourcepub async fn build(self) -> Result<BrowserContext, BrowserError>
pub async fn build(self) -> Result<BrowserContext, BrowserError>
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for NewContextBuilder<'a>
impl<'a> !RefUnwindSafe for NewContextBuilder<'a>
impl<'a> Send for NewContextBuilder<'a>
impl<'a> Sync for NewContextBuilder<'a>
impl<'a> Unpin for NewContextBuilder<'a>
impl<'a> !UnwindSafe for NewContextBuilder<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more