david-dick / firefox-marionette

This is a client module to automate the Mozilla Firefox browser via the Marionette protocol
https://metacpan.org/dist/Firefox-Marionette
Other
12 stars 3 forks source link

invalid cookie domain: Document is cookie-averse #4

Closed eserte closed 3 years ago

eserte commented 3 years ago

If using add_cookie before loading a page, then an exception happens. A sample script:

#!/usr/bin/env perl

use strict;
use warnings;
use v5.10.0;
use Firefox::Marionette;

my $fm = Firefox::Marionette->new;
#$fm->go("http://www.example.org"); # uncomment to make problem go away
say $fm->uri;
my $cookie = Firefox::Marionette::Cookie->new(name=>'testcookie', value=> 'testvalue', domain=>'www.example.org', path=>"/", secure=>0);
$fm->add_cookie($cookie);
$fm->go("http://www.example.org");

__END__

Output:

about:blank
invalid cookie domain: Document is cookie-averse in /tmp/firefox-marionette-script-3.pl at line 12

The first output line probably gives the answer: cookies can probably be only set for "real" pages. A workaround could be: preload the URL. (Using another domain wouldn't work, this would lead to the error invalid cookie domain: Cookies may only be set for the current domain (...))

Is there a possibility to set the cookie before loading the (possibly heavy) page? If not, then maybe this restriction should be documented?

david-dick commented 3 years ago

This is pretty awful, but it looks like it's a webdriver thing. Reference is at https://developer.mozilla.org/en-US/docs/Web/WebDriver/Errors/InvalidCookieDomain

I've added a comment to this effect in the documentation for add_cookie and pushed the commit. Does that seem acceptable?

eserte commented 3 years ago

Documentation-only is fine, but the current wording seems strange. Maybe "This method cannot thrown an exception ..." -> "This method throws an exception ..."?

david-dick commented 3 years ago

zonk fixed and pushed.