Skip to content
FunnelGuard

Fix guide by FunnelsGuard

Deprecated API warnings (document.write, sync XHR): fix them

PRF-129Low impactCould addBy FunnelGuardPublished Updated
On this page

What this issue is

document.write() is an old JavaScript method that writes HTML straight into the page while it loads. Synchronous XHR is a network request (XMLHttpRequest with the async flag set to false) that freezes the page until the server answers. Browsers mark both as deprecated or harmful and print warnings in the console.

How these APIs can cost you
  • Sync XHR blocks the page, so buttons and forms feel frozen while the request runs.
  • document.write can inject a script that blocks rendering, so the page appears later, especially on slow mobile connections.
  • Chrome can skip cross-site scripts injected with document.write on slow connections, so a tag or widget may silently not load for some visitors.
  • Calling document.write after the page has loaded can wipe the whole page, which breaks the funnel step.
  • Browsers may remove these APIs in the future, turning a warning into a real failure.
How a document.write script can lose a lead
  1. Page starts loadingVisitor on a slow mobile connection
  2. document.write adds a scriptBrowser decides to skip it
  3. Widget or tag missingChat, form helper or tracking not loaded
  4. Lead or event lostNo conversion recorded

A cross-site script written with document.write may be skipped on a slow connection, so later steps depend on something that never loaded.

Find the warnings in Chrome
  1. Open DevTools

    Open your landing page, form page and checkout in Chrome. Press F12 (or Cmd+Option+I on Mac) and open the Console tab.

  2. Reload with the console open

    Tick 'Preserve log', reload, and make sure the 'Verbose' level is enabled so violations show.

  3. Filter for the warning

    Type document.write or Synchronous XMLHttpRequest in the filter box.

  4. Click the source link

    The right-hand file name shows which script triggered it. Expand the stack trace to see the caller.

  5. Test a slow connection

    In the Network tab, set throttling to Slow 4G and reload. Look for the message that a script was not loaded via document.write.

  6. Try Lighthouse

    Run Lighthouse from DevTools. The best-practices section lists 'Avoids document.write()' when it finds a problem.

Fix by platform
  1. Identify the plugin or theme

    Use the DevTools source link. File paths containing /wp-content/plugins/name/ or /wp-content/themes/name/ tell you the owner.

  2. Update or replace it

    Update the plugin or theme first. If the warning stays, check the vendor changelog or switch to an alternative. Test on a staging copy.

Load a script without document.writejavascript
var s = document.createElement('script');
s.src = 'https://example.com/widget.js';
s.async = true;
document.head.appendChild(s);
Replace synchronous XHR with fetchjavascript
// Before (blocks the page)
// var xhr = new XMLHttpRequest();
// xhr.open('GET', '/api/data', false);
// xhr.send();

// After
fetch('/api/data')
  .then(function (res) { return res.json(); })
  .then(function (data) {
    console.log(data);
  })
  .catch(function (err) {
    console.error('Request failed', err);
  });
Old method vs modern method

Deprecated

  • document.write injects a blocking script
  • Sync XHR freezes the page
  • Console shows violation warnings
  • Script may be skipped on slow connections

Modern

  • Script added with async or defer
  • fetch runs without blocking
  • Console is clean
  • Script loads reliably
Confirmation checks
  • Reload each funnel page with the Console open: no document.write or Synchronous XMLHttpRequest messages remain.
  • Re-run Lighthouse and check that 'Avoids document.write()' passes.
  • Throttle to Slow 4G and confirm the widget or tag still loads.
  • Submit a test lead and check it reaches your inbox or CRM.
  • Check in GA4 DebugView or your ad platform's tag tool that conversion events still fire.
Prevention habits
  • Load third-party scripts with async or defer.
  • Keep themes, plugins and apps updated.
  • Check the console on a staging page before publishing any new tag.
  • Ask vendors for their current snippet rather than copying one from an old guide.
  • Review Custom HTML tags in your tag manager a few times a year.
  • Add a console check to your release checklist.
Where deprecated APIs tend to hurtExample numbers
Where deprecated APIs tend to hurt (example)Warning only, page works: 1 relative risk (1-10); Slow page on weak mobile: 4 relative risk (1-10); Script skipped, tag missing: 7 relative risk (1-10); Page wiped after load: 9 relative risk (1-10)0371479Warning only, page wo…Slow page on weak mob…Script skipped, tag m…Page wiped after loadrelative risk (1-10)

Example: illustrative scores only, not measured data. Risk depends on which script uses the API.

Questions people ask

Why does Chrome say 'Avoid using document.write()'?

Chrome shows this violation when a script calls document.write, which can block page rendering. It usually comes from an old theme, plugin or third-party snippet. Find the file in the console's source link and update or replace it.

Is document.write bad for SEO?

It is not a direct ranking penalty, but it can slow rendering and Lighthouse flags it in best practices. If it makes a script fail to load, content or tags may be missing. Replacing it with async loading is the safer choice.

How do I fix 'Synchronous XMLHttpRequest on the main thread is deprecated'?

Change the request to be asynchronous, ideally with fetch, and handle the response in a callback or with await. If the call comes from a third-party script, update that script or contact the vendor.

Why is my script not loading because of document.write?

On slow connections Chrome can skip cross-site scripts that are injected with document.write. The script never runs, so the widget or tag is missing. Load it with a script element or an async script tag instead.

Can Google Tag Manager cause document.write warnings?

Yes, a Custom HTML tag with an old vendor snippet can use document.write. Replace it with the vendor's current template or load the script by creating a script element. Only enable 'Support document.write' if a tag truly needs it.

Do deprecated API warnings stop my forms or tracking from working?

Usually not, because they are warnings. They become a problem when the browser skips the script or the page freezes. Always test a submission and your conversion events after any change.

Does FunnelGuard detect deprecated API warnings?

No, not yet. It is a possible future check. FunnelGuard does catch real funnel failures such as broken steps, missing tracking hits and test leads that do not arrive.

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.