Saturday, November 21, 2015

TenFourFoxBox: because it's time to think inside the (fox)box. (a/k/a: we dust off Mozilla Prism for a new generation)

As long as there have been web browsers, there have been people trying to get the web freed up from the browser that confines it, because, you know, the Web wants to be free, or some other similarly aspirational throwaway platitude. These could be robots, or screen scrapers, or aggregating services, or chromeless viewers, but no matter what these browserless browsers are doing, they all tend to specialize in a particular site for any number of reasons usually circulating around business or convenience. This last type, the chromeless viewer, spawned the subcategory of "site specific browsers" that morphed into the "Rich Internet Application" and today infects our phones and tablets in the guise of the "lazy-*ss programmer mobile app."

Power Mac users have only had access to a few tools that could generate site-specific browsers. Until Adobe withdrew support, Adobe AIR could run on PowerPC 10.4+, but it was more for generally Internet-enabled apps and wasn't specifically focused at creating site-specific browsers, though it could, with a little work. Leopard users could use early betas of Fluid before that went Intel-only, and I know a few of you still do. Even Mozilla themselves got into the act with Mark Finkle's WebRunner, which became Mozilla Prism in 2007, languished after a few releases, got moved to Salsita and renamed WebRunner again in 2011, and cancelled there as well around the time of Firefox 5. However, WebRunner née Prism née WebRunner was never available for Power Macs; its required binary components were Intel-only, even though the Mozilla releases could run on 10.4, so that was about it for PowerPC. (Mozilla tried again shortly afterward with Chromeless, but this didn't get off the ground either, and was never intended as a Prism successor in any case. Speaking of, Google Chrome can do something similar, but Chrome was of course never released for Power Macs either because Alphagooglebet are meaniepants.)

There are unique advantages as TenFourFox users to having separate apps that only handle one site at a time. Lots of tabs requires lots of garbage collection, the efficiency of which Mozilla has improved substantially, but is still a big drain on old computers like ours which are always under memory pressure. In addition, currently Firefox and TenFourFox must essentially cooperatively multitask between tabs because JavaScript infamously has run-to-completion semantics, which is why you get the "script too long" dialogue box if the watchdog portion of the browser detects something's pegging it. Since major portions of the browser itself are written in JavaScript, plus all those addons you tart it up with, the browser chrome must also cooperatively multitask with everything else which is why sometimes it temporarily grinds to a halt. I've sunk an incredible amount of time over TenFourFox's existence into our just-in-time JavaScript compiler for PowerPC to reduce this overhead, but that only gets us so far, and the typical scripts on popular websites aren't getting any less complex. Mozilla intends to solve this problem (and others) with multi-process Firefox, also known as Electrolysis, but it won't work without significant effort on 10.4 and I have grave doubts about its ability to perform well on these older computers; for that reason, I've chosen not to support it.

However, generating standalone browser apps for your common sites helps to mitigate both these problems. While each instance of the standalone browser uses more memory than a browser tab, with only one site in it garbage collection is much easier to accomplish (and therefore faster), and the memory is instantly reclaimed when the standalone browser terminates. In fact, on G5 systems with more than 2GB of RAM, it helps you actually use that extra memory more effectively: while TenFourFox is a 32-bit application (being a hybrid of Carbon and Cocoa), you'd be running multiple instances of it, all of which have their own 32-bit address space which can be located in that extra RAM you've got on board. Also, separate browser instances become ... multiple processes. That means they preemptively multitask, like Electrolysis content processes would. They could even be scheduled on a different core on multiprocessor Power Macs. That improves their responsiveness substantially, to say nothing of the fact that the substantially reduced amount of browser chrome has dramatically less overhead. Now, standalone browsers also have disadvantages; they lack a lot of the features of a regular browser, including safety features, and they can be more difficult to navigate in because of the reduced interface. But for many sites those are acceptable tradeoffs.

So, without further ado, let's introduce TenFourFoxBox.

TenFourFoxBox is an application that generates site-specific browsers ("foxboxes") for you, running them in private instances of TenFourFox (a la XULRunner). This has been one of my secret internal projects since I got Amazon Music working properly with TenFourFox, so I wanted to use it as a jukebox without dragging down the rest of the browser, and to help beef up the performance of my online coursework site which has a rather heavy implementation and depends greatly on Google Docs and Box. And now you'll get to play with it as well.

Although TenFourFoxBox borrows some code from Prism/WebRunner, mostly the reduced browser chrome, in actual operation it functions somewhat differently. First, TenFourFoxBox isn't itself written in XUL; it's a "native" OS X application that just happens to generate XUL-based applications. Second, for webapps created with Prism (or its companion tool Refractor), it's Prism itself that actually does the running with its own embedded copy of the XUL framework, not Firefox. With TenFourFoxBox, however, foxboxes you create actually run using the copy of TenFourFox you have installed (and yes, the foxboxes will look for and run the correct version for your architecture), just as separate processes, with their own browser chrome and their own application support and cache directory independent of the main browser. The nice thing about that is when you upgrade TenFourFox, you upgrade the browser core in every foxbox on your system all at once, as well as your main browser, because TenFourFox is your main browser, amirite?

The implementation in TenFourFoxBox is also a little different with respect to how data is stored. Foxboxes are driven essentially as independent XULRunner apps, so they have their own storage separate from the browser. Prism allowed this space to be shared, but I don't think that was a good idea, so not only are all foxboxes independent, but by default they operate effectively in "private browsing" mode and clear out cookies and other site data when they quit. By default they also disable autocomplete, improving both privacy and a little bit of performance; you can, of course, change these settings, and override checks sites might do which could detect you're not actually in a regular browser. I also decided to keep a constant unchanging title (regardless of the website you're viewing) so that you can more easily identify it in Exposé.

So, let's see it in action. Here's Bing Maps, in full 1080p on the quad G5, looking for drone landing sites.

And here's what I originally wrote this for, Amazon Music, playing the more or less official album of International Space Year:

(Stupid Amazon. I already have Flood and Junta!)

So now it's time to get this ready for the masses, and what better way than to have you slavering lot mercilessly bang on it? The following bugs/deficiencies are known:

  • The application menu only has "Quit." This is actually Mozilla bug 1181977, and will be fixed in TenFourFox 38.5, after which all the foxboxes will "fix themselves."
  • Localization isn't supported yet, even if you have a localized TenFourFox; most things will still appear in English. It's certainly possible to do, just non-trivial because of TenFourFoxBox's dual nature (we have to localize both the OS X portion and the XUL code it generates, and then figure out how to juggle multi-lingual resources). I'm not likely to do anything with this until the rest of it is stable enough to freeze strings.
  • Although the browser core they run is shared, individual foxboxes have their own private copies of the foxbox support code and chrome which are independent. Thus, when a new TenFourFoxBox comes out, you will need to manually update each of your foxboxes. You can do this in place and overwrite them; it's just somewhat inconvenient.
  • There are probably browser features missing that you'd like. I'm willing to entertain reasonable requests.

Even the manual is delivered as a foxbox, which makes it easy to test on your system. Download it, try it and post your comments in the comments. TenFourFox 38.4 or higher is required. This is a beta, so treat it accordingly, with the plan to release it for general consumption a week or so after 38.5 comes out.

Let's do a little inside-the-box thinking with an old idea for a new generation, shall we?

34 comments:

  1. I'm puzzled. Why didn't you just use the webapp runtime that comes with Firefox, and more or less just does that?

    ReplyDelete
    Replies
    1. It doesn't work with the 10.4 SDK, and this was easier than trying to patch it to do so.

      Delete
  2. Stainless (10.5 and later only, http://stainlessapp.com/) does something similar (but using WebKit) by launching separate browser processes for each tab or window you open.
    Maybe something similar could be done for TenFourFox as well - on the fly creation of TenFourFoxBoxes.

    ReplyDelete
    Replies
    1. It's definitely an idea worth thinking about. I just have to consider of how it would all integrate, since the GRE expects to have control of the whole XUL widget, so we're talking separate windows and window management between multiple disparate processes would be ... interesting. Something like this would almost certainly have a rather different UI and almost no add-on compatibility.

      The other possibility is some shadow widget or shared memory but that's starting to get very complex.

      Delete
  3. What a great idea. I just tried this on a script-heavy grocery store site, and the site's actually usable now. Now I can click their coupons and feed their narc algorithms without taking all day.

    You do realize with software like this, you're making me de-prioritize purchasing that ARM-based MacBook I had my eye on. I was starting to look forward to it :)

    ReplyDelete
    Replies
    1. I'm ordering pizza in a foxbox right now. Just have to make sure the fox doesn't eat it first.

      Delete
  4. Great stuff that helps us all keep up our PPC spirit!

    ReplyDelete
  5. great idea, could you add option to select icon of new app generated by your TenFourFoxBox app?

    ReplyDelete
  6. I'm continuously impressed with the ideas you come up with. I use Google Earth all the time, and this should come in handy once Google changes the API and the Google Earth 5.1.3 standalone application stops working. For example.

    ReplyDelete
  7. Cool idea! Currently TenFourFoxBox requires that the installed TenFourFox app carry the as shipped name (TenFourFox7450.app, for example). Would it be difficult to make it work if the app name has been trimmed to the more generic TenFourFox.app?

    ReplyDelete
    Replies
    1. I can add this, though it would be a fallback if the expected executable were not present.

      Delete
    2. That would work for me, Cameron. Would it cause issues for other users? I'm not a developer by any stretch, but thought maybe I could make a change to TenFourFoxBox.app/Contents/MacOS/foxbox to accomplish this myself without bothering you, but didn't have any luck.

      Delete
    3. No, it shouldn't be a problem, but keep in mind that if you have a "properly named" TenFourFox on your system, it will always get precedence.

      Delete
    4. Got it. That makes perfect sense. Thanks!

      Delete
    5. I rename my Tenfourfoxes as well because I use at least 17 and the latest one simultaneously (TFF 38 = 'TenFourFox7450-38.app' on my systems). I have set $path in the Perl script accordingly.

      Delete
    6. I mentioned attempting edits of the Perl script previously. I gave it another go yesterday morning and was still unable to get it working if I modified the script in the Desktop directory trees of non-admin and admin accounts, both with home directories located on a non-boot volume. Modifying TenFourFoxBox User Guide.app's script in the Desktop tree of either account, which I hadn't tried before, worked like a charm. I then tried moving a modified copy of TenFourFoxBox.app to /Applications and subsequently another directory tree on the boot volume and it worked in both cases. I'm not sure what to make of that, but thanks for the nudge to beat on the Perl script a little more.

      Delete
  8. As an end user and someone who likes my power pc's, but doesn't know much about what goes on under the hood, I like TenFourFoxBox.
    It knocks my sox off!

    ReplyDelete
  9. OK CamBot, this is Bad-@$$! Easily one of your best ventures yet. Made a Working Twitter Client in about 30-seconds! Is there any plan to add your SafariSandbox functionality into this??

    ReplyDelete
    Replies
    1. I mean so flash-sites can be sandboxed within TenFourFoxBox using your SafariSandbox?

      Delete
    2. No. I'm not sure how that would work, actually. I imagine someone could generate a tool to pop out preconfigured sandboxed Safari browser instances but I don't see there would be much advantage over the current mechanism (which are single window/tab anyway), it would be a mess managing permissions on all of the instances, and it would be totally separate anyway.

      Delete
    3. I was actually able to spoof an 'open location' call to Sandbox Safari through with shell-script access of the app's executable, and it does work - sort of.... Really simple flash sites work fine, but ones that require disc-caching/storage don't work. Not a biggie, as they work fine in TenFourKit, but was just a fun test. TenFourFoxBox is still amazing though and you deserve massive kudos for it. Is there any way to include both a print option, and maybe a way to copy a link (so say if one is on Facebook, and can't view someone's Flash-based video, they might grab the link and paste it into Safari/WebKit??)

      Delete
    4. The print option is there (look under the Box menu, or press Command-P).

      With regard to sending SandboxSafari URLs, you can certainly do so through the command line, and it's supported, though sending a 'GURL' Apple Event is the best/official way to trigger (or using Launch Services to do it, etc.). I don't want to make the chrome too fat, since the idea is to have a very minimal Gecko context, but adding a copy link to the context menu might not be too difficult. I just have to see where I can wedge that in. It might be something we do after 1.0.

      Delete
  10. P.S. As a PPC enthusiast, you simply have to try the new "Rise of the Tomb Raider" on 360. Here is a GLOWING review from EuroGamer:
    http://www.eurogamer.net/articles/digitalfoundry-2015-rise-of-the-tomb-raider-face-off

    ReplyDelete
  11. This has allowed me to get Google Music to load again (Fluid gives me nothing but a white page), but since Google Music is Flash based I still can't play my music.

    I can see it now – I just can't play it!

    ReplyDelete
    Replies
    1. What about using SandboxSafari? You'll need Tobias' tools to relink it against Leopard WebKit (or it'll just use the old system WebKit which won't load Google Music) but it should work.

      Delete
  12. Cool stuff, but Amazon Music won´t play any Song.
    It will not run without Flash.

    Any idea?

    PS: Amazon Music Germany

    ReplyDelete
    Replies
    1. I don't know about Amazon Music Germany, but the US site works just fine. It *says* it needs Flash, but if you go and play anything, it "just works."

      Delete
    2. If you mean https://www.amazon.de/gp/dmusic/cloudplayer/player, this works without a problem in Tenfourfox 38.4.0 as well as a Foxbox (with cloak=1) I made for testing.

      Delete
  13. Amazing hack! Wonderful Christmas gift to PowerPC users! This is just what I needed to keep the inefficient Yahoo web mail scripts from bogging my TenFourFox session. And it's a great way to get threads to run on those extra cores. And speaking of cores, I managed to find a G5 quad with a decent cooling system. I stress-tested it by running four instances of memtest on its 6.5GB. Took an hour to run. I was astonished how much heat it put out. (Reviews indicate the quad goes from 150W no load to 550W all-load.) Must be cozy at Cameron's house during TFF builds!

    ReplyDelete
  14. Is this based on the -app / WebRT support? I ask because that's getting removed; see thread: http://thread.gmane.org/gmane.comp.mozilla.firefox.devel/3634 Hopefully it isn't; the way you describe it, it might be -chrome instead (and still loading the rest of Firefox).

    (I unfortunately cannot check directly as I have no Mac, PPC or not.)

    ReplyDelete
    Replies
    1. No, this is all chrome-based (see my reply to glandium). We don't use the webapprt at all for foxboxing.

      Delete
  15. Smashing! I like my FoxBoxes.

    Is there a way to change the location where downloads get saved? Seems like all downloads are sent to the desktop.

    ReplyDelete

Due to an increased frequency of spam, comments are now subject to moderation.