Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request interception #83

Open
ghost opened this issue Jan 6, 2022 · 6 comments
Open

Request interception #83

ghost opened this issue Jan 6, 2022 · 6 comments

Comments

@ghost
Copy link

ghost commented Jan 6, 2022

Is request interception supported? I see NetworkManager functions that seem like they may enable request interception (they appear to be related to Handler and not Page), but I don't see how to implement them in my own code.

@ghost
Copy link
Author

ghost commented Jan 13, 2022

I overlooked page.event_listener::<RequestWillBeSent however it is not catching all requests. The code in #28 does not enable fetch/XHR request interception. I also get some errors while the page is navigating:

[2022-01-13T03:46:18Z ERROR chromiumoxide::handler] WS Connection error: Serde(Error("data did not match any variant of untagged enum Message", line: 0, column: 0))
[2022-01-13T03:46:18Z ERROR chromiumoxide::conn] Failed to deserialize WS response data did not match any variant of untagged enum Message
[2022-01-13T03:46:18Z ERROR chromiumoxide::handler] WS Connection error: Serde(Error("data did not match any variant of untagged enum Message", line: 0, column: 0))
[2022-01-13T03:46:19Z ERROR chromiumoxide::conn] Failed to deserialize WS response data did not match any variant of untagged enum Message
[2022-01-13T03:46:19Z ERROR chromiumoxide::handler] WS Connection error: Serde(Error("data did not match any variant of untagged enum Message", line: 0, column: 0))
[2022-01-13T03:46:19Z ERROR chromiumoxide::conn] Failed to deserialize WS response data did not match any variant of untagged enum Message
[2022-01-13T03:46:19Z ERROR chromiumoxide::handler] WS Connection error: Serde(Error("data did not match any variant of untagged enum Message", line: 0, column: 0))

The trace of one of the error messages looks like this:

[2022-01-13T03:47:24Z TRACE tungstenite::protocol] Received message {"method":"Network.requestWillBeSent","params":{"requestId":"475742D522E65043717C83E682E60A29","loaderId":"","documentURL":"https://gql.twitch.tv/gql","request":{"url":"https://gql.twitch.tv/gql","method":"OPTIONS","headers":{"Accept":"*/*","Access-Control-Request-Method":"POST","Access-Control-Request-Headers":"authorization,client-id,device-id","Origin":"https://www.twitch.tv","User-Agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36","Sec-Fetch-Mode":"cors"},"initialPriority":"High","referrerPolicy":"strict-origin-when-cross-origin"},"timestamp":88031.531252,"wallTime":1642045644.800056,"initiator":{"type":"preflight","url":"https://gql.twitch.tv/gql","requestId":"84218.9"},"type":"Other","hasUserGesture":false},"sessionId":"2080018A284A5608EEEC8F7A84708972"}
[2022-01-13T03:47:24Z ERROR chromiumoxide::conn] Failed to deserialize WS response data did not match any variant of untagged enum Message
[2022-01-13T03:47:24Z ERROR chromiumoxide::handler] WS Connection error: Serde(Error("data did not match any variant of untagged enum Message", line: 0, column: 0))

It looks like there are 2 requests that cause errors, and another error is triggered on ResponseReceived for each of the requests. These errors don't seem related to request interception, but I noticed that these requests hang indefinitely and the page never finishes loading.

@Sytten
Copy link
Contributor

Sytten commented Jan 4, 2023

Did you manage to do request interception?

@Sytten
Copy link
Contributor

Sytten commented Jan 4, 2023

You can look at my PR #118, I added an example

@goni098
Copy link

goni098 commented Jul 3, 2023

@Sytten Can you give a example to get the reponse body after requesting network with a given url ?

@Sytten
Copy link
Contributor

Sytten commented Jul 11, 2023

It's been a while since I touched this code, there is probably an event you can listen to to get that data. I don't have that need, but feel free to share if you manage to do it.

@escritorio-gustavo
Copy link
Contributor

Would it be possible to do this on the browser level, so that setting it up once affects all pages? I tried following the example, but it didn't work because Browser doesn't implement Clone.

Is there another way? And if not, Would it be worth it (or even possible) implementing the Clone trait for Browser?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants