#Installing crate breaks code

72 messages · Page 1 of 1 (latest)

dire spire
#

Greetings. I'm a beginner rust developer.
I'm writing project to automate some of my web3 related stuff, so mostly I do browser automation.
For that purpouse I use chromiumoxide crate, with their fetcher feature.
The problem arise when I install ethers-rs crate, to be able to sign some user-interactions in automated manner.
Just installing this package makes my code panic with this error:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: BrowserFail(ChannelSendError(Send(SendError { kind: Disconnected })))'

It worth noting that there also tokio::task handler, which polls browser websocket from another thread and therefore emits additional panic:

thread 'tokio-runtime-worker' panicked at 'data did not match any variant of untagged enum Message', autoblur-node-rs\src\blur\browser.rs:74:21

Can't imagine how installing crate affects code in another crate (I exclude bug in my own code because without ethers-rs installation it works flawlessly)

dire spire
peak cipher
#

so maybe that dependency, somewhere in its dependency tree, enables a feature in a crate you use

that's not meant to happen, features are meant to be purely additive, but it can

fleet tundra
dire spire
fleet tundra
dire spire
# fleet tundra what does the code around like 74 look like?
self.page = Some(
            self.browser
                .new_page("about:blank")   // <=== error here
                .await
                .map_err(move |error| Box::new(BlurInitError::BrowserFail(error)))
                .unwrap(),
        );

        let page = self.page.as_mut().unwrap();

        // load interceptor
        page.evaluate_on_new_document(REQ_INTERCEPT_SCRIPT.to_string().replace("{}", &pk))
            .await
            .map_err(move |error| Box::new(BlurInitError::BrowserFail(error)))?;
fleet tundra
fleet tundra
#

oh wait it has tracing built in

#

do you have tracing setup for the project by chance?

dire spire
fleet tundra
#

do you have a subscriber?

#

hmm though its probably going to be the same error as above...

#

what I really want is the json

fleet tundra
# dire spire Sure

of you could change line 139 (at least thats what it is on the repo) from

return match serde_json::from_slice::<Message<T>>(&msg.into_data()) {

to

return match serde_json::from_slice::<Message<T>>(dbg!(&msg.into_data())) {

I think that would be informative as then it should print out the json message the server sent

#

it will be in the form of a long list of numbers, but we can convert it to text if we get it

dire spire
fleet tundra
#

On another note, after digging through your cargo tree output I think I might know what is happening

#

so it looks like chromiumoxide uses the async-std runtime by default

#

however either-rs polls in a package that switches things to use the tokio runtime

#

so maybe you need to set chromiumoxide to also use tokio

dire spire
fleet tundra
dire spire
#

Yes

fleet tundra
#

well that idea goes out the window

#

it's either the browser sending back a "bad" message or the websocket implementation somehow

dire spire
#

How can I force cargo to recompile chromiumoxide ?

fleet tundra
#

though its usually good picking up changes by itself

dire spire
#

and last decoded output:

fleet tundra
#

Good response

{
  "id": 6,
  "result": {
    "frameTree": {
      "frame": {
        "id": "5D60618AD49142710F6B71FC4777CB0E",
        "loaderId": "DC528A83E5EE10D4FB59D26759340545",
        "url": "chrome://newtab/",
        "domainAndRegistry": "",
        "securityOrigin": "chrome://newtab",
        "mimeType": "text/html",
        "adFrameStatus": {
          "adFrameType": "none"
        },
        "secureContextType": "Secure",
        "crossOriginIsolatedContextType": "NotIsolated",
        "gatedAPIFeatures": []
      }
    }
  },
  "sessionId": "FEA4F65DBB9FB7573FEA7820079DA35B"
}

bad:

{
  "method": "Page.lifecycleEvent",
  "params": {
    "frameId": "5D60618AD49142710F6B71FC4777CB0E",
    "loaderId": "DC528A83E5EE10D4FB59D26759340545",
    "name": "commit",
    "timestamp": 106302.789599
  },
  "sessionId": "FEA4F65DBB9FB7573FEA7820079DA35B"
}
#

so um yeah that doesn't seem right

dire spire
#

hold on, I will remove ethers-rs and will provide you with a output

fleet tundra
#

k

#

I just decoded the one above the last to get that first one

#

it looks like an event maybe

#
/// A received `Event` from the websocket where the `params` is deserialized as
/// json
#[derive(Deserialize, Debug, PartialEq, Eq, Clone)]
pub struct CdpJsonEventMessage {
    /// Name of the method
    pub method: MethodId,
    /// The session this event is meant for.
    pub session_id: Option<String>,
    /// Json payload of the event
    pub params: serde_json::Value,
}

ah yeah

#

and wouldn't you know it session_id doesn't have a rename

#

though I need to check if the other code actually used the default

#

it doesn't

dire spire
fleet tundra
#

Now I have no idea why you didn't get any events before

dire spire
fleet tundra
fleet tundra
#

so I guess the question is why does the browser respond with the session ID when ethers-rs is there

fleet tundra
dire spire
fleet tundra
dire spire
#
pub struct CdpJsonEventMessage {
    /// Name of the method
    pub method: MethodId,
    /// The session this event is meant for.
    #[serde(rename = "sessionId", skip_serializing_if = "Option::is_none")]
    pub session_id: Option<String>,
    /// Json payload of the event
    pub params: serde_json::Value,
}
fleet tundra
#

the serializing stuff isn't needed

#

because it only has Deserialize, but still that shouldn't change anything

dire spire
#

yeah that's what I thought

fleet tundra
#

I dont see what else would cause the deserialization to fail

fleet tundra
#

i wonder how that plays with untagged

dire spire
fleet tundra
#

yeah I noticed that to

fleet tundra
dire spire
fleet tundra
#

I have no clue why it fails to deserialize that message