Win32::WebBrowser

renodino on 2007-11-07T18:22:20

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.


More Tests?

Mr. Muskrat on 2007-11-07T20:51:53

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.');
        exit;
    }
}

ok( open_browser('about:blank'), 'About: Blank' );

Re:More Tests?

renodino on 2007-11-07T23:32:59

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/google.pl that can be exersized by the more QA conscientious.

Re:More Tests?

Alias on 2007-11-07T23:56:45

Yes, leaving garbage windows around is indeed frowned upon.

Re:More Tests?

Mr. Muskrat on 2007-11-08T00:40:40

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...

Re:More Tests?

renodino on 2007-11-08T15:20:01

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.

Re:More Tests?

Mr. Muskrat on 2007-11-08T15:37:04

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.

HTML::Display

mw487 on 2007-11-08T13:32:06

http://search.cpan.org/user/corion/HTML-Display-0.39/lib/HTML/Display.pm

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

HTML::Display::Opera

HTML::Display::Phoenix display HTML through Phoenix

HTML::Display::TempFile base class to display HTML via a temporary file

HTML::Display::Win32 display an URL through the default application for HTML

HTML::Display::Win32::IE use IE to display HTML pages

HTML::Display::Win32::OLE use an OLE object to display HTML

Re:HTML::Display

renodino on 2007-11-08T15:14:47

  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 seems kinda hit and miss)

Re:HTML::Display

mw487 on 2007-11-08T15:54:18

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.

Re:HTML::Display

bart on 2007-11-09T01:07:41

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.