diff --git a/.changeset/hot-ghosts-crash.md b/.changeset/hot-ghosts-crash.md new file mode 100644 index 0000000000000..c5195428ab399 --- /dev/null +++ b/.changeset/hot-ghosts-crash.md @@ -0,0 +1,5 @@ +--- +"gradio": patch +--- + +fix:SSR Safari Fix diff --git a/gradio/routes.py b/gradio/routes.py index f9beda359c9c4..66272e646bc28 100644 --- a/gradio/routes.py +++ b/gradio/routes.py @@ -274,11 +274,31 @@ async def proxy_to_node( request.method, httpx.URL(url), headers=headers ) node_response = await App.client.send(new_request) + content = node_response.content + user_agent = request.headers.get("user-agent", "").lower() + is_safari = ( + "safari" in user_agent + and "chrome" not in user_agent + and "chromium" not in user_agent + ) + response_headers = {} + if is_safari: + response_headers = { + "Access-Control-Allow-Origin": "*", + "Cross-Origin-Opener-Policy": "same-origin", + "Cross-Origin-Embedder-Policy": "require-corp", + } + if request.url.path.endswith(".js"): + response_headers["Content-Type"] = ( + "application/javascript; charset=utf-8" + ) + elif request.url.path.endswith(".css"): + response_headers["Content-Type"] = "text/css; charset=utf-8" return Response( - content=node_response.content, + content=content, status_code=node_response.status_code, - headers=dict(node_response.headers), + headers=response_headers if is_safari else node_response.headers, ) def configure_app(self, blocks: gradio.Blocks) -> None: