This article was originally published here in July 2016 and is republished here with the author's permission.

So you write some code, validate the feature, send it off to QA, and move on to something else. The last thing you expect is to have a QA engineer come back and say that your code doesn't work.

When that happens, you begin the process of identifying the differences (or the singular difference) between the tester's system and yours.

I opened the site on my phone, it works. I open the site on his phone, it doesn't work.

We both have iPhones. Both have the same iOS version. Both have the same browser. My links work, his don't. Go figure. Wait, why is his border black and mine is white? Ahh, he's in private browsing mode. Well that shouldn't make any difference, should it? Links are links, right?

So I open an incognito tab, go to the site, and sure enough my links don't work either. Who would've guessed?

incognito_tab.jpg

So, I hook up my phone to my computer to open my dev tools and start scouring the console log for errors. This one looks unusual:

QuotaExceededError: DOM Exception 22: An attempt was made to add something to storage that exceeded the quota.

Turns out I had added a script to save the open navigation tabs to sessionStorage, so subsequent page views would display the open tabs when the user opened the hamburger menu. Safari's mobile browser not only disables localStorage and sessionStorage in private mode, but also throws a fatal error! The script stops running. Degredation is hardly graceful. In this case, the links did not respond to tap events.

The problem here was pretty easy to fix. Test for sessionStorage and use a try/catch to silently ignore the error:

if (typeof sessionStorage === 'object') {
   try {
       sessionStorage.setItem( 'openMobileMenuTabs' , JSON.stringify(openMobileTabs));
   } catch (e) {
       // silently ignore when sessionStorage is unavailable. The most likely case is private browsing mode.
   }
}

Lesson learned. Always test your code in private mode on a mobile device when using localStorage or sessionStorage


Author

Mark Carlson

Mark Carlson is a Senior UI Developer at Avenue Code. Once a radio station personality and programmer, Mark built an online music research system to help determine song rotations. That project turned into a business of its own, taking Mark out of the on-air studio. Now, Mark is sharing his web development experience with Avenue Code clients in the SF Bay Area.


What are CSS Custom Properties

READ MORE

How to Build Your Own Facial Recognition Web App

READ MORE

4 Ways to Make Your Angular App Sustainable and Scalable

READ MORE

How to Build a Custom Component in VueJS

READ MORE