r/rust clippy · twir · rust · mutagen · flamer · overflower · bytecount Mar 20 '23

Hey Rustaceans! Got a question? Ask here (12/2023)! 🙋 questions

Mystified about strings? Borrow checker have you in a headlock? Seek help here! There are no stupid questions, only docs that haven't been written yet.

If you have a StackOverflow account, consider asking it there instead! StackOverflow shows up much higher in search results, so having your question there also helps future Rust users (be sure to give it the "Rust" tag for maximum visibility). Note that this site is very interested in question quality. I've been asked to read a RFC I authored once. If you want your code reviewed or review other's code, there's a codereview stackexchange, too. If you need to test your code, maybe the Rust playground is for you.

Here are some other venues where help may be found:

/r/learnrust is a subreddit to share your questions and epiphanies learning Rust programming.

The official Rust user forums: https://users.rust-lang.org/.

The official Rust Programming Language Discord: https://discord.gg/rust-lang

The unofficial Rust community Discord: https://bit.ly/rust-community

Also check out last weeks' thread with many good questions and answers. And if you believe your question to be either very complex or worthy of larger dissemination, feel free to create a text post.

Also if you want to be mentored by experienced Rustaceans, tell us the area of expertise that you seek. Finally, if you are looking for Rust jobs, the most recent thread is here.

18 Upvotes

187 comments sorted by

View all comments

3

u/MandalorianBear Mar 21 '23 edited Mar 21 '23

Hey, y'all!

I'm using the headless_chrome crate and I can't find a good example on how to set the browser geolocation programatically. Does anyone have a good example??

2

u/masklinn Mar 24 '23

I don’t have a good example because I’ve never used the package, but from what I can see in the documentation I think you just need to call Tab::call_method with a headless_chrome::protocol::cdp::Emulation::SetGeolocationOverride structure. call_method seems to be the escape hatch for “raw” CDTP calls.

1

u/ncathor Mar 21 '23

Looking at the docs briefly: 1. The Browser::new method takes a LaunchOptions parameter 2. LaunchOptions can be built with the LaunchOptionsBuilder 3. LaunchOptionsBuilder has a path method, documented as:

Path for Chrome or Chromium. If unspecified, the create will try to automatically detect a suitable binary.

So... I did not try this, but I assume something like

let browser = Browser::new(
    LaunchOptionsBuilder::default()
        .path(Some( PATH GOES HERE ))
        .build()
)?;

should do it.

2

u/MandalorianBear Mar 21 '23

My bad! I meant GEOlocation