Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

renodino (6856)

  (email not shown publicly)

Perl Contrarian & SQL fanboy.

Here's my CPAN goods. []

Journal of renodino (6856)

Wednesday November 07, 2007
01:22 PM


[ #34852 ]
After re-implementing this by hand about a dozen times now, I've created a package to deal with it in a single method call. Win32::WebBrowser exports a single method, open_browser(), that pops open the default browser in a detached process and points it at a URL.

Who knows, maybe it'll make the Strawberry Perl dist...

Update: New 1.02 release: Prior version did some URL munging it shouldn't have.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • Any chance that you can add more tests? One that tries to call open_browser with 'about:blank' (which works in IE, Firefox and presumably any modern browser. Perhaps ship an HTML file in t/ that could be loaded with open_browser in yet another test.

    # 02about_blank.t
    use Test::More tests => 1;
    use Win32::WebBrowser;

    BEGIN {
        unless ($^O eq 'MSWin32') {
            skip('This package is for Microsoft Windows platforms only.');


    • I considered it, but it has side-effects, namely, its going to pop open a browser that can't be closed except by hand. My general impression has been that those sorts of test side effects are frowned upon.

      So I just did a load test, and made sure it worked on IE, Firefox, and Opera before shipping.

      There is an examples/ that can be exersized by the more QA conscientious.

      • Yes, leaving garbage windows around is indeed frowned upon.
      • Sounds like you need to add close_browser() then. :)

        If you chose to do so, it shouldn't be too difficult since you are already using Win32::Process. For the automated tests, you'd want to have the ability to know if open_browser reused a browser window (FF for example will just add a tab if it's already running when you call open_browser) so that you'd know whether or not to close it.

        Just a thought...

        • Sounds like you need to add close_browser() then. :)

          Slippery slope, that (including your note wrt Firefox). My intent was more in the spirit of my favorite Perlism: "Simple things should be easy". Opening a browser using Perl on Windows seems simple, and should be easy, but wasn't.

          Now it is.

          • My comment was mostly in jest. ("Mostly" because if you're going to go to the trouble of making it easy to open a browser in Perl then why not go the extra step and make it just as easy to close it when you are done?)

            To be honest, there has only been one or two times that I've wanted to open a browser with Perl. I think I used a system call to 'start URL' and found the window with Win32::GUITest so that I could close it when I was finished.

  • []

    Why stop at Win32?

    HTML::Display display HTML locally in a browser

    HTML::Display::Common routines common to all HTML::Display subclasses

    HTML::Display::Debian display HTML using the Debian default

    HTML::Display::Dump dump raw HTML to the console

    HTML::Display::Galeon display HTML through Galeon

    HTML::Display::Mozilla display HTML through Mozilla

    HTML::Display::OSX display HTML on OSX


      1. I had no idea it existed, and yes I have searched CPAN numerous times. It might have been helpful if the name included "Browser" or "WebBrowser" or somesuch.
      2. The following from HTML::Display::Win32 [] is a bit problematic:

        Currently does not work.

      That said, I will keep it in my toolbox for future *nix platform efforts (tho I wonder how effective it is there, given the lack of a formal standard for locating the default browser on such platforms. If you're lucky, $ENV{BROWSER} exists, but beyond that, it

      • Finding modules >IS hard. It would be nice to upgrade HTML::Display so it comes up as a hit to your searches- though I do not know what is the right way.

        You are right, they say Win32 does not work, I forgot that.

        Maybe you two authors should get together. Max is cool. Maybe you can cross reference each others documentation to each others modules, or combine in one namespace.
        • Max is cool.
          Since you're talking about Corion [], let me tell you this: he's a very experienced user of Windows. So if he can't get HTML::Display to work on Windows, you may be pretty sure there must be a very good reason for it.