Maaz Zindani

Loading the index…

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

Google sign-in popup blocked by Cross-Origin-Opener-Policy

ErrorGoogle sign-in with signInWithPopup cannot complete while the page is served with Cross-Origin-Opener-Policy: same-origin

Short 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.

  • Applies to Firebase JS SDK (modular), Next.js 15, Chrome
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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-policy
  2. 2Match what you see, then jump to its fix

    1. 1The 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. 2Nothing 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. 3You must keep same-origin, for example for cross-origin isolationPopup sign-in is the wrong flow for this pageFix

What does the error look like?

  • Google sign-in with signInWithPopup cannot complete while the page is served with Cross-Origin-Opener-Policy: same-origin
  • The 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/null

2Fix

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-policy

Confirmed by developer.mozilla.org

Did this fix it?

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-policy

Confirmed by developer.mozilla.org

Did this fix it?

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/null

2Fix

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

Did this fix it?

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:

Related fixes

Next step

Want this handled for good?

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