Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

fix(eajs): allow copying to clipboard in chrome (#80072)

Nicolò Pretto1da1d694ffcd
diff --git a/frontend/src/metabase/embedding/embedding-iframe-sdk/embed.ts b/frontend/src/metabase/embedding/embedding-iframe-sdk/embed.ts
index 2f42186433f..95aff8a8fd7 100644
--- a/frontend/src/metabase/embedding/embedding-iframe-sdk/embed.ts
+++ b/frontend/src/metabase/embedding/embedding-iframe-sdk/embed.ts
@@ -372,6 +372,10 @@ export abstract class MetabaseEmbedElement<T extends string[] = string[]>
this._iframe.setAttribute("data-metabase-embed", "true");
+ // Chrome blocks the Clipboard API in cross-origin iframes unless the host
+ // explicitly delegates the permission (e.g. copying a Metabot answer).
+ this._iframe.setAttribute("allow", "clipboard-write");
+
this._removeMessageListener = listenForEajsMessages({
messageSource: "iframe-content",
iframe: this._iframe,
diff --git a/frontend/src/metabase/embedding/embedding-iframe-sdk/embed.unit.spec.ts b/frontend/src/metabase/embedding/embedding-iframe-sdk/embed.unit.spec.ts
index a9c2beb0cea..82f0ebf2e9a 100644
--- a/frontend/src/metabase/embedding/embedding-iframe-sdk/embed.unit.spec.ts
+++ b/frontend/src/metabase/embedding/embedding-iframe-sdk/embed.unit.spec.ts
@@ -225,6 +225,19 @@ describe("embed.js script tag for sdk iframe embedding", () => {
);
});
+ it('should have `allow="clipboard-write"` in the iframe to allow copying to clipboard in chrome', () => {
+ defineMetabaseConfig({
+ instanceUrl: "https://example.com",
+ });
+
+ const embed = document.createElement("metabase-dashboard");
+ embed.setAttribute("dashboard-id", "1");
+ document.body.appendChild(embed);
+
+ const iframe = embed.querySelector("iframe");
+ expect(iframe?.getAttribute("allow")).toBe("clipboard-write");
+ });
+
describe("guest embed token provider", () => {
function setupGuestEmbed({
dashboardId,