Skip to content

Commit dc4149d

Browse files
authored
Merge pull request #45 from tryretool/exposeIframeProperties
[feat] Add iframe permissions
2 parents 48dcb1b + 3885857 commit dc4149d

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import Retool from 'react-retool';
2020
function App() {
2121
const sample = { name: 'Sample data' }
2222
return (
23-
<Retool
23+
<Retool
2424
url="https://retoolin.tryretool.com/embedded/public/f7607e1f-670a-4ebf-9a09-be54cf17181e"
2525
data={sample}
2626
/>
@@ -40,6 +40,8 @@ export default App;
4040

4141
`<Retool>` will accept an optional `onData` callback that will be called with the data of an event that is sent from the embedded Retool app. These events can be sent from a JavaScript query inside of Retool by using the `parent.postMessage()` syntax.
4242

43+
`<Retool>` also accepts optional `allow` and `sandbox` parameters to configure permissions of the iframe used to embed the Retool app. `allow-scripts` and `allow-same-origin` are required in order to run Retool, so if `sandbox` is specified, `allow-scripts` and `allow-same-origin` will always be appended to ensure the Retool app works.
44+
4345
### Example
4446

4547
Running `yarn start` will start an application with a basic Retool app embeded.

src/components/Retool.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { useEffect, useRef, useState } from "react";
22

3-
const Retool = ({ data, url, height, width, onData }) => {
3+
const MINIMUM_SANDBOX_PERMISSIONS = 'allow-scripts allow-same-origin'
4+
5+
const Retool = ({ data, url, height, width, onData, sandbox, allow }) => {
46
const embeddedIframe = useRef(null);
57
const [elementWatchers, setElementWatchers] = useState({});
68

@@ -90,15 +92,19 @@ const Retool = ({ data, url, height, width, onData }) => {
9092
}
9193
};
9294

95+
const sandboxAttrib = typeof sandbox === 'string' ? `${MINIMUM_SANDBOX_PERMISSIONS} ${sandbox}` : sandbox === true ? MINIMUM_SANDBOX_PERMISSIONS : sandbox
96+
9397
return (
9498
<iframe
99+
allow={allow}
100+
sandbox={sandboxAttrib}
95101
height={height ?? "100%"}
96102
width={width ?? "100%"}
97103
frameBorder="none"
98104
src={url}
99105
ref={embeddedIframe}
100106
title="retool"
101-
></iframe>
107+
/>
102108
);
103109
};
104110

0 commit comments

Comments
 (0)