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

I want to do a quickie workflow tool to quickly scan web pages. (on both an Ubuntu and a windows machine) I use Open::Browser on the Linux machine, and a system (start, $url) on the Windows machine. Is there an extension that will open a new tab, then has a command to close the tab it just opened? (And just the tab, not any others after keeping it open for a pre-determined number of seconds using the sleep function)

It does not seem that any function or perl module will close a tab after opening it

Replies are listed 'Best First'.
Re: Module to open and close browser tabs
by marto (Cardinal) on Jan 10, 2025 at 21:01 UTC

    You don't say which browser, but there's WWW::Mechanize::Chrome. If you're target content doesn't depend on JavaScript you can look at Mojo::UserAgent or similar to parse what you need.

      Agreed the question's too vague as is to give a good answer but the Selenium project is possibly something to check out.

      The cake is a lie.
      The cake is a lie.
      The cake is a lie.

      Yes, this has it. it has the autoclose function, which wasn't mentioned in the main Mechanize CPAN.

        Again, you're not being specific. Are you saying that WWW::Mechanize does not document closure of an actual browser?

Re: Module to open and close browser tabs
by cavac (Prior) on Jan 16, 2025 at 09:19 UTC

    Unless you need to do something very specific, as mentioned by others there are better ways to automate HTTP requests than opening a browser.

    Either way, you can automate most GUI programs by simulating keyboard presses and mouse clicks and taking screenshots to "look" at the screen. See Autoclicker! Cheating is winning, too! for an example of an autoclicker. X11::GUITest also supports keyboard input.

    I actually use X11::GUITest as part of a commercial product (cash register). After a user logs in, the cash register opens a website with an HTML Canvas that needs to go fullscreen. But browsers don't allow JS to put an element into fullscreen mode without user interaction. So the website informs a locally running (minimal) tool that it wants to go fullscreen, and the local tool simulates a mouse click to circumvent browser "security"...

    PerlMonks XP is useless? Not anymore: XPD - Do more with your PerlMonks XP
    Also check out my sisters artwork and my weekly webcomics
Re: Module to open and close browser tabs
by harangzsolt33 (Deacon) on Jan 10, 2025 at 18:50 UTC