Allow to copy in embed (#4251)

This commit is contained in:
Greg Bergé
2026-05-13 06:49:14 +02:00
committed by GitHub
parent d994875bea
commit 37a9453917
4 changed files with 17 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@gitbook/embed": patch
---
Allow copying in embed
@@ -44,6 +44,16 @@ export function createGitBookFrame(iframe: HTMLIFrameElement): GitBookFrameClien
if (!iframe.contentWindow) { if (!iframe.contentWindow) {
throw new Error('Iframe must have a content window'); throw new Error('Iframe must have a content window');
} }
const allowTokens = iframe.allow
.split(';')
.map((token) => token.trim())
.filter(Boolean);
if (!allowTokens.includes('clipboard-write')) {
iframe.allow = [...allowTokens, 'clipboard-write'].join('; ');
}
const channel = createChannel(iframe.contentWindow); const channel = createChannel(iframe.contentWindow);
channel.receive((message: FrameToParentMessage) => { channel.receive((message: FrameToParentMessage) => {
@@ -76,6 +76,7 @@ export function GitBookFrame(props: GitBookFrameProps) {
src={frameURL} src={frameURL}
width="100%" width="100%"
height="100%" height="100%"
allow="clipboard-write"
className={className} className={className}
style={colorScheme ? { colorScheme } : undefined} style={colorScheme ? { colorScheme } : undefined}
/> />
+1
View File
@@ -101,6 +101,7 @@ function getIframe() {
widgetIframe?.remove(); widgetIframe?.remove();
widgetIframe = document.createElement('iframe'); widgetIframe = document.createElement('iframe');
widgetIframe.id = 'gitbook-widget-iframe'; widgetIframe.id = 'gitbook-widget-iframe';
widgetIframe.allow = 'clipboard-write';
if (frameOptions?.colorScheme) { if (frameOptions?.colorScheme) {
widgetIframe.style.colorScheme = frameOptions.colorScheme; widgetIframe.style.colorScheme = frameOptions.colorScheme;
} }