Skip to content
FunnelGuard

Fix guide by FunnelsGuard

localStorage unavailable in private mode breaks your site

PRF-131Medium impactCould addBy FunnelGuardPublished Updated
On this page

What this issue is

Many sites save small bits of data in the browser: a cart ID, a consent choice, UTM values, a form draft. They use localStorage, sessionStorage or cookies for this. In some situations the browser refuses access. Then the call either throws an error or silently saves nothing.

Typical cases: the visitor blocks all cookies or site data, uses a hardened privacy browser or extension, or opens the site inside an in-app browser or embedded frame with storage restricted. Older Safari private mode also threw a QuotaExceededError on every write. Behaviour differs by browser and version, so never assume storage works.

Why it costs you leads or sales

Visitors who browse privately or block cookies are often cautious buyers. If the page breaks for them, they leave without telling you. You see no error, only a lower conversion rate for a group you cannot easily see.

How a storage error stops a funnel
  1. Landing page loadsPage renders normally
  2. Script saves to localStorageBrowser throws SecurityError
  3. Form or cart codeNever runs
  4. Lead or orderNot created

A single unguarded storage call can break everything after it.

Conversion by storage settingExample numbers
Conversion by storage setting (example)Storage allowed: 3.2 %; Storage blocked, unguarded code: 0.4 %; Storage blocked, guarded code: 2.9 %0123.20.42.9Storage allowedStorage blocked, ungu…Storage blocked, guar…%

Example: illustrative numbers showing how a storage error can cut conversions for visitors who block storage.

How to check if your site has it

Test with storage blocked
  1. Open a private window

    Use Incognito, InPrivate or Private Browsing. Run your main funnel: submit a lead form, add to cart, start checkout.

  2. Block all cookies and site data

    In Chrome, go to Settings > Privacy and security > Third-party cookies or Cookies and other site data, and choose Block all cookies. In Safari, turn on Block all cookies under Settings > Privacy. Reload and test again.

  3. Watch the console

    Open DevTools (F12) > Console. Look for SecurityError, QuotaExceededError, or 'Access is denied for this document'.

  4. Search your code

    Search your theme and tag code for localStorage, sessionStorage and document.cookie. Any use without try/catch is a risk.

  5. Test an embedded frame

    If your form or booking widget runs inside an iframe, test it on a page where third-party storage is blocked. Frames are often the first thing to lose access.

A storage error halts the page

The script hits a blocked storage call, throws, and the rest of the page logic stops.

How to fix it

The fix is the same everywhere: never call storage directly. Use a small safe wrapper that tests access, catches errors and falls back to a variable in memory. The data then lasts for the page view, which is enough for most flows.

Safe storage wrapper with memory fallbackjavascript
const memoryStore = {};

function storageAvailable() {
  try {
    const k = '__test__';
    window.localStorage.setItem(k, '1');
    window.localStorage.removeItem(k);
    return true;
  } catch (e) {
    return false;
  }
}

const canStore = storageAvailable();

const safeStorage = {
  get(key) {
    try {
      return canStore ? window.localStorage.getItem(key) : (memoryStore[key] ?? null);
    } catch (e) {
      return memoryStore[key] ?? null;
    }
  },
  set(key, value) {
    try {
      if (canStore) { window.localStorage.setItem(key, value); return; }
    } catch (e) {}
    memoryStore[key] = String(value);
  },
  remove(key) {
    try {
      if (canStore) window.localStorage.removeItem(key);
    } catch (e) {}
    delete memoryStore[key];
  }
};
Apply the fix on your platform
  1. Add the wrapper

    Place the safe storage wrapper in a shared script loaded before other code.

  2. Replace direct calls

    Swap every localStorage.getItem/setItem and sessionStorage call for safeStorage. Wrap document.cookie writes in try/catch too.

  3. Handle missing data

    Make sure the flow still works when get returns null, for example by using a default value or asking the server.

How to confirm it's fixed

Confirmation checks
  • Open a private window and block all cookies, then complete your lead form or checkout up to the payment step.
  • The console shows no SecurityError or QuotaExceededError.
  • Consent banner, cart and form still work, even if a saved value is lost on reload.
  • The same flow also works in a normal window with storage allowed.
  • Repeat in Chrome, Safari and Firefox, on desktop and mobile.
Unguarded vs guarded storage

Before

  • Direct localStorage.setItem calls
  • Blocked storage throws an error
  • Form and checkout scripts stop

After

  • Calls wrapped in try/catch
  • Falls back to memory
  • Funnel completes for every visitor

How to prevent it happening again

Prevention habits
  • Make the safe wrapper the only way your code touches storage.
  • Add a lint rule or code review check against direct localStorage use.
  • Include a private-window and blocked-cookies run in your release checklist.
  • Re-test after adding any new app, widget, chat tool or tag.
  • Log JavaScript errors in a monitoring tool so storage errors show up.

How FunnelGuard handles this

FunnelGuard does not check this yet. A check for blocked storage is a possible future addition. Its robot visitor runs in a standard browser session, so it does not simulate private mode or blocked cookies.

What FunnelGuard does cover nearby: it runs your real journeys (lead forms, checkouts, booking and chat buttons) on a schedule, checks each step and the tracking hits, and sends one alert with a screenshot and a likely cause when a step fails. That can reveal a broken funnel from other causes, but it will not tell you that blocked storage is the reason for a failure seen only by some visitors.

To watch for this yourself, run the private-window and blocked-cookies test after each release, and use a browser error-logging tool to collect SecurityError and QuotaExceededError reports from real visitors.

Questions people ask

Why is my website not working in private browsing mode?

Often because your code uses localStorage, sessionStorage or cookies and the browser blocks or limits them in private mode. If the code does not catch the resulting error, the script stops and forms or carts break. Wrap storage calls in try/catch and add a memory fallback.

What does 'SecurityError: The operation is insecure' mean for localStorage?

It means the browser refused your script access to storage, usually because cookies or site data are blocked, or the page runs in a restricted frame. Accessing window.localStorage can itself throw. Guard it with try/catch.

Why do I get QuotaExceededError when setting localStorage in Safari?

Older Safari private browsing set the storage quota to zero, so every write failed with QuotaExceededError. Newer versions behave differently, but the safe fix is the same: catch the error and fall back to memory.

How do I check if localStorage is available in JavaScript?

Try writing and removing a test key inside a try/catch block, and return false if it throws. Do not rely on if (window.localStorage) alone, because the access can throw. Use the result to choose between localStorage and an in-memory object.

Should I use cookies instead of localStorage as a fallback?

Not as the only fallback, because blocked cookies are often blocked together with storage. An in-memory variable works for the current page view, and the server can hold anything that must persist, such as a cart ID tied to a session.

How do I test my site with cookies and localStorage blocked?

Open a private window, and in browser settings block all cookies and site data. Then run your key journeys with DevTools open and watch the console for errors. Repeat in Safari and Firefox.

Does FunnelGuard detect blocked localStorage?

No. FunnelGuard does not check this yet; it is a possible future check. It does run your real funnel journeys on a schedule and alerts you when a step fails, but it does not simulate private mode.

Does FunnelGuard catch this?

Could add

Not checked yet: could be added to FunnelGuard.

Stop finding out from your customers

FunnelGuard runs your real forms and checkouts on a schedule, checks the tracking and the leads behind them, and alerts you once, with a screenshot. Try any paid plan free for 3 days.