Chrome drops a cookie from another site because third-party cookies are blocked
Your error
This attempt to set a cookie via a Set-Cookie header was blocked due to user preferences3 more lines it can showFix it fast
Most common cause, 1 of 3The front end and the PHP API are on different sites
Put the API on the same site as the front end: a subdomain of the app's own domain, or a path on the app's host that forwards to the PHP backend.
<?php
// API now served from https://api.example.com for the app on https://app.example.com
setcookie('session', $token, [
'path' => '/',
'secure' => true,
'httponly' => true,
'samesite' => 'Lax',
]);Short answer
DevTools says a Set-Cookie header was blocked due to user preferences when the cookie comes from another site than the page and the browser blocks third-party cookies, as Chrome does in Incognito by default. SameSite=None; Secure cannot help then. Serve the API on the page's own site, or mark embed cookies Partitioned (CHIPS). Current Chrome.
Which cause do you have?
Open the DevTools console in the frame that sends the request and compare its site with the API's. Different registrable domains (or schemes) make the response cookie third-party; true for embedded means the page runs inside someone else's iframe.
({ page: location.origin, api: new URL('https://api.example.net/login').origin, embedded: window.top !== window })Then find the line you see in this list and open its fix:
- 1The front end and the PHP API are on different sites
embedded is false, the page is on one registrable domain (app.example.com) and the API on another (api.example.net), and the cookie is sent from an AJAX or fetch call with credentials - 2A widget embedded on other sites sets its own cookie
embedded is true: your PHP app runs in an iframe on a customer's site, and the cookie only needs to work inside that embed - 3An embedded login must share one session across many sites
embedded is true, and the embed needs the same signed-in session it has on its own site, so a cookie stored per top-level site does not help
What does the error look like?
This attempt to set a cookie via a Set-Cookie header was blocked due to user preferencesThis Set-Cookie was blocked due to user preferences.This cookie was blocked due to user preferences.The login works in a normal window but the session cookie never sticks in Incognito
Cause 1 of 3
The front end and the PHP API are on different sites
You seeembedded is false, the page is on one registrable domain (app.example.com) and the API on another (api.example.net), and the cookie is sent from an AJAX or fetch call with credentials
Check
Blocked due to user preferences means the browser itself refused the cookie because it counts as third-party. Two URLs are same-site when the scheme and the eTLD+1 match, so app.example.com and api.example.com are same-site while example.com and example.net are not. Chrome blocks third-party cookies in Incognito by default, and for everyone who picked Block third-party cookies in settings; Google's guide says that setting blocks them in all contexts, so SameSite=None; Secure cannot bring the cookie back.
curl -s -D - -o /dev/null https://api.example.net/login | grep -i '^set-cookie'Fix
Put the API on the same site as the front end: a subdomain of the app's own domain, or a path on the app's host that forwards to the PHP backend. The cookie is then first-party, and SameSite=Lax is enough.
<?php
// API now served from https://api.example.com for the app on https://app.example.com
setcookie('session', $token, [
'path' => '/',
'secure' => true,
'httponly' => true,
'samesite' => 'Lax',
]);Verify
In an Incognito window, the login response's Cookies tab in DevTools shows the cookie with no warning, and the next request sends it.
curl -s -D - -o /dev/null https://api.example.com/login | grep -i '^set-cookie'Confirmed by web.dev
Cause 2 of 3
A widget embedded on other sites sets its own cookie
You seeembedded is true: your PHP app runs in an iframe on a customer's site, and the cookie only needs to work inside that embed
Check
An iframe from your domain on a customer's page is a third-party context, so its cookies fall under the same block. A Partitioned cookie (CHIPS) is stored per top-level site: the copy set while embedded on site A is sent only while the embed is on site A again. Google's CHIPS guide calls partitioned cookies the way to read and write cookies in cross-site iframes while third-party cookies are blocked. Chrome has supported them by default since version 114, and they must carry Secure.
curl -s -D - -o /dev/null https://widget.example.com/frame | grep -i '^set-cookie'Fix
Mark the embed's cookie Partitioned. PHP 8.5 added a partitioned option to setcookie(), which demands secure; on older PHP send the header yourself.
<?php
// PHP 8.5 and later
setcookie('__Host-widget', $id, [
'path' => '/',
'secure' => true,
'samesite' => 'None',
'partitioned' => true,
]);
// PHP 8.2 to 8.4
header('Set-Cookie: __Host-widget=' . rawurlencode($id) . '; Path=/; Secure; SameSite=None; Partitioned', false);Verify
In DevTools under Application, Storage, Cookies, the cookie appears with the partition key of the site that embeds the widget.
curl -s -D - -o /dev/null https://widget.example.com/frame | grep -i 'partitioned'Confirmed by privacysandbox.google.com
Cause 3 of 3
An embedded login must share one session across many sites
You seeembedded is true, and the embed needs the same signed-in session it has on its own site, so a cookie stored per top-level site does not help
Check
Partitioning gives each embedding site its own copy, so it cannot carry a login made on your own domain into another site's page. Google lists the Storage Access API for this case: an iframe asks the user for access to its unpartitioned cookies. MDN notes the request is refused unless it runs during a user gesture such as a click, or permission was granted before.
navigator.permissions.query({ name: 'storage-access' }).then((s) => console.log(s.state))Fix
Ask for storage access from a button inside the iframe, then reload the embed's state. If the user refuses, fall back to a top-level login page on your own site.
document.querySelector('#sign-in').addEventListener('click', () => {
document.requestStorageAccess().then(
() => location.reload(),
() => window.open('https://login.example.com/', '_blank'),
);
});Verify
After the click and the user's consent, the session cookie is sent with the embed's next request.
navigator.permissions.query({ name: 'storage-access' }).then((s) => console.log(s.state)) // grantedConfirmed by developer.mozilla.org
How do I stop it coming back?
- Test every cookie-based login in an Incognito window, where Chrome blocks third-party cookies by default.
- Plan API and front-end hosts on one registrable domain from the start, so session cookies stay first-party.
- Give each embed cookie a __Host- name with Secure and Partitioned, and keep shared sign-in for a top-level page.
Sources
- Chrome DevTools source: NetworkRequest.ts (current wording)
- Chrome DevTools source, older release (older wording)
- Chrome Help: third-party cookie settings
- Privacy Sandbox: CHIPS (Partitioned cookies)
- Privacy Sandbox: debug third-party cookie blocking
- PHP manual: setcookie()
- Privacy Sandbox: third-party cookies overview
- web.dev: same-site and same-origin
- MDN: Document.requestStorageAccess()
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.
Which stack is behind this page?
Projects of mine on the same stack: Spotless Laundry, EZ Estimater.