LFT notifications in your browser

23 January 2022

PROJECT

On the 9th of January 2022, The Sunday Times published a story that asserted that the UK Government were in the process of phasing out a policy that had arguably kept normal life running during many months of the Covid-19 pandemic.

Where other countries had made Covid testing something citizens had to seek out privately, the 'Test and trace' programme in the UK — aside from doing very little tracing — had made free lateral flow tests available, delivered to your door, in packs of 7.1

Given this policy was supposedly coming to an end whilst the Omicron wave was still out in force, and public life was still heavily disrupted for those looking to avoid catching the virus, there was a rush on Covid tests. The website crashed repeatedly, and frequently was returning a page stating that home delivery tests were out of stock.

Enter the Twitter bot, @LFT_Alert, the inspiration for this tool, which alerted people in their Twitter feed whenever tests became available. A fantastic service, and anonymously set up on New Years Eve 2021, this bot tweeted to its 9000 followers whenever tests went in and out of stock.

But there were two things I could see about this approach that could be improved.

Firstly, whoever was running LFT_Alert needed to keep a computer running themselves in order to repeatedly verify if tests were available. This effectively became a single point of failure to the system (and a point of maintenace and annoyance for the owner) as disruption to the machine would end the service.

And secondly, Twitter is a mess. For me, following over 3000 people, my Twitter feed is awash with hundreds of different faces. To pick LFT Alert's valuable messages amongst the noise of retweets and chatter would be difficult. Twitter offers notifications for any one account, but this had the secondary effect of notifying me whenever tests went in or out of stock. It only matters to get tests when you are running out. To be alerted every time would be a hassle.

So, far too late to the party, as I would soon find out, I picked up my keyboard and spent a few hours on the night of the 9th of January building an alternative to solve this.

lft.tk.gg was born.

The app

Built on two principles: keep the work to the person searching for the test, and don't abuse the LFT portal.

When a user loads the page, they immediately start a timer that executes every minute2 which triggers a check to a shared serverless API endpoint, that is cached for 30 seconds. This endpoint goes to the NHS service and uses a private API to check if LFT orders are open or closed. The API returns the state of the ordering, and the last time the check ran.


{
"status": "OPEN",
"timeChecked": 1642919745205
}

The page then responds, updating the last time the check ran. If the ordering is open, it then uses the web notifications API to send a push notification to the user, triggering a link through to the order page.

I thought this was the simplest solution to the problem. A user needing tests could simply open the page in the morning, work through the day, and get the notification as soon as tests were available.

It's a little frustrating that the government service didn't offer something similar to this. The only major downside I had was learning that the Notification API was (of course) not available for mobile browsers (and full on crashes Safari when used natively). I thought about working out how to send notifications to a mobile browser. This would have required some extra work to set up a service worker, and then using the Push API instead. I planned to do this if the service got a lot of traffic (and may still), but the short term supply issue appears to have been resolved, and the status is now very rarely CLOSED.

Still, I enjoyed building the app and learning a few new things about notifications, and keeping browser tabs awake (it turns out you can play audio to keep something permanently awake, but Chrome checks to see if the audio is audible!).

I hope it really won't be useful in the future! Stay safe.

Footnotes

  1. Just a aside on how infuriating it is that then they also enforced mandatory private lateral flow testing, at a cost of around £20 per flight, for international travellers, despite everyone keeping a half dozen identical tests at home, provisioned free at a massive discount by a public provider...

  2. Chrome throttles background functions running more frequently than this)