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

SessionNotCreated error on second run with fantoccini and geckodriver #206

Closed
jhiver opened this issue Feb 17, 2023 · 1 comment
Closed

Comments

@jhiver
Copy link

jhiver commented Feb 17, 2023

Hello & thanks for your library!

I have the following issue with this code:

use fantoccini::ClientBuilder;
use std::error::Error;


#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    // Launch a Firefox browser instance using WebDriver
    let client = ClientBuilder::native()
        .connect("http://localhost:4444")
        .await?;

    // Navigate to a website
    client.goto("https://google.com/").await?;

    Ok(())
}

When running the code multiple times, it results in a SessionNotCreated error with the following message:

Error: SessionNotCreated(WebDriver { error: SessionNotCreated, message: "Session is already started", stacktrace: "" })

I have to kill/restart geckodriver to be able to run the code again.

Any ideas how to fix it?

Also, it would be really handy to have some code in the README that shows how to save / reuse session/profile information such as cookies.

Thanks a lot!

@jonhoo
Copy link
Owner

jonhoo commented Mar 4, 2023

Ah, yes, this is because Firefox's geckodriver doesn't allow concurrent sessions, combined with the fact that you're not calling and then awaiting Client::close which would cleanly terminate the previous session before the next one is started. See the paragraph in the documentation on Client. Adding a client.close.await? before you return Ok() should fix the issue :)

For higher-level operation, I recommend you use something like @stevepryde's thirtyfour, which will probably make it easier to do things like keep state over time.

@jonhoo jonhoo closed this as completed Mar 4, 2023
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

2 participants