Skip to content

Commit 497906d

Browse files
author
Darcy Ye
authored
fix: enable docs website to be embedded in iframe (#1217)
* fix: add logto domains to frame ancestors * chore: do not pop GOT when embedded in iframe
1 parent ab21a74 commit 497906d

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

src/theme/Layout/index.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import BrowserOnly from '@docusaurus/BrowserOnly';
22
import type { WrapperProps } from '@docusaurus/types';
33
import type LayoutType from '@theme/Layout';
44
import Layout from '@theme-original/Layout';
5-
import { type ReactNode } from 'react';
5+
import { type ReactNode, useState, useEffect } from 'react';
66

77
import GoogleOneTapInitializer from './GoogleOneTapInitializer';
88
import { useGoogleOneTapConfig } from './hooks';
@@ -11,11 +11,24 @@ type Props = WrapperProps<typeof LayoutType>;
1111

1212
export default function LayoutWrapper(props: Props): ReactNode {
1313
const { config } = useGoogleOneTapConfig();
14+
const [isInIframe, setIsInIframe] = useState(false);
15+
16+
useEffect(() => {
17+
// Check if the page is embedded in an iframe
18+
try {
19+
setIsInIframe(window.self !== window.top);
20+
} catch {
21+
// If accessing window.top throws an error, we're in a cross-origin iframe
22+
setIsInIframe(true);
23+
}
24+
}, []);
1425

1526
return (
1627
<>
1728
<Layout {...props} />
18-
{config?.oneTap?.isEnabled && <BrowserOnly>{() => <GoogleOneTapInitializer />}</BrowserOnly>}
29+
{config?.oneTap?.isEnabled && !isInIframe && (
30+
<BrowserOnly>{() => <GoogleOneTapInitializer />}</BrowserOnly>
31+
)}
1932
</>
2033
);
2134
}

static/_headers

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
/*
2-
Content-Security-Policy: default-src 'self'; script-src 'self' 'unsafe-inline' https://akasha.logto.io https://accounts.google.com; connect-src 'self' https://akasha.logto.io https://accounts.google.com https://auth.logto.dev https://*.logto.dev https://auth.logto.io https://*.logto.io https://api.inkeep.com; style-src 'self' 'unsafe-inline' https://cdn.jsdelivr.net https://accounts.google.com https://fonts.googleapis.com; font-src 'self' https://cdn.jsdelivr.net https://fonts.gstatic.com; frame-src https://accounts.google.com; img-src 'self' data: https:; object-src 'none'; base-uri 'self'; form-action 'self' https://*.logto.dev https://*.logto.io https://cloud.logto.dev https://cloud.logto.io; frame-ancestors 'none'
2+
Content-Security-Policy: default-src 'self'; script-src 'self' 'unsafe-inline' https://akasha.logto.io https://accounts.google.com; connect-src 'self' https://akasha.logto.io https://accounts.google.com https://auth.logto.dev https://*.logto.dev https://auth.logto.io https://*.logto.io https://api.inkeep.com; style-src 'self' 'unsafe-inline' https://cdn.jsdelivr.net https://accounts.google.com https://fonts.googleapis.com; font-src 'self' https://cdn.jsdelivr.net https://fonts.gstatic.com; frame-src https://accounts.google.com; img-src 'self' data: https:; object-src 'none'; base-uri 'self'; form-action 'self' https://*.logto.dev https://*.logto.io https://cloud.logto.dev https://cloud.logto.io

0 commit comments

Comments
 (0)