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

Constructor param data_directory has no effect but it is present in the launch args #73

Open
hadjiprocopis opened this issue Aug 29, 2023 · 0 comments

Comments

@hadjiprocopis
Copy link

hadjiprocopis commented Aug 29, 2023

I can't spawn the browser with a different user data dir.

Via the CLI I can do:

google-chrome --user-data-dir=xxxxx

(EDIT: dir is created automatically if it does not exist, it contains various browser items and no cookies nor history are remembered from last session)

And the dir is created and the browser does not know history+cookies of the previous session.

But running the browser via [WWW::Mechanize::Chrome] does not run in separate data dir although I can see in the log that the spawning options contain --user-data-dir=xxxxx

use Log::Log4perl qw(:easy);
use WWW::Mechanize::Chrome;
Log::Log4perl->easy_init($DEBUG);

    my %default_mech_params = (
	 'data_directory' => 'xxxxx',
	);
    my $mech_obj = eval {
        WWW::Mechanize::Chrome->new(%default_mech_params)
    };
    die $@ if $@;

sleep(1000);

The result:

2023/08/29 11:52:33 Spawning for websocket $VAR1 = [
          '/usr/bin/google-chrome',
          '--remote-debugging-port=0',
          '--remote-allow-origins=*',
          '--remote-debugging-address=127.0.0.1',

          '--user-data-dir=xxxxx' , # <<<<<<<<< it is here!!!!!!

          '--enable-automation',
          '--no-first-run',
          '--mute-audio',
          '--no-sandbox',
          '--safebrowsing-disable-auto-update',
          '--no-default-browser-check',
          '--disable-background-networking',
          '--disable-breakpad',
          '--disable-client-side-phishing-detection',
          '--disable-component-update',
          '--disable-hang-monitor',
          '--disable-prompt-on-repost',
          '--disable-sync',
          '--disable-web-resources',
          '--disable-default-apps',
          '--disable-popup-blocking',
          '--disable-gpu',
          '--disable-domain-reliability',
          'about:blank'
        ];
2023/08/29 11:52:33 Spawned child as 34709, communicating via websocket
2023/08/29 11:52:34 Connecting to ws://127.0.0.1:35455/devtools/browser/0610305f-a9e1-491c-9d1c-a37afbf4299f
2023/08/29 11:52:34 Connected to ws://127.0.0.1:35455/devtools/browser/0610305f-a9e1-491c-9d1c-a37afbf4299f
2023/08/29 11:52:34 Attached to tab 9084D773A279E05A69A2952880C358D8, session BBC2805B8C0CB0C88487AC9A2937A441
2023/08/29 11:52:34 Ignoring 'Runtime.executionContextCreated'

No dir is created, cookies and history are remembered.

EDIT: I have hacked the code to print the spawned command line which works just fine if I run it from my terminal:

/usr/bin/google-chrome --remote-debugging-port=0 --remote-allow-origins=* --remote-debugging-address=127.0.0.1 --user-data-dir=xxxxx --enable-automation --no-first-run --mute-audio --no-sandbox --safebrowsing-disable-auto-update --no-default-browser-check --disable-background-networking --disable-breakpad --disable-client-side-phishing-detection --disable-component-update --disable-hang-monitor --disable-prompt-on-repost --disable-sync --disable-web-resources --disable-default-apps --disable-popup-blocking --disable-gpu --disable-domain-reliability about:blank

Even by short-circuiting the module's code to simplify the command line args, this still does not create the user data dir:

2023/08/29 11:22:45 Spawning for websocket $VAR1 = [
          '/usr/bin/google-chrome',
          '--user-data-dir=xxxxx',
          '--remote-debugging-port=0',
          '--remote-allow-origins=*'
        ];
2023/08/29 11:22:45 Spawned child as 20605, communicating via websocket
2023/08/29 11:22:46 Connecting to ws://127.0.0.1:41239/devtools/browser/3fdbf9ea-ad73-4bcd-aaa5-7a0400ad4f1d
2023/08/29 11:22:46 Connected to ws://127.0.0.1:41239/devtools/browser/3fdbf9ea-ad73-4bcd-aaa5-7a0400ad4f1d
2023/08/29 11:22:46 Attached to tab F469D08E7340E1B6592302A73797FF94, session DF552A462B7BEC9D7D7196C660E25840
2023/08/29 11:22:46 Ignoring 'Runtime.executionContextCreated'

EDIT: I forgot to mention that I also get these warnings when using the module, I did not think they can affect this problem but maybe they are, they are signature warnings (similar to issue #67):

Use of @_ in numeric eq (==) with signatured subroutine is experimental at /opt/perlbrew/perls/perl-5.36.0-O3/lib/site_perl/5.36.0/WWW/Mechanize/Chrome.pm line 837.
Use of @_ in array element with signatured subroutine is experimental at /opt/perlbrew/perls/perl-5.36.0-O3/lib/site_perl/5.36.0/WWW/Mechanize/Chrome.pm line 837.
Use of @_ in array element with signatured subroutine is experimental at /opt/perlbrew/perls/perl-5.36.0-O3/lib/site_perl/5.36.0/WWW/Mechanize/Chrome.pm line 2007.
Use of @_ in numeric eq (==) with signatured subroutine is experimental at /opt/perlbrew/perls/perl-5.36.0-O3/lib/site_perl/5.36.0/WWW/Mechanize/Chrome.pm line 5704.
Use of @_ in list assignment with signatured subroutine is experimental at /opt/perlbrew/perls/perl-5.36.0-O3/lib/site_perl/5.36.0/WWW/Mechanize/Chrome.pm line 5704.
Use of @_ in list assignment with signatured subroutine is experimental at /opt/perlbrew/perls/perl-5.36.0-O3/lib/site_perl/5.36.0/WWW/Mechanize/Chrome.pm line 5707.
Use of @_ in numeric eq (==) with signatured subroutine is experimental at /opt/perlbrew/perls/perl-5.36.0-O3/lib/site_perl/5.36.0/WWW/Mechanize/Chrome.pm line 5814.
Use of @_ in list assignment with signatured subroutine is experimental at /opt/perlbrew/perls/perl-5.36.0-O3/lib/site_perl/5.36.0/WWW/Mechanize/Chrome.pm line 5814.
Use of @_ in list assignment with signatured subroutine is experimental at /opt/perlbrew/perls/perl-5.36.0-O3/lib/site_perl/5.36.0/WWW/Mechanize/Chrome.pm line 5817.

WWW::Mechanize::Chrome version 0.71
google-chrome version is 116.0.5845.110
perl version 5.36.0
EDIT: linux fedora 36

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

1 participant