[][src]Struct headless_chrome::browser::tab::Tab

pub struct Tab { /* fields omitted */ }

A handle to a single page. Exposes methods for simulating user actions (clicking, typing), and also for getting information about the DOM and other parts of the page.

Methods

impl<'a> Tab[src]

pub fn new(target_info: TargetInfo, transport: Arc<Transport>) -> Fallible<Self>[src]

pub fn update_target_info(&self, target_info: TargetInfo)[src]

pub fn get_target_id(&self) -> &TargetId[src]

pub fn get_target_info(&self) -> Fallible<TargetInfo>[src]

Fetches the most recent info about this target

pub fn get_browser_context_id(&self) -> Fallible<Option<String>>[src]

pub fn get_url(&self) -> String[src]

pub fn set_user_agent(
    &self,
    user_agent: &str,
    accept_language: Option<&str>,
    platform: Option<&str>
) -> Fallible<()>
[src]

Allows overriding user agent with the given string.

pub fn call_method<C>(&self, method: C) -> Fallible<C::ReturnObject> where
    C: Method + Serialize + Debug
[src]

pub fn wait_until_navigated(&self) -> Fallible<&Self>[src]

pub fn navigate_to(&self, url: &str) -> Fallible<&Self>[src]

pub fn set_default_timeout(&self, timeout: Duration) -> &Self[src]

Set default timeout for the tab

This will be applied to all wait_for_element and wait_for_elements calls for this tab

let tab = browser.wait_for_initial_tab()?;
tab.set_default_timeout(std::time::Duration::from_secs(5));

pub fn wait_for_element(&self, selector: &str) -> Fallible<Element>[src]

pub fn wait_for_element_with_custom_timeout(
    &self,
    selector: &str,
    timeout: Duration
) -> Fallible<Element>
[src]

pub fn wait_for_elements(&self, selector: &str) -> Fallible<Vec<Element>>[src]

pub fn find_element(&self, selector: &str) -> Fallible<Element>[src]

pub fn get_document(&self) -> Fallible<Node>[src]

pub fn find_elements(&self, selector: &str) -> Fallible<Vec<Element>>[src]

pub fn describe_node(&self, node_id: NodeId) -> Fallible<Node>[src]

pub fn type_str(&self, string_to_type: &str) -> Fallible<&Self>[src]

pub fn press_key(&self, key: &str) -> Fallible<&Self>[src]

pub fn move_mouse_to_point(&self, point: Point) -> Fallible<&Self>[src]

Moves the mouse to this point (dispatches a mouseMoved event)

pub fn click_point(&self, point: Point) -> Fallible<&Self>[src]

pub fn capture_screenshot(
    &self,
    format: ScreenshotFormat,
    clip: Option<Viewport>,
    from_surface: bool
) -> Fallible<Vec<u8>>
[src]

Capture a screenshot of the current page.

If clip is given, the screenshot is taken of the specified region only. Element::get_box_model() can be used to get regions of certains elements on the page; there is also Element::capture_screenhot() as a shorthand.

If from_surface is true, the screenshot is taken from the surface rather than the view.

use headless_chrome::{protocol::page::ScreenshotFormat, Browser, LaunchOptionsBuilder};
let browser = Browser::new(LaunchOptionsBuilder::default().build().unwrap())?;
let tab = browser.wait_for_initial_tab()?;
let viewport = tab.navigate_to("https://en.wikipedia.org/wiki/WebKit")?
    .wait_for_element("#mw-content-text > div > table.infobox.vevent")?
    .get_box_model()?
    .margin_viewport();
 let png_data = tab.capture_screenshot(ScreenshotFormat::PNG, Some(viewport), true)?;

pub fn print_to_pdf(
    &self,
    options: Option<PrintToPdfOptions>
) -> Fallible<Vec<u8>>
[src]

pub fn reload(
    &self,
    ignore_cache: bool,
    script_to_evaluate: Option<&str>
) -> Fallible<&Self>
[src]

Reloads given page optionally ignoring the cache

If ignore_cache is true, the browser cache is ignored (as if the user pressed Shift+F5). If script_to_evaluate is given, the script will be injected into all frames of the inspected page after reload. Argument will be ignored if reloading dataURL origin.

pub fn enable_profiler(&self) -> Fallible<&Self>[src]

Enables the profiler

pub fn disable_profiler(&self) -> Fallible<&Self>[src]

Disables the profiler

pub fn start_js_coverage(&self) -> Fallible<&Self>[src]

Starts tracking which lines of JS have been executed

Will return error unless enable_profiler has been called.

Equivalent to hitting the record button in the "coverage" tab in Chrome DevTools. See the file tests/coverage.rs for an example.

By default we enable the 'detailed' flag on StartPreciseCoverage, which enables block-level granularity, and also enable 'call_count' (which when disabled always sets count to 1 or 0).

pub fn stop_js_coverage(&self) -> Fallible<&Self>[src]

Stops tracking which lines of JS have been executed If you're finished with the profiler, don't forget to call disable_profiler.

pub fn take_precise_js_coverage(&self) -> Fallible<Vec<ScriptCoverage>>[src]

Collect coverage data for the current isolate, and resets execution counters.

Precise code coverage needs to have started (see start_js_coverage).

Will only send information about code that's been executed since this method was last called, or (if this is the first time) since calling start_js_coverage. Another way of thinking about it is: every time you call this, the call counts for FunctionRanges are reset after returning.

The format of the data is a little unintuitive, see here for details: https://chromedevtools.github.io/devtools-protocol/tot/Profiler#type-ScriptCoverage

pub fn enable_request_interception(
    &self,
    patterns: &[RequestPattern],
    interceptor: RequestInterceptor
) -> Fallible<()>
[src]

Allows you to inspect outgoing network requests from the tab, and optionally return your own responses to them

The interceptor argument is a closure which takes this tab's Transport and its SessionID so that you can call methods from within the closure using transport.call_method_on_target.

The closure needs to return a variant of RequestInterceptionDecision (so, Continue or Response(String)).

pub fn continue_intercepted_request(
    &self,
    interception_id: &str,
    modified_response: Option<&str>
) -> Fallible<()>
[src]

Once you have an intercepted request, you can choose to let it continue by calling this.

If you specify a 'modified_response', that's what the requester in the page will receive instead of what they normally would've received.

pub fn enable_response_handling(&self, handler: ResponseHandler) -> Fallible<()>[src]

Lets you listen for responses, and gives you a way to get the response body too.

Please note that the 'response' does not include the body of the response -- Chrome tells us about them seperately (because you might quickly get the status code and headers from a server well before you receive the entire response body which could, after all, be gigabytes long).

Currently we leave it up to the caller to decide when to call fetch_body (the second argument to the response handler), although ideally it wouldn't be possible until Chrome has sent the Network.loadingFinished event.

Currently you can only have one handler registered, but ideally there would be no limit and we'd give you a mechanism to deregister the handler too.

pub fn enable_runtime(&self) -> Fallible<&Self>[src]

Enables runtime domain.

pub fn disable_runtime(&self) -> Fallible<&Self>[src]

Disables runtime domain

pub fn enable_debugger(&self) -> Fallible<()>[src]

Enables Debugger

pub fn disable_debugger(&self) -> Fallible<()>[src]

Disables Debugger

pub fn get_script_source(&self, script_id: &str) -> Fallible<String>[src]

Returns source for the script with given id.

Debugger must be enabled.

pub fn enable_log(&self) -> Fallible<&Self>[src]

Enables log domain.

Sends the entries collected so far to the client by means of the entryAdded notification.

See https://chromedevtools.github.io/devtools-protocol/tot/Log#method-enable

pub fn disable_log(&self) -> Fallible<&Self>[src]

Disables log domain

Prevents further log entries from being reported to the client

See https://chromedevtools.github.io/devtools-protocol/tot/Log#method-disable

pub fn start_violations_report(
    &self,
    config: Vec<ViolationSetting>
) -> Fallible<&Self>
[src]

Starts violation reporting

See https://chromedevtools.github.io/devtools-protocol/tot/Log#method-startViolationsReport

pub fn stop_violations_report(&self) -> Fallible<&Self>[src]

Stop violation reporting

See https://chromedevtools.github.io/devtools-protocol/tot/Log#method-stopViolationsReport

pub fn evaluate(
    &self,
    expression: &str,
    await_promise: bool
) -> Fallible<RemoteObject>
[src]

Evaluates expression on global object.

pub fn add_event_listener(
    &self,
    listener: Arc<dyn EventListener<Event> + Send + Sync>
) -> Fallible<Weak<dyn EventListener<Event> + Send + Sync>>
[src]

Adds event listener to Event

Make sure you are enabled domain you are listening events to.

Usage example

tab.enable_log()?;
tab.add_event_listener(Arc::new(move |event: &Event| {
    match event {
        Event::LogEntryAdded(_) => {
            // process event here
        }
        _ => {}
      }
    }))?;

pub fn remove_event_listener(
    &self,
    listener: &Weak<dyn EventListener<Event> + Send + Sync>
) -> Fallible<()>
[src]

pub fn get_bounds(&self) -> Result<CurrentBounds, Error>[src]

Get position and size of the browser window associated with this Tab.

Note that the returned bounds are always specified for normal (windowed) state; they do not change when minimizing, maximizing or setting to fullscreen.

pub fn set_bounds(&self, bounds: Bounds) -> Result<&Self, Error>[src]

Set position and/or size of the browser window associated with this Tab.

When setting the window to normal (windowed) state, unspecified fields are left unchanged.

pub fn get_cookies(&self) -> Fallible<Vec<Cookie>>[src]

Returns all cookies that match the tab's current URL.

pub fn get_title(&self) -> Fallible<String>[src]

Returns the title of the document.

tab.navigate_to("https://google.com")?;
tab.wait_until_navigated()?;
let title = tab.get_title()?;
assert_eq!(title, "Google");

Auto Trait Implementations

impl Unpin for Tab

impl Send for Tab

impl Sync for Tab

impl UnwindSafe for Tab

impl RefUnwindSafe for Tab

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

impl<T> Typeable for T where
    T: Any

fn get_type(&self) -> TypeId

Get the TypeId of this object.