jonhoo / fantoccini

A high-level API for programmatically interacting with web pages through WebDriver.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add support for setting cookies

LukeMathWalker opened this issue · comments

fantoccini exposes an API to delete/access existing cookies, but there is no way to set one.
I have seen the discussion in #130 - is webdriver still a blocker to implement this functionality? Is there a tracking issue I can follow there?

It's a bit of a mix. w3c/webdriver#1238 definitely poses a challenge to providing a nice API for this. You can always set cookies through JavaScript, but then you can only set cookies for the current domain (and not HttpOnly cookies).

Does Client::add_cookie() solve this one? There's a unit test for it also, which includes this:

    // Add a new cookie.
    use fantoccini::cookies::Cookie;
    let mut cookie = Cookie::new("cookietest", "fantoccini");
    cookie.set_domain(".wikipedia.org");
    cookie.set_path("/");
    cookie.set_same_site(Some(SameSite::Lax));
    c.add_cookie(cookie.clone()).await?;

Ah, so, unfortunately the WebDriver "AddCookie" API says:

If cookie name or cookie value is null, cookie domain is not equal to the current browsing context’s active document’s domain, cookie secure only or cookie HTTP only are not boolean types, or cookie expiry time is not an integer type, or it less than 0 or greater than the maximum safe integer, return error with error code invalid argument.

Which means that API only works for setting cookies for the current domain. I suppose we could close this since there is at least a way to set cookies in general, it just has this very onerous restriction.