Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

CORS problem while embeded "gen-search-widget" in Sites.google

while i add the "gen-search-widget" in my sites.google url, as below: https://www.mywawa-iot.com/ai-bots 

while I click the search result,  it happed one problem as below:

Access to XMLHttpRequest at 'https://play.google.com/log?format=json&hasfast=true&authuser=0' from origin 'https://www.mywawa-iot.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Origin' header has a value 'http://play.google.com' that is not equal to the supplied origin.

 

"I would appreciate it if everyone could offer me some advice. Thank you."

 
 
 
 
Solved Solved
2 1 786
1 ACCEPTED SOLUTION

This error occurs because the browser is blocking a web page from making requests to a different domain than the one that served the web page. In your case, your site at `https://www.mywawa-iot.com` is trying to make a request to `https://play.google.com`, and the browser is blocking it due to CORS policy.

Set up a server-side proxy on your own domain that can forward requests to `https://play.google.com`. This way, your site makes requests to your own domain, and the server forwards the request to `https://play.google.com`. This can bypass the CORS issue since requests are made from the same origin.

If you control the server at `https://play.google.com`, you can configure it to include the appropriate CORS headers, allowing requests from your domain. Add the following headers to the server's response:

Show More
Access-Control-Allow-Origin: https://www.mywawa-iot.com
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
Access-Control-Allow-Headers: Content-Type

This will allow requests from `https://www.mywawa-iot.com` to access the resources.

Please note that these options might not be feasible depending on the service you are trying to access, and you should ensure that you comply with the terms of service of the external service. Always prefer using official APIs if available, as they are designed to be used by third-party applications and typically handle these issues more gracefully.

You might also want to include more details regarding your issue if my provided resolution will not fix it.

View solution in original post

1 REPLY 1

This error occurs because the browser is blocking a web page from making requests to a different domain than the one that served the web page. In your case, your site at `https://www.mywawa-iot.com` is trying to make a request to `https://play.google.com`, and the browser is blocking it due to CORS policy.

Set up a server-side proxy on your own domain that can forward requests to `https://play.google.com`. This way, your site makes requests to your own domain, and the server forwards the request to `https://play.google.com`. This can bypass the CORS issue since requests are made from the same origin.

If you control the server at `https://play.google.com`, you can configure it to include the appropriate CORS headers, allowing requests from your domain. Add the following headers to the server's response:

Show More
Access-Control-Allow-Origin: https://www.mywawa-iot.com
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
Access-Control-Allow-Headers: Content-Type

This will allow requests from `https://www.mywawa-iot.com` to access the resources.

Please note that these options might not be feasible depending on the service you are trying to access, and you should ensure that you comply with the terms of service of the external service. Always prefer using official APIs if available, as they are designed to be used by third-party applications and typically handle these issues more gracefully.

You might also want to include more details regarding your issue if my provided resolution will not fix it.