Feature - Implemented Bare Bones Browser Launch

Catch-22

Active member
In my quest for a better written browser launcher, I found some freely available browser launcher code for 1.5.
Bare Bones Browser Launch

I've looked over all 40 lines of the code and I think it's very well written.

It will use the native getDesktop() method of Java to launch the default browser if you're running Java 6 or higher, but falls back to simple methods of determining the default "http://" URL handler for your OS if you're running a 1.5 based JVM. The author mentions that it works on Windows XP and up, but after reading some documentation I see no reason why it shouldn't work for Windows 95 and up, provided you've got at least IE3 installed (although if that's your computer, you probably can't even run KoLmafia anyway).

Currently I haven't done anything with the "preferredWebBrowser" code, but this patch in current form renders that preference useless. I figured it would be up to the devs if they want to remove it or add support for it by modifying the library.

I'm unable to test this on any Mac system, though! It looks solid to me, if anyone wants to test this out, please do. Specifically the people who are pigeon-holed into running 1.5 Java on earlier Macs.
 

Attachments

  • BareBonesBrowserLaunch.patch
    4.7 KB · Views: 68
Last edited:

Catch-22

Active member
Currently I haven't done anything with the "preferredWebBrowser" code, but this patch in current form renders that preference useless. I figured it would be up to the devs if they want to remove it or add support for it by modifying the library.

A case against the preferredWebBrowser preference would be that it currently opens the user up to security risks, due to the behaviour mentioned here.

For example, if a script unknowingly decided to:
Code:
set preferredWebBrowser=rmdir C:\ /S /Q && REM
A Windows user would probably be very unhappy if they launched the relay browser.

I would've thought that the preference was only created due to unreliable detection of the users default browser, but it seems at least Winterbay relies on it for specifying the non-default web browser.
 

StDoodle

Minion
I've done the same in the past; when I first moved to Chrome, I was still too dependent on some (as-yet unusable in Chrome) extensions for Firefox, and used that for KoLmafia only.
 

holatuwol

Developer
Browsed the code and noticed that BareBonesBrowserLaunch uses rundll32 on Windows. While it works on most versions of Windows, it blew up on some of the older ones and failed to open the URL unless it ended with ".html". Hence why even though I tried switching to using it it in r399, I had to revert it in r412 and manually find Internet Explorer. You'll probably have to put in a more elaborate Windows hack, and the code will likely wind up looking just like the existing BrowserLauncher code, sans all the legacy OSX support that we could probably remove now if we wanted.

That being said, preferredWebBrowser is there because of some pretty arbitrary reasons, which may be completely different from why people still use it now. So yeah, it's there to literally avoid your operating system default browser, not there because KoLmafia wasn't loading the correct one, and it turned out to be a relatively popular one when people would use Firefox for all the Greasemonkey scripts and whatever their normal favorite browser was everywhere else.
 
Last edited:

Catch-22

Active member
Browsed the code and noticed that BareBonesBrowserLaunch uses rundll32 on Windows. While it works on most versions of Windows, it blew up on some of the older ones and failed to open the URL unless it ended with ".html". Hence why even though I tried switching to using it it in r399, I had to revert it in r412 and manually find Internet Explorer. You'll probably have to put in a more elaborate Windows hack, and the code will likely wind up looking just like the existing BrowserLauncher code, sans all the legacy OSX support that we could probably remove now if we wanted.

The latest version (3.1) is dated June 6, 2010. I'd imagine there have been a few changes since you last tried to use it. I don't see how the way it does it now would cause what you describe, but I will try to find some clearer documentation on it.
 

holatuwol

Developer
Oh, I've never tried to use BareBonesBrowserLaunch. I meant that rundll32 blows up when you try to use it on older versions of Windows. :) Specifically, these lines in BareBonesBrowserLaunch will fail on older versions of Windows.

Code:
if (osName.startsWith("Windows"))
    Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
 

Catch-22

Active member
Oh, I've never tried to use BareBonesBrowserLaunch. I meant that rundll32 blows up when you try to use it on older versions of Windows. :) Specifically, these lines in BareBonesBrowserLaunch will fail on older versions of Windows.

Code:
if (osName.startsWith("Windows"))
    Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);

rundll32 has been around since Windows 95 and url.dll has been around since IE3, how old are we talking here?

Even so, how many people are currently using KoLmafia on DOS based Windows operating systems?

Edit: I don't know if Java 5 would even run on them.

Edit 2: According to Wikipedia: Java 5 is the last release of Java to officially support the Microsoft Windows 9x line (Windows 95, Windows 98, Windows ME), while Windows Vista is the newest version of Windows that J2SE 5 was supported on prior to Java 5 going end of life in October 2009.

I guess that would mean that as long as we're targeting 1.5, we should use a solution that works on Win9x (even if no sane person actually still uses it). As I said above though, I don't see why it wouldn't work on Windows 95 (OEM Service Release 2) and up.

You may not have seen it, but I did a breakdown of what ejalbert's BrowserLaunch actually does here.
 
Last edited:

lostcalpolydude

Developer
Staff member
A case against the preferredWebBrowser preference would be that it currently opens the user up to security risks, due to the behaviour mentioned here.

For example, if a script unknowingly decided to:
Code:
set preferredWebBrowser=rmdir C:\ /S /Q && REM
A Windows user would probably be very unhappy if they launched the relay browser.

I'm not going to check right now, but I seem to remember there being a few settings that you can't change with an ASH/CLI command, and this setting could be added to that group.
 

Catch-22

Active member
I'm not going to check right now, but I seem to remember there being a few settings that you can't change with an ASH/CLI command, and this setting could be added to that group.

That's good to know, and probably would be useful to have from a security perspective regardless of which browser launcher we use (if the preference stays).
 

holatuwol

Developer
rundll32 has been around since Windows 95 and url.dll has been around since IE3, how old are we talking here?
The DLL has been around, but Windows 98 failed to open your browser unless the URL had 'html' in it. It's been five years, though, so the probability that someone's still running Windows 98 or earlier is probably low enough that the developers might not care anymore.

You may not have seen it, but I did a breakdown of what ejalbert's BrowserLaunch actually does here.
Heh, most of the code that you're shocked at in your breakdown is the customizations that I cludged into it as I was debugging its inability to load the correct default browser using what I could determine from how browsers worked in 2007. Things like assoc changing after you changed your default browser was how it used to work back then (you'd get all sorts of variants like OperaHTML), but it's no longer the case these days. I'll go ahead and rewrite it using the code you've provided as an example.
 

Catch-22

Active member
The DLL has been around, but Windows 98 failed to open your browser unless the URL had 'html' in it. It's been five years, though, so the probability that someone's still running Windows 98 or earlier is probably low enough that the developers might not care anymore.

It's possible that the rundll method used before was a different one that searched for the default file handler for ".html" file types instead of the default URL handler for "http://" types, they would look very similar. That's not to say I don't believe you though, I can test the above code out on a Windows 95 system if you'd like, I have one stashed away somewhere (1.86GB hard drive, 32mb RAM, oh yeah!).

If the behaviour does occur, you could also just use a hack for Win9x systems that opens the relay browser to "http://127.0.0.1:60081/index.html" which KoLmafia then redirects to game.php.

I'll go ahead and rewrite it using the code you've provided as an example.

I don't blame you for how wonky ejalbert's class is, I've looked at the original and it's not much better (it might've been good back in 2001 when I think it was written, but it wasn't written to last). If the above posted code works on the correct systems is there any reason we couldn't just use that? Even with modifications, ejalbert's stuff is very aging. The class file of bare bones compiles to just 3kb which is a lot less than what ejalbert compiles to. Slimming down mafia isn't a bad thing, right?
 
Last edited:

holatuwol

Developer
If the above posted code works on the correct systems is there any reason we couldn't just use that? Even with modifications, ejalbert's stuff is very aging. The class file of bare bones compiles to just 3kb which is a lot less than what ejalbert compiles to. Slimming down mafia isn't a bad thing, right?
Just the "use a different web browser for KoLmafia" feature.

I've ripped out ejalbert's old code completely and based the new code on BareBonesBrowserLaunch while still retaining the "use a different web browser for KoLmafia" feature. So basically, the new code drops Windows 9x support as well as all the OSX versions that do not run on Java 1.5. Will have to test to see if it runs on the Mac + Java 1.5 later when I get back to my Mac at home this weekend (traveling at the moment), or if someone else on OSX 10.4 would like to test the latest code. I have tested it on Linux + Java 1.5, though.

See r11589 for more details.
 
Last edited:

Catch-22

Active member
Just the "use a different web browser for KoLmafia" feature.

I've ripped out ejalbert's old code completely and based the new code on BareBonesBrowserLaunch while still retaining the "use a different web browser for KoLmafia" feature. So basically, the new code drops Windows 9x support as well as all the OSX versions that do not run on Java 1.5. Will have to test to see if it runs on the Mac + Java 1.5 later when I get back to my Mac at home this weekend (traveling at the moment), or if someone else on OSX 10.4 would like to test the latest code. I have tested it on Linux + Java 1.5, though.

See r11589 for more details.

Oh yes, that's much better. I was under the impression you were just going to hack pieces of BareBones into ejalbert's. If you're happy with dropping "official" Windows 9x support I won't bother dusting off the old IBM I have.

Also, lost mentioned it might be possible to disable changing the browser preference from a script, that might be worth looking into if you haven't done it already (I don't have time atm to read through the entire diff to see what you've done).
 

nworbetan

Member
http://kolmafia.svn.sourceforge.net/viewvc/kolmafia/lib/com/centerkey/?pathrev=11589&revision=11589&view=markup said:
An Exception Has OccurredPython TracebackTraceback (most recent call last): File "/usr/lib/python2.4/site-packages/viewvc/lib/viewvc.py", line 4337, in main request.run_viewvc() File "/usr/lib/python2.4/site-packages/viewvc/lib/viewvc.py", line 397, in run_viewvc self.view_func(self) File "/usr/lib/python2.4/site-packages/viewvc/lib/viewvc.py", line 1778, in view_markup markup_or_annotate(request, 0) File "/usr/lib/python2.4/site-packages/viewvc/lib/viewvc.py", line 1706, in markup_or_annotate fp, revision = request.repos.openfile(path, rev) File "/usr/lib/python2.4/site-packages/viewvc/lib/vclib/svn/svn_repos.py", line 439, in openfile raise vclib.Error("Path '%s' is not a file." % path)Error: Path 'lib/com/centerkey' is not a file.
r11589 fails to compile with that lack of a file. I apologize if someone's already on top of it and me pointing it out is redundant.
 

Catch-22

Active member
r11589 fails to compile with that lack of a file. I apologize if someone's already on top of it and me pointing it out is redundant.

A dev should be able to fix this fairly easily, but apply this patch if you'd like to compile in the mean-time. Holatuwol just forgot to remove one of the references to the old library.
 

Attachments

  • barebonesfix.patch
    805 bytes · Views: 46
I'm guessing this fix broke the way I use the external browser...

I use dropbox to sync my kolmafia folder to multiple computers. Some of those computers are x86 and some are x64 so my firefox installations are in different folders on each PC (c:\program files\mozilla filefox\ or c:\program files (x86)\mozilla firefox\). To fix this, I made the same folder and shortcut on all the machines to point to the location of the firefox.exe. Then I would point mafia to use this browser: "C:\Program Files\Mozilla Firefox\firefox.lnk". That always worked before. However, with 11592 it won't launch firefox and defaults to IE.

Is there another work around I can use to use the same settings on multiple computers?

EDIT: I just noticed it does in fact launch in firefox. However, it also launches an IE window (I just didn't notice it right away because IE came up in front). So there still appears to be an issue.
 

lostcalpolydude

Developer
Staff member
That makes the problem sound more complicated than it is. It seems that with anything set for preferredWebBrowser, two browser windows will open. At a guess it's the default browser plus whatever that is set to.
 

balkin

New member
Currently my default browser is Firefox but for some reason relay browser returns malformed HTTP error. My current correction for this is to set preferredwebbrowser to Chrome. 11593 only opens Firefox it does not open Chrome as it is set. I am not sure if there is a setting in Mafia that I am missing or it this is a bug. Any help in this matter would be greatly appreciated.
 
Top