Handoff in Safari: How To Transfer Browsing State in Spree Commerce

David Jones · Jun 10, 2014 · 2 min read · Share:

Last week at Apple’s Worldwide Developer Conference several continuity features were announced for iOS 8 and OS X Yosemite. One of them is called “Handoff.” This feature lets you hand-off an activity from one device to another. For example, if you’re looking at Safari on your iPhone but want to move over to your iPad or Mac you can resume browsing on the other device right where you left off.

I was excited by the possibilities but when I got into the details I found it is mostly targeted at Handoffs between:

  • a native app to a website
  • a website to a native app

A website to website Handoff is possible but limited.

State Transfer and eCommerce

The problem is during a Handoff, Safari just passes the URL over to the receiving device. "State" such as cookies, is not transferred. If you’re shopping at your favourite online store, add a few items to your cart and switch to another device, it’s going to load the online store, but not the contents of your cart.

Transferring Cart Contents in Spree

In order to transfer state we need to take advantage of the URL. I’ve been working on a proof of concept that does this in Spree Commerce. Once you’ve added something to your cart, we’ll append a parameter to all URLs which contains the order number for your current order.

The receiving device knows this order number does not belong to this new cart, which triggers the contents of that order to be transferred to the receiving cart.

Proof of Concept

Source code is available here https://gist.github.com/djones/80394768b4e2cd0505ab

Further Considerations

The receiving device may already have some items in its cart, so how do you handle conflicts? Perhaps prompting the user if they want to use the new cart instead is a solution.

Another issue is the need for an extra parameter on all URLs. This is not desirable so perhaps this would only happen if a supported browser and operating system was detected.

The Future

I hope Apple will add more advanced support for Handoff in Safari in the future. One might first think bringing cookies over would be a sound thing to do, but it creates complexities when the receiving device already has those cookies. Either way iOS 8 and OS X Yosemite greatly improve the user experience between multiple devices and I look forward to seeing where it goes next.


"Handoff in Safari: How To Transfer Browsing State in Spree Commerce" was written by David Jones.


Join The Conversation

Share and start a conversation about this post: