Open Web Browser With Multiple Tabs

Hi, I have found this other blog post where they talk about using the open library to open up a website url in a browser.

Now I would like to make a little cli tool for myself that opens up say 5 or 10 different urls as different tabs within one browser window.

I don't see any way of doing this explained in the docs, and it's not clear to me from the api that you have to use there...

I could loop over my vector of strings and call open::that on each one, but I'm assuming they would each open in their own browser window which is not what I want.

So, I'm wondering- is it possible to do this in one window? Is it possible using the open library? How would you do it?

Thanks!

It’s up to the browser to decide what to do with links from other programs, but at least on my system using Firefox, they open in new tabs if there is an existing window.

You can test this with a simple program like:

fn main() {
    open::that("http://rust-lang.org").unwrap();
    open::that("http://rust-lang.org").unwrap();
}
1 Like

My guess is that this going to be highly dependent on your OS, browser, and perhaps even whether the browser is running already or not. So, if you're trying to do it in a cross-platform way...could be difficult. If you just want something that works for you and your browser/desktop, then your best bet is to try it out.

FWIW, the open library also provides the commands method which returns the actual commands it will run to try and open your browser; so you could try to inspect those and modify them. For example, Firefox takes a new-tab command line option.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.