Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

Chrome blocks a request from a public site to a local address

ErrorLook for and connect to any device on your local network

Short answer

Chrome now treats a request from a public page to localhost or a private IP as a Local Network Access request. The user must grant permission in a prompt, the page must be a secure context, and company policy can pre-allow or block it. Check the permission and the policy first.

  • Applies to Chrome 142 and newer, Chrome Enterprise policies
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Check what the page is and what it calls. Print whether the page is a secure context, and look at the exact target address of the failing request in the Network panel.

    console.log(window.isSecureContext, location.origin)
  2. 2Match what you see, then jump to its fix

    1. 1The request fails at once with no prompt, or the prompt text mentions finding and connecting to devices on the local network.The user denied or never saw the permission promptFix
    2. 2The page URL starts with http:// and is not localhost.The page is not a secure contextFix
    3. 3The console reports a mixed content block instead of a permission error.Mixed content blocks an http target from an https pageFix
    4. 4The request only fails on managed work computers, and the permission cannot be changed.An office policy blocks or does not pre-allow the siteFix

What does the error look like?

  • Look for and connect to any device on your local network
  • fetch from a public https page to http://localhost or 192.168.x.x fails only in recent Chrome

Cause 1 of 4

The user denied or never saw the permission prompt

1Check

Chrome gates local-network and loopback requests behind a permission prompt, replacing the older preflight-based Private Network Access design.

console.log(window.isSecureContext)

2Fix

Choose Allow when the prompt appears, and reset the site permission in Chrome if it was denied earlier. In your code, make the request after a user action so the prompt can appear.

document.querySelector('#connect').addEventListener('click', async () => {
  const res = await fetch('http://localhost:8765/status');
  console.log(await res.json());
});

3Verify

The request now completes, and the status shows in the console.

curl http://localhost:8765/status

Confirmed by developer.chrome.com

Did this fix it?

Cause 2 of 4

The page is not a secure context

1Check

Only secure contexts may make private network requests, and Chrome enforces this since Chrome 94.

console.log(window.isSecureContext)

2Fix

Serve the page over HTTPS.

# serve the site from https://, for example behind a TLS-terminating proxy

3Verify

isSecureContext prints true.

console.log(window.isSecureContext)

Confirmed by developer.chrome.com

Did this fix it?

Cause 3 of 4

Mixed content blocks an http target from an https page

1Check

A request to a local http address from an https page is mixed content unless it is exempt. Private IP literals and .local names are exempt. A public domain name that resolves to a local address is not.

console.log(new URL('http://192.168.0.1/ping').hostname)

2Fix

Tell Chrome the target is local with the targetAddressSpace fetch option.

fetch('http://example.com/ping', { targetAddressSpace: 'local' });

3Verify

The mixed content message disappears and the permission prompt shows.

console.log('retry the fetch and read the console')

Confirmed by developer.chrome.com

Did this fix it?

Cause 4 of 4

An office policy blocks or does not pre-allow the site

1Check

Chrome has enterprise policies for this: LocalNetworkAllowedForUrls for local network targets and LoopbackNetworkAllowedForUrls for the local device, An admin controls them.

# ask your admin which Chrome policies are set for local network access

2Fix

Ask the admin to add the site's origin to the Allowed policy for the target type.

# policy LocalNetworkAllowedForUrls, value: https://example.com

3Verify

Restart Chrome, retry the request and check that no prompt or block appears.

# retry the request from the page

Confirmed by chromeenterprise.google

Did this fix it?

How do I stop it coming back?

  • Make local requests from a button click, not at page load, so users see the prompt in context.
  • Test local-device features in current Chrome as well as the version your users run.
  • Document the allow policy for the admins of customers who use a local agent.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Related fixes

Web apps

tsconfig rejects allowImportingTsExtensions

An error that allowImportingTsExtensions needs noEmit or emitDeclarationOnly

allowImportingTsExtensions lets files import each other with .ts or .tsx extensions, and TypeScript only allows it together with noEmit or emitDeclarationOnly.

2 causes, each with a fix

Web apps

A POST to a Google Apps Script web app returns 405 or a CORS error

Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Apps Script web apps run doPost for POST and doGet for GET, and the Apps Script guides describe no other entry points.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.