Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage in Chrome Extension #362

Open
ChenCodes opened this issue Jul 23, 2024 · 2 comments
Open

Usage in Chrome Extension #362

ChenCodes opened this issue Jul 23, 2024 · 2 comments

Comments

@ChenCodes
Copy link

Hi there!

Thank you for creating this repo. I have a question around usage of this library in a Chrome Extension.

I am using a React/Typescript setup for my extension.

Here is what my manifest.json file looks like.

{
    "version": "1.0.0",
    "manifest_version": 3,
    "name": "React Chrome Extension",
    "description": "This is a Chrome extension built with React and TypeScript",
    "action": {
        "default_popup": "dist/js/index.html",
        "default_title": "React Chrome Extension"
    },
    "background": {
        "service_worker": "background.js"
    },
    "permissions": [
        "identity",
        "identity.email"
    ],
    "host_permissions": [
        "https://www.googleapis.com/"
    ],
    "key": "HIDDEN",
    "content_security_policy": {
        "extension_pages": "script-src 'self'; object-src 'self'; script-src-elem 'self' 'unsafe-inline' https://accounts.google.com/gsi/client;"
    }
}

Here is my App.tsx file:

import { GoogleOAuthProvider, GoogleLogin } from '@react-oauth/google';
import { useEffect } from 'react';

function App() {
  useEffect(() => {
    const loadGoogleScript = () => {
      const script = document.createElement('script');
      script.src = '../public/google_client.js'; // due to the CSP issue, i have downloaded the contents of https://accounts.google.com/gsi/client into a local file called google_client.js and am referencing that in <script> in my index.html file
      script.async = true;
      script.defer = true;
      document.body.appendChild(script);
    };

    loadGoogleScript();
  }, []);

  return (
    <GoogleOAuthProvider clientId={CLIENT_ID}>
      <div className="App" style={{
        height: '100vh',
        width: '300px',
      }}>
      <GoogleLogin onSuccess={(res) => console.log(res)} />
      </div>
    </GoogleOAuthProvider>
  );
}

export default App;

When the extension loads, it looks like the component doesn't get rendered properly, when I go to inspect the element, it seems to only show an empty div with a height of 40px.

I'd appreciate any thoughts / suggestions on what the issue may be! Thank you.

@flazouh
Copy link

flazouh commented Oct 31, 2024

I have the same problem @ChenCodes @MomenSherif Any idea what to do here for the component to render, or when using the

const login = useGoogleLogin({
		onSuccess: (tokenResponse) => {
			return console.log(tokenResponse);
		},
		flow: "auth-code",
	});

there is nothing happening when clicking a button that calls this

@Ahmed-Ibrahim-Anter
Copy link

the same @flazouh there is nothing happening when clicking a button that calls this
Non-OAuth Error: _.rj {message: 'Popup window closed', stack: 'Error: Popup window closed\n at new _.rj (https:… (https://accounts.google.com/gsi/client:223:551)', type: 'popup_closed'}
i tried every thing that i found
last one
server: { headers: { "Cross-Origin-Opener-Policy": "same-origin-allow-popups", "Cross-Origin-Embedder-Policy": "require-corp", }, },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants