Skip to content

Commit

Permalink
feat: Add iframeSandbox config (#157)
Browse files Browse the repository at this point in the history
Co-authored-by: mhensley-nw <mhensley@nerdwallet.com>
Co-authored-by: mattcompiles <mattjones701@gmail.com>
  • Loading branch information
3 people committed May 31, 2020
1 parent 4ee913b commit 482bafc
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -68,6 +68,7 @@ module.exports = {
webpackConfig: () => ({
// Custom webpack config goes here...
}),
iframeSandbox: 'allow-scripts',
};
```

Expand All @@ -81,6 +82,8 @@ export { Button } from '../Button'; // Re-exporting a named export
// etc...
```

The `iframeSandbox` option can be used to set the [`sandbox` attribute](https://www.html5rocks.com/en/tutorials/security/sandboxed-iframes/) on Playroom's iframe. A minimum of `allow-scripts` is required for Playroom to work.

Now that your project is configured, you can start a local development server:

```bash
Expand Down
1 change: 1 addition & 0 deletions examples/seek-style-guide/playroom.config.js
Expand Up @@ -47,4 +47,5 @@ module.exports = {
],
},
}),
iframeSandbox: 'allow-scripts',
};
3 changes: 3 additions & 0 deletions lib/start.js
Expand Up @@ -17,6 +17,9 @@ module.exports = async (config, callback) => {
compress: true,
inline: true,
watchOptions: { ignored: /node_modules/ },
// Added to prevent Webpack HMR from breaking when iframeSandbox option is used
// See: https://github.com/webpack/webpack-dev-server/issues/1604
disableHostCheck: true,
};

const compiler = webpack(webpackConfig);
Expand Down
3 changes: 3 additions & 0 deletions src/Playroom/Frames/Iframe.tsx
Expand Up @@ -12,6 +12,8 @@ interface IframeProps extends AllHTMLAttributes<HTMLIFrameElement> {
intersectionRootRef: MutableRefObject<Element | null>;
}

const playroomConfig = (window.__playroomConfig__ = __PLAYROOM_GLOBAL__CONFIG__);

export default function Iframe({
intersectionRootRef,
style,
Expand Down Expand Up @@ -52,6 +54,7 @@ export default function Iframe({
return (
<iframe
ref={iframeRef}
sandbox={playroomConfig.iframeSandbox}
onLoad={() => setLoaded(true)}
onMouseEnter={() => {
if (src !== renderedSrc) {
Expand Down
1 change: 1 addition & 0 deletions src/index.d.ts
Expand Up @@ -11,6 +11,7 @@ interface PlayroomConfig {
storageKey?: string;
webpackConfig?: () => void;
baseUrl?: string;
iframeSandbox?: string;
}

interface InternalPlayroomConfig extends PlayroomConfig {
Expand Down

0 comments on commit 482bafc

Please sign in to comment.