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

CORS policy #11

Closed
lucaspessivaldo opened this issue Jul 17, 2022 · 3 comments
Closed

CORS policy #11

lucaspessivaldo opened this issue Jul 17, 2022 · 3 comments
Labels
wontfix This will not be worked on

Comments

@lucaspessivaldo
Copy link

lucaspessivaldo commented Jul 17, 2022

I'm using ReactJs.
When I use the request example. I'm getting CORS error.

import translate from 'google-translate-api-x';

const res = await translate('Ik spreek Engels', { to: 'en' });

console.log(res.text); //=> I speak English
console.log(res.from.language.iso);  //=> nl

That code return

Access to fetch at 'https://translate.google.com/' from origin 'http://localhost:5173' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Is that an API error or I need to use some param on the request translate()?

  • with node that error doesn't occur.
@AidanWelch AidanWelch added the wontfix This will not be worked on label Jul 17, 2022
@AidanWelch
Copy link
Owner

No, this is not an error with this package, this is an intended feature of browsers called the Same-Origin Policy. It is critical for protecting sensitive user information. From a normal webpage context it is not possible to use this package, it can be used from a a browser extension background script or an Electron project though.

@AidanWelch
Copy link
Owner

AidanWelch commented Jul 17, 2022

For an example of usage in a browser extension see here

@lucaspessivaldo
Copy link
Author

Thankst to answer, I'll check it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants