From 213d6eb78cf2d762fe14c007cd49d4319d48b9e0 Mon Sep 17 00:00:00 2001 From: Randall Coding Date: Thu, 17 Mar 2022 10:00:22 -0600 Subject: [PATCH 1/2] Fix basic file upload functionality -> ElementHandle#set_input_files --- src/build.rs | 7 ++++--- src/imp/utils.rs | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/build.rs b/src/build.rs index a1a0790..17467c2 100644 --- a/src/build.rs +++ b/src/build.rs @@ -4,7 +4,9 @@ use std::{ path::{Path, PathBuf, MAIN_SEPARATOR} }; -const DRIVER_VERSION: &str = "1.11.0-1620331022000"; +// const DRIVER_VERSION: &str = "1.11.0-1620331022000"; +const DRIVER_VERSION: &str = "1.12.2"; +const NEXT: &str = ""; fn main() { let out_dir: PathBuf = env::var_os("OUT_DIR").unwrap().into(); @@ -79,10 +81,9 @@ fn url(platform: PlaywrightPlatform) -> String { // .contains("next") // .then(|| "/next") // .unwrap_or_default(); - let next = "/next"; format!( "https://playwright.azureedge.net/builds/driver{}/playwright-{}-{}.zip", - next, DRIVER_VERSION, platform + NEXT, DRIVER_VERSION, platform ) } diff --git a/src/imp/utils.rs b/src/imp/utils.rs index 4344e7e..fafd884 100644 --- a/src/imp/utils.rs +++ b/src/imp/utils.rs @@ -228,14 +228,14 @@ pub struct PdfMargins<'a, 'b, 'c, 'd> { #[derive(Debug, Serialize, PartialEq)] pub struct File { pub name: String, - pub mime: String, + pub mimeType: String, pub buffer: String } impl File { - pub fn new(name: String, mime: String, body: &[u8]) -> Self { + pub fn new(name: String, mimeType: String, body: &[u8]) -> Self { let buffer = base64::encode(body); - Self { name, mime, buffer } + Self { name, mimeType, buffer } } } /// Browser distribution channel. From 6019353db591bcd1baf1fbac84343099dc1a1c8b Mon Sep 17 00:00:00 2001 From: Randall Coding Date: Mon, 25 Apr 2022 00:41:49 -0500 Subject: [PATCH 2/2] Adds request event handling to BrowserContext --- src/api/browser_context.rs | 12 ++++++++---- src/api/request.rs | 2 +- src/imp/browser_context.rs | 19 +++++++++++++++---- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/api/browser_context.rs b/src/api/browser_context.rs index 3e2ef07..1ebc229 100644 --- a/src/api/browser_context.rs +++ b/src/api/browser_context.rs @@ -1,6 +1,6 @@ pub use crate::imp::browser_context::EventType; use crate::{ - api::{Browser, Page}, + api::{Browser, Page, request::Request}, imp::{ browser_context::{BrowserContext as Impl, Evt}, core::*, @@ -219,7 +219,7 @@ impl BrowserContext { // service_workers } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum Event { // BackgroundPage for chromium persistent // ServiceWorker @@ -242,14 +242,18 @@ pub enum Event { /// ]); /// console.log(await newPage.evaluate('location.href')); /// ``` - Page(Page) + Page(Page), + /// Emitted when a page issues a request. The request object is read-only. In order to intercept and mutate requests, see + /// [`method: Page.route`] or [`method: BrowserContext.route`]. + Request(Request), } impl From for Event { fn from(e: Evt) -> Event { match e { Evt::Close => Event::Close, - Evt::Page(w) => Event::Page(Page::new(w)) + Evt::Page(w) => Event::Page(Page::new(w)), + Evt::Request(w) => Event::Request(Request::new(w)), } } } diff --git a/src/api/request.rs b/src/api/request.rs index 10b1059..253b517 100644 --- a/src/api/request.rs +++ b/src/api/request.rs @@ -16,7 +16,7 @@ use crate::{ /// /// If request gets a 'redirect' response, the request is successfully finished with the 'requestfinished' event, and a new /// request is issued to a redirected url. -#[derive(Clone)] +#[derive(Debug, Clone)] pub struct Request { inner: Weak } diff --git a/src/imp/browser_context.rs b/src/imp/browser_context.rs index a068313..7c5adf1 100644 --- a/src/imp/browser_context.rs +++ b/src/imp/browser_context.rs @@ -3,7 +3,8 @@ use crate::imp::{ core::*, page::Page, prelude::*, - utils::{Cookie, Geolocation, Header, StorageState} + utils::{Cookie, Geolocation, Header, StorageState}, + request::Request, }; #[derive(Debug)] @@ -244,6 +245,7 @@ impl RemoteObject for BrowserContext { method: Str, params: Map ) -> Result<(), Error> { + println!("BrowserContext method: {}", method.as_str()); //DEBUG!! match method.as_str() { "page" => { let first = first_object(¶ms).ok_or(Error::InvalidParams)?; @@ -255,6 +257,12 @@ impl RemoteObject for BrowserContext { "close" => self.on_close(ctx)?, "bindingCall" => {} "route" => self.on_route(ctx, params)?, + "request" => { + let last = params.get("request").ok_or(Error::InvalidParams)?; + let OnlyGuid { guid } = serde_json::from_value((*last).clone())?; + let request = get_object!(ctx, &guid, Request)?; + self.emit_event(Evt::Request(request)); + } _ => {} } Ok(()) @@ -264,7 +272,8 @@ impl RemoteObject for BrowserContext { #[derive(Debug, Clone)] pub(crate) enum Evt { Close, - Page(Weak) + Page(Weak), + Request(Weak), } impl EventEmitter for BrowserContext { @@ -278,7 +287,8 @@ impl EventEmitter for BrowserContext { #[derive(Debug, Clone, Copy, PartialEq)] pub enum EventType { Close, - Page + Page, + Request } impl IsEvent for Evt { @@ -287,7 +297,8 @@ impl IsEvent for Evt { fn event_type(&self) -> Self::EventType { match self { Self::Close => EventType::Close, - Self::Page(_) => EventType::Page + Self::Page(_) => EventType::Page, + Self::Request(_) => EventType::Request, } } }