fowibotak has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I can't seem to figure out how to close a tab when using WWW::Mechanize::Chrome.
my $mech = WWW::Mechanize::Chrome->new(); $mech->get('https://www.google.com/');
There is no $mech->close_tab() function. So the question is, how do you close the tab you're currently working with? Thanks

Replies are listed 'Best First'.
Re: WWW::Mechanize::Chrome How to close a tab
by Corion (Patriarch) on Sep 21, 2018 at 06:24 UTC

    The tab should automatically close once your $mech object goes out of scope.

    If you want to force the closing of the tab, you can undef your $mech object:

    undef $mech;

    What is your use case for closing the tab? I think the Chrome API allows for closing a tab, but I didn't implement it, as I didn't see a use case.

    Update: The driver object already has a way to close the tab and you can use it as:

    $mech->driver->close_tab( $mech->tab )->get

    ... but that will leave your $mech object without a tab. This is not always what you might want.