Google sign-in popup blocked by Cross-Origin-Opener-Policy
Google sign-in with signInWithPopup cannot complete while the page is served with Cross-Origin-Opener-Policy: same-originShort answer
If your site sends Cross-Origin-Opener-Policy: same-origin, a sign-in popup from another origin lands in a separate browsing context group, so your page cannot reach it. Send same-origin-allow-popups instead, or remove the header, or use signInWithRedirect. Check the header your server actually returns before changing code.
Fix it fast
1Find out which cause you have
See which COOP value your page is served with. The popup problem starts with same-origin.
curl -sI https://your-site.example | grep -i cross-origin-opener-policy2Match what you see, then jump to its fix
- 1
The curl above prints same-origin, and the error appears when the Google popup opens or closesThe site sends Cross-Origin-Opener-Policy: same-originFix - 2
Nothing in the project needs SharedArrayBuffer or other isolated features, yet a COOP header is set by a template or hosting presetYou do not need cross-origin isolation, so the header can goFix - 3
You must keep same-origin, for example for cross-origin isolationPopup sign-in is the wrong flow for this pageFix
- 1
What does the error look like?
Google sign-in with signInWithPopup cannot complete while the page is served with Cross-Origin-Opener-Policy: same-originThe page loses its reference to the sign-in popup window, because the opener policy severs it
Cause 1 of 3
The site sends Cross-Origin-Opener-Policy: same-origin
1Check
Find where the header is set: next.config.js headers(), middleware, or the web server.
grep -rn "Cross-Origin-Opener-Policy" next.config.* middleware.* nginx/ 2>/dev/null2Fix
Change the value to same-origin-allow-popups. MDN describes it as meant for keeping a live reference to a trusted cross-origin window such as an OAuth provider. In Next.js it goes in headers().
// next.config.js
module.exports = {
async headers() {
return [
{
source: '/:path*',
headers: [
{ key: 'Cross-Origin-Opener-Policy', value: 'same-origin-allow-popups' },
],
},
];
},
};3Verify
Restart the server, confirm the new header with curl, then sign in again.
curl -sI http://localhost:3000 | grep -i cross-origin-opener-policyConfirmed by developer.mozilla.org
Cause 2 of 3
You do not need cross-origin isolation, so the header can go
1Check
unsafe-none is the default value. Cross-origin isolation, which needs same-origin, is the only reason MDN gives for the strict value.
grep -rn "Cross-Origin-Embedder-Policy\|SharedArrayBuffer" src/ next.config.*2Fix
Delete the Cross-Origin-Opener-Policy entry from the headers config or hosting settings, redeploy, and keep the default.
// next.config.js: remove the entry
{ key: 'Cross-Origin-Opener-Policy', value: 'same-origin' }3Verify
The curl command from the first step prints nothing, and popup sign-in works.
curl -sI https://your-site.example | grep -ci cross-origin-opener-policyConfirmed by developer.mozilla.org
Cause 3 of 3
Popup sign-in is the wrong flow for this page
1Check
Look for signInWithPopup in your auth code.
grep -rn "signInWithPopup" src/ app/ 2>/dev/null2Fix
Use signInWithRedirect and read the result with getRedirectResult after the page loads. Firebase warns that redirect needs an authDomain that matches where your app is served, so set it as in its redirect best-practices guide.
import { getAuth, signInWithRedirect, getRedirectResult, GoogleAuthProvider } from "firebase/auth";
const auth = getAuth();
await signInWithRedirect(auth, new GoogleAuthProvider());
// on the page that loads after the redirect
const result = await getRedirectResult(auth);3Verify
Sign in; you land back on the app signed in, with result.user set.
console.log((await getRedirectResult(getAuth()))?.user?.uid);Confirmed by firebase.google.com
How do I stop it coming back?
- Set COOP deliberately in one place, and re-check it after changing hosting or adding a security-headers preset.
- Test sign-in in a production build behind the real headers, not only on the dev server.
- If you use redirect sign-in, set authDomain to the domain that serves the app.
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.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- SessionBirdAn omnichannel engagement suite in Flutter: campaigns, chatbot, tickets, analytics and live calling.
- WorkforceA field app, an admin console and a self-hosted Node.js server for push and reconciliation.
Related fixes
Web apps
Firebase Auth says the API key is not valid
Firebase: Error (auth/api-key-not-valid.-please-pass-a-valid-api-key.)
The apiKey your app sends is either empty, wrong, or blocked.
4 causes, each with a fixWeb apps
FirebaseError: Expected first argument to collection() to be a CollectionReference
FirebaseError: Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore
In the modular Firebase SDK, collection() is a function whose first argument must be the Firestore instance from getFirestore(app).
2 causes, each with a fixWeb apps
AuthUserPoolException: Auth UserPool not configured in a Next.js app
Auth UserPool not configured
The error means an Amplify Auth call ran before Amplify.configure did.
3 causes, each with a fixWeb apps
Apollo Server rejects a request as a potential CSRF
HTTP 400 Bad Request from the GraphQL endpoint
Apollo Server's CSRF prevention is on by default.
3 causes, each with a fixWeb apps
Clerk cannot read its publishable key in a Next.js app
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY is undefined
Clerk reads NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY.
3 causes, each with a fixWeb apps
The shell cannot find create-next-app
command not found: create-next-app
create-next-app is not meant to be installed as a shell command.
2 causes, each with a fix