Skip to content
FunnelGuard

Fix guide by FunnelsGuard

JS error only on old browsers: optional chaining fix

PRF-128Medium impactCould addBy FunnelGuardPublished Updated
On this page

What this issue is

JavaScript keeps gaining new syntax. Optional chaining (user?.address), nullish coalescing (a ?? b), logical assignment (a ||= b) and class fields are examples. Browsers released before a feature shipped do not understand it.

This is different from a missing API, where the code parses but a function is absent. With new syntax, the browser fails at parse time. It shows a SyntaxError such as Unexpected token '.' or Unexpected token '?', and none of the code in that file runs. Your site looks fine on your own up-to-date laptop, so the problem stays hidden.

Syntax that breaks older browsersjavascript
const city = lead?.address?.city ?? 'unknown';
settings.retries ||= 3;

Why it costs you leads or sales

When the main bundle fails to parse, everything it controls goes with it: form validation and submission, add-to-cart buttons, chat widgets, consent banners and tracking tags. The page still renders, so visitors do not see an error. They just find a form or button that does nothing.

The damage is partial, which makes it easy to miss. Only visitors on older phones, old tablets, corporate machines or unupdated devices are affected. Your overall conversion rate dips a little and no alert fires. Impact is medium because the share of affected visitors depends on your audience.

What an old browser does with modern syntax
  1. Visitor opens pageOld browser loads HTML and CSS fine
  2. Script downloadsFile contains ?. or ??
  3. Parse failsSyntaxError: Unexpected token
  4. Form and buttonsHandlers never attached
  5. Tracking and leadNo conversion hit sent

One unparseable line stops the whole script, so everything after it is lost.

Conversion rate by browser groupExample numbers
Conversion rate by browser group (example)Current browsers: 3.2 %; Older browsers: 0.4 %; Blended average: 3 %0123.20.43Current browsersOlder browsersBlended average%

Example: illustrative numbers showing how one group of older browsers can convert far worse while the overall average hides it.

How to check if your site has it

Find out whether old browsers choke on your scripts
  1. Check your analytics by browser version

    In GA4, open Reports > Tech > Tech details and choose Browser (or Operating system with version). Look for versions whose conversion rate is far below the rest.

  2. Test in a real older browser

    Use an older iPhone or Android device, or a browser-testing service that offers older versions. Open your key page, open the form and try to submit.

  3. Read the console

    Look for SyntaxError: Unexpected token. The error names the script file and line, which tells you which bundle or third-party script contains the modern syntax.

  4. Scan your built files

    Search your production JavaScript for ?. and ??. If they appear in the output, nothing converted them.

  5. Check error monitoring

    If you use a browser error tracker, filter for SyntaxError grouped by browser version.

Quick scan of built files for modern syntaxbash
grep -rnE "\?\.[a-zA-Z_\[(]| \?\? " dist/ --include=*.js | head

How to fix it

There are two routes: convert the syntax at build time (transpiling), or serve a script that already avoids it. Which one applies depends on how your site is built.

Fix by platform
  1. Set a browserslist target

    Add a browserslist entry in package.json (or a .browserslistrc file) that includes the browsers your visitors use, for example defaults plus iOS >= 12. Pick the range from your own analytics.

  2. Transpile with Babel, SWC or esbuild

    With Babel use @babel/preset-env so it reads the browserslist and rewrites ?. and ??. With esbuild set the target option, for example --target=es2017.

  3. Transpile your dependencies too

    Many bundlers skip node_modules. If a library ships modern syntax, include it in your transpile rules. Check the console error's file name to find it.

  4. Rebuild and redeploy

    Purge your CDN cache so visitors do not receive the old bundle.

The same logic in older-safe syntaxjavascript
var city = (lead && lead.address && lead.address.city != null)
  ? lead.address.city
  : 'unknown';
if (!settings.retries) { settings.retries = 3; }
package.json: example browserslistjson
{
  "browserslist": [">0.5%", "last 2 versions", "not dead", "iOS >= 12"]
}
Bundle output

Before

  • Built file still contains ?. and ??
  • Old browsers throw SyntaxError
  • Forms and tags silently dead for those visitors

After

  • Build targets your real browser range
  • Syntax converted to older equivalents
  • Forms and tags run on old and new browsers

How to confirm it's fixed

Confirmation checklist
  • Open the page in an older browser or device: no SyntaxError in the console
  • Submit the form and confirm the lead arrives
  • Check the conversion tag fires in the network tab
  • Search the built files again: no untranspiled ?. or ?? in your own code
  • Confirm the CDN serves the new file, not a cached one
  • Watch GA4 conversion rate for older browser versions over the next days

How to prevent it happening again

Keep a single browserslist target and have the build read it. Add a build step that fails if the output contains syntax beyond your target, such as ESLint with the eslint-plugin-compat or es-check tool. Re-check older browsers after adding any new plugin, app or vendor script, because those can bring new syntax with them.

Fail the build if output is newer than ES2017bash
npx es-check es2017 'dist/**/*.js'
How it usually unfolds
  1. Day 0

    A developer or plugin update introduces `?.` in a bundle.

  2. Day 0

    Tests on current browsers pass. Release goes live.

  3. Day 1

    Visitors on older browsers hit a SyntaxError. Forms do nothing.

  4. Week 2

    Someone notices a small dip in conversions for certain browsers.

  5. Week 2

    Transpile target is set and the site is redeployed.

How FunnelGuard handles this

FunnelGuard does not check for this yet. A check for syntax errors on older browsers is a possible future addition, not a current feature.

What FunnelGuard does do is run your real customer journeys on a schedule with a robot visitor, from the EU or the US. It checks that each step works, that tracking hits reach platforms like GA4, Google Ads and Meta, and that test leads arrive in your inbox and CRM. If a script error breaks a form or a tag for the robot's browser, the failed step is re-checked from a second region and you get one alert with a screenshot and a likely cause. That covers errors that hit modern browsers, but not ones that appear only in old browsers.

To watch for the old-browser case today, combine these: segment GA4 conversions by browser version, use a browser error tracker that reports SyntaxError by browser, run es-check in your build, and test key forms on an older device after each release.

Questions people ask

Why does my website work in Chrome but not on an older browser?

Your code probably uses modern syntax, such as optional chaining (?.) or nullish coalescing (??), that older browsers cannot parse. The browser throws a SyntaxError and refuses to run the entire script file. Transpile your code to a target that matches your visitors' browsers.

What does 'SyntaxError: Unexpected token' mean on an old browser?

It means the browser met syntax it does not understand, such as ?.. Unlike a missing function, this stops the whole file from running. The error message names the file and line, so you can find the source.

How do I fix optional chaining not working in older browsers?

Transpile your JavaScript with Babel, SWC or esbuild using a browserslist or target that includes the older browsers. Also transpile any dependencies that ship modern syntax. Alternatively, rewrite the line using plain checks like a && a.b.

Do I need to support old browsers at all?

It depends on your audience. Check your analytics for browser and OS versions, then support the range that carries real traffic. If older versions bring leads or sales, a broken form there has a direct cost.

How can I test my site in an older browser?

Use a real older phone or tablet, or a cross-browser testing service that offers older browser versions. Open the console, load your funnel pages, submit the form and check for SyntaxError. Also compare conversion rates by browser version in GA4.

Can Google Tag Manager cause JavaScript errors on old browsers?

Yes. Custom HTML tags and Custom JavaScript variables run in the visitor's browser, so modern syntax in them can fail. Write GTM custom JavaScript in plain ES5 and test in Preview mode.

Does FunnelGuard detect JavaScript errors on old browsers?

No, not yet. It is a possible future check. FunnelGuard does run your real journeys and check forms, tracking hits and lead delivery, so it catches breaks that affect its own test browser, but not errors that appear only in older browsers.

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.