24 янв. 2018 г.

Don't forget to test your web site/application in private browsing (incognito) mode

From time to time one or another web site or web application (SPA, PWA whatever word is now trendy) faces that problem: it throws errors and does not work when private browsing mode is turned on. Real-world examples: Google+ signinAmazon Cognito Identity SDK.

Here is more-or-less correct and complete list of things that don't work when private browsing (incognito mode) is turned on:
  • Safari 10 and below: localStorage and sessionStorage API is present, but throws a DOMException.QUOTA_EXCEEDED_ERR when the code is trying to write something. Fixed in Safari 11
  • IE10+/Edge: indexedDB is undefined
  • Firefox: indexedDB is undefined
A similar situation may happen when the user has disabled cookies/data, e.g. in Chrome/Chromium: Settings -> "Show advanced settings..." -> "Content settings..." -> "Block sites from setting any data".
  • Chrome/Chromium: cookies, localStorage, sessionStorage and indexedDB are disabled. Will throw "Uncaught SecurityError: Access to 'localStorage' is denied for this document".
  • Firefox: cookies, localStorage, sessionStorage
  • IE: cookies
And one more restriction exists in Safari when JavaScript is in strict mode: modification of error object may be forbidden (both overwriting existing property and adding a new one) and may throw

10 янв. 2018 г.

How to write to NTFS USB drives on Mac OS X

Mac OS X by default can only read from attached USB drives with the NTFS file system. Here are the steps to enable read/write access:


Initial setup (only first time on a new Mac)

  1. Install Homebrew (and probably additional XCode tools)
  2. In Terminal: brew install caskroom/cask/osxfuse
  3. In Terminal: brew install ntfs-3g
  4. In Terminal: sudo mkdir -p /Volumes/NTFS

Each time when an NTFS USB drive is connected to the computer

  1. List disk partitions: diskutil list
  2. Find identifier of the partition with Windows_NTFS type (typically disk2s1 or disk3s1)
  3. Unmount found drive: sudo umount /dev/disk2s1
  4. Mount the drive with read/write access: sudo ntfs-3g /dev/disk2s1 /Volumes/NTFS -olocal -oallow_other
  5. The mounted drive should appear on the desktop, the file system should be mounted at /Volumes/NTFS.

The same steps in a shell script


sudo mkdir -p /Volumes/NTFS
DISK=`diskutil list | grep Windows_NTFS | sed -E "s/.+Windows_NTFS .+ GB +//"`
echo Mounting NTFS disk $DISK
sudo umount /dev/$DISK
sudo ntfs-3g /dev/$DISK /Volumes/NTFS -olocal -oallow_other

8 янв. 2018 г.

Proper transition: transform CSS for Android 4.4 browser, Chrome and Safari

Suppose you want CSS transitions for CSS "transform" property on mobile devices (Android 4.4 and above, iOS Safari 7 and above). You'd write

.example {
    transition: transform 1s ease;
}

But what about browser support for CSS 2D transforms and 3D transforms? They require "-webkit-" vendor prefix. No problem, you just add another line

.example {
    transition: -webkit-transform 1s ease;
    transition: transform 1s ease;
}

Stop. That won't work: the former rule is overridden by latter. OK, then combine them into one rule. Browsers should either ignore unknown transition property or use transition for both:

.example {
    transition: transform 1s ease, -webkit-transform 1s ease;
}

Surprise! Safari 7.X (and probably 8.X) doesn't comply to the specification and ignores the whole rule, not only the unknown "transform" property. The only way to write transition cross-browser is

.example {
    transition: -webkit-transform 1s ease;                    /* 1 */
    transition: transform 1s ease;                            /* 2 */
    transition: transform 1s ease, -webkit-transform 1s ease; /* 3 */
}

Let's analyze it with regard to intended browser support:

  • Safari 7.X and 8.X will accept rule 1 and ignore the rest because of unknown "transform" property. That's fine - they will use transition for the "-webkit-transform".
  • The same applies to WebKit-based browsers in Android 4.4
  • Chrome and Safari 9+ will accept rule 1, then override it with rule 2, then override it with rule 3. That's fine too - they will use transition for both prefixed and unprefixed transforms.
The easiest way to avoid such traps is to use Autoprefixer to automatically add vendor prefixes to CSS rules.