Gmail, the web, and yak shaving

A couple of days ago, someone asked me whether the Gmail website was any good on mobile. I said: it seems so, the couple of times I’ve used it, but I’m not really sure. I’ll find out, I said.

You’d think I’d know better by now.

once more into the breach, dear enemies

The way to actually find out whether it’s any good, with the gmail web app as with all things, is to use it for real for a bit. So I decided that what I’d do is exclusively use the web app to read my mail on my phone for a week.

There are two base criteria here which must be met. First: I have to be able to get at gmail from an icon on my iPhone’s home screen, and second I have to get notifications when I get a new mail. Those two things are axioms, here: if they’re not possible, then my answer is “the gmail web app is crap” because I can’t use it. The easy bit first.

the easy bit

Go to gmail.com in the browser: press the share button, press “add to home screen”. Done.

notifications for a new email

Web apps have a notification API, but it’s not useful on mobiles, because the whole point of a new mail notification is that you get it even if you’re not looking at your mail app. You wouldn’t want to keep the gmail web page open all the time, even if you were allowed to do so on a phone, which you are not. (The Nokia N9 allowed this. No-one else does; mobile platforms routinely decide to quietly kill your app and then raise it from the dead again when you want it back, and while it’s dead it’s not notifying anybody of anything, because it’s dead). So, we need a way for me to get a notification that I have a new email. This requires some sort of native app on the phone, fine, OK, but I didn’t want to have to write a native app to do it; someone must have written an app which can handle notifications and then open up gmail in the web browser. And indeed it is so: on the iPhone there’s Boxcar and Prowl. (I assume there are similar for Android.) Prowl costs money, so I looked at Boxcar first. Boxcar does, indeed, allow you to have it get notifications when you get a new email and then do some sort of user-specified activity when a notification comes in, hooray! (It does this by giving you a magic email address: you tell gmail to forward all your mail to that email address, and when it gets an email, it sends your phone a notification and then deletes the email. This requires trusting the Boxcar people, I agree, but the purpose of this exercise was to see if this could be done at all. If you want security, run your own webmail server, or your own server which monitors gmail and then send the notifications yourself, that’s fine; Boxcar can help with that too via their API.)

the easy bit… is never that easy

So, at this point, when I get an email, Boxcar shows a notification: I press the notification, and it opens my configured URL, which is gmail.com. This is great and I should be done by now, except…Boxcar opens my chosen address in a little in-built web view rather than my browser. Lots of iPhone apps do this — build in a webview rather than using the browser — and it really, really irritates me. There is no option to say “open this in the browser, damn you!” Grr.

But, after some poking around, I notice that the Boxcar changelog says “NEW: Add ability to open custom safari:// URLs in MobileSafari.” Aha! That sounds like what I want. So… I configure my custom URL to be safari://mail.google.com, right?

That doesn’t work. Nor does safari://http://mail.google.com, or any other combination I could think of. There is no documentation other than the above changelog line. Frustrated.

Then I thought: well, it doesn’t have to be Safari, per se. I have Google Chrome on the phone too. Maybe I can use that. The iPhone is set up so that apps routinely register custom URL schemes: it’s how they communicate. Is there, wondered I, some sort of custom URL scheme that I can use to force an https link to open in Chrome rather than Safari?

Indeed there is. Well done Chrome people. If I open googlechromes://mail.google.com it opens https://mail.google.com in Chrome. Yay! So I configure that as my link in Boxcar. Now when I get an email, I touch the notification, and gmail opens in Chrome! Hooray! We’re done!

We’re not done. Now, you see, my home screen link opens in Safari, and my Boxcar link opens in Chrome. That’s annoying and wrong. So, how do I edit the home screen link to be to googlechromes://mail.google.com?

You can’t. You can’t edit a home screen bookmark once it’s created. Bah. So, how do I make Chrome bookmark something to the home screen?

You can’t. Only Safari can do that, because it’s allowed the magic secret APIs and no-one else is.

So how do I put a Chrome bookmark on my home screen? Well, one way would be to have an HTML file which meta refreshes to the googlechromes: URL, and bookmark the HTML file in Safari. That way, I’ll press the home screen icon, that’ll start Safari, Safari will instantly start Chrome, and I’ll have a bookmark. Slightly inelegant, but not too bad.

I stuck the HTML page on my site, and tried it. Minor problem: the page refreshes before I can bookmark it! So, remove the meta refresh, open the page in Safari, bookmark it, put the meta refresh back in again. Ha! That works. (And add a nice home screen icon with <link rel="apple-touch-icon">.

New problem. Every time I hit the home screen bookmark, or the link from Boxcar, we open a new tab in Chrome with gmail in it. After ten minutes of testing this, I’ve got fifteen gmail tabs in Chrome. That’s no good. The Chrome links doc dictates how to explicitly say “I want a new tab”, but not how to say “I don’t want a new tab: reuse the previous one”. After a bit more poking around, though, you can use an [x-callback-url][]-style URL with Chrome, and that lets you specify a source. So, instead of making my bookmark and my Boxcar URL be googlechromes://mail.google.com, I’ll make it be googlechrome-x-callback://x-callback-url/open/?x-source=boxcar&&url=https%3A%2F%2Fmail.google.com. That way, when you open that link a second time, it stays in the same tab as the first time! Hooray!

It’s not perfect. I can’t get Boxcar links and the home screen link to share a tab between them, so I end up with two Gmail tabs in Chrome. That’s annoying but not a total crisis. And this is now clean enough that I can stand to use it for a week. Now I get to actually try using the Gmail web app for a week and see what it’s like!

how annoying is the iPhone?

This all seems like a great big faff to me. Is that all the iPhone’s fault? Well… certainly some of it is. All that crap with Safari being the only thing that can bookmark to the home screen? You can’t add home screen bookmarks that aren’t to real URLs? Sure, these things are fairly technical, but they don’t seem like they’d get in anyone’s way if they did exist. Apparently in older versions of iOS you could bookmark (via a roundabout data URL procedure) weird URLs such as pref:something to open a Settings page directly, and Apple took that away. So that’s annoying.

But in general, I think that the approach of having a server monitor my email and then use the platform’s push notification service to tell me about it and open the webmail client…seems like a good approach. Android does seem to have a couple of IMAP notify apps in the Play Store, but they aren’t reviewed very well, and I don’t really want my phone to hang on an IMAP IDLE socket 24 hours a day. Avoiding that is precisely what push notifications (Google’s “Cloud to Device Messaging”) were invented for. (Note: there are lots of mail notification apps, but they poll. I don’t want polling. When I get an email, I want a notification. Not five minutes later.)

So, then… is this doable on Android? Is there an app like Boxcar where there’s a server component which can (somehow) monitor my gmail account and notify my Android phone, and then pressing the notification on my Android phone will open up https://mail.google.com in the phone’s browser? I’d be interested in hearing the answer to this, Android-using readers.

What about other platforms? How will Firefox OS handle this? (Maybe because they’re all web, they’ll just keep the web page open without ever suspending it, and let it use the web notification API?) I’d like to hear about other approaches. (I don’t want to hear “just use the native app”. Of course that’s the logical thing to do. The point here is to see whether I can set up my life so using a web app for email on my phone is a doable thing. If your answer is “you need to use the native app”, then I’ll take that as you saying “you can’t use web apps for this; you have to go native”. That’s a perfectly reasonable argument, but this post is not directed at you if that’s how you feel.)

Fun little project of gluing together technical bits, I must say. Constraints are the mother of inventiveness!