All Projects → godaddy → react-safe-src-doc-iframe

godaddy / react-safe-src-doc-iframe

Licence: MIT License
A component which applies guards to srcdoc iframes in order to provide a predictable and safe experience to the user. Complements the sandbox native iframe attribute.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to react-safe-src-doc-iframe

typesafe-templates
Template engine that leverages JSX to generate JavaScript code from TypeScript code files rather than text templates.
Stars: ✭ 27 (+22.73%)
Mutual labels:  jsx
candycrushreact
Candy crush app with React Js
Stars: ✭ 12 (-45.45%)
Mutual labels:  jsx
react-tabllist
React-based customizable style table or list components that support event and callback functions.
Stars: ✭ 20 (-9.09%)
Mutual labels:  jsx
Prakma
Prakma is a framework to make applications using JSX, focusing on writing functional components.
Stars: ✭ 16 (-27.27%)
Mutual labels:  jsx
njsx
A customizable and declarative interface for creating React and React Native components without JSX syntax.
Stars: ✭ 29 (+31.82%)
Mutual labels:  jsx
zaftig
~2kB css in js: z`display flex` // .zjsdkk43-1
Stars: ✭ 15 (-31.82%)
Mutual labels:  jsx
cargo-safety
cargo-safety provides safety checks for Rust projects by finding all uses of unsafe code in dependencies.
Stars: ✭ 61 (+177.27%)
Mutual labels:  safety
mastofeed
ActivityPub feed => iframe embed. https://www.mastofeed.com
Stars: ✭ 55 (+150%)
Mutual labels:  iframe
DLV
Safety Verification of Deep Neural Networks
Stars: ✭ 45 (+104.55%)
Mutual labels:  safety
remote-frames
Render a subset of the React tree to a different location, from many locations, without having to coordinate them
Stars: ✭ 27 (+22.73%)
Mutual labels:  iframe
indent.js
Pure code indentation for jsx, tsx, ts, js, html, css, less, scss.
Stars: ✭ 55 (+150%)
Mutual labels:  jsx
jsxmock
使用 JSX 来定义 Mock Server
Stars: ✭ 31 (+40.91%)
Mutual labels:  jsx
focus-outside
📦 一个很棒的 clickOutside 库,它解决了 iframe 无法触发 clickOutside 的问题,并且它支持分组绑定处理。A good clickOutside library, which solves the problem that iframe cannot trigger clickOutside, and it supports grouping binding processing.
Stars: ✭ 74 (+236.36%)
Mutual labels:  iframe
qadmin
基于layui框架与Vue.js构建的QAdmin轻量级后台模板
Stars: ✭ 34 (+54.55%)
Mutual labels:  iframe
string-replace-to-array
Like Javascript's string.replace, but accepts and returns an array
Stars: ✭ 19 (-13.64%)
Mutual labels:  jsx
omi-docs
📃omil文档
Stars: ✭ 64 (+190.91%)
Mutual labels:  jsx
NonEmptyCollections
A type-safe implementation for collections that cannot be empty. Life is too short for emptiness-checks!
Stars: ✭ 45 (+104.55%)
Mutual labels:  safety
zaku
[WIP] A JSX-based UI builder for auto generate code.
Stars: ✭ 68 (+209.09%)
Mutual labels:  jsx
snabbdom-pragma
'NotReact.createElement' jsx pragma although for snabbdom
Stars: ✭ 47 (+113.64%)
Mutual labels:  jsx
After-Effects-Fun
Expressions, scripts and projects for Adobe After Effects
Stars: ✭ 20 (-9.09%)
Mutual labels:  jsx

React Safe Srcdoc Iframe

A component which applies guards to srcdoc iframes in order to provide a predictable and safe experience to the user. Complements the sandbox native iframe attribute.

Table of Contents

The Problem 🔴

You need to render an html document, for which you have the source locally, into an iframe on your React application. However, you would like some guards applied to the document in order to provide a safe and consistent experience to the user. For example, preventing clicks on elements which could lead to page navigation.

This Solution 🔵

This component compliments the sandbox iframe attribute. It will take the html document source code which you provide through the srcDoc component prop and inject safeguards on document load.

Guards 👮

The following guards are applied to the document:

  • disable pointer events on any element with an href attribute, buttons, and images.
  • only whitelist the "allow-same-origin" sandbox attribute flag for guard injection into the document.
  • referrerPolicy set to "no-referrer".

Install

npm install --save react-safe-src-doc-iframe

Or

yarn add react-safe-src-doc-iframe

Note this package also depends on react and prop-types. Ensure they are installed or available beforehand.

Import Examples

// 1) es6 module
import SafeSrcDocIframe from 'react-safe-src-doc-iframe';

// 2) commonjs
const SafeSrcDocIframe = require('react-safe-src-doc-iframe').default;

// 3) window
const SafeSrcDocIframe  = window.SafeSrcDocIframe;

Usage Example 📝

▶️ Try it out on CodeSandbox!

import React from 'react';
import SafeSrcDocIframe from 'react-safe-src-doc-iframe';

const html = `
  <!DOCTYPE html>
  <html>
    <head>
      <title>My Cats Page</title>
    </head>
    <body>
      <a href="https://link-to-about-page.com">About</a><br />
      <a href="https://link-to-awesome-cats.com"><img src="http://placekitten.com/200/300" /></a><br />
      <button onclick="navigate();">Click me to see more cats!</button>
    </body>
  </html>
`;

const App = () => {
  return <SafeSrcDocIframe srcdoc={html} width="500" height="500" />;
};

Component Props

Note: any prop not specified here will be forwarded to the native iframe element. However, if src is passed, it will always be filtered out.

referrerPolicy

string | optional. Default value: no-referrer.

sandbox

string | optional. Default value: allow-same-origin (for safeguard injection).

The value for the sandbox iframe attribute.

srcDoc

string | required.

Source of the html document to render.

title

string | required.

Provide a title for the iframe in order to help screen reader users. More info

Special Thanks 👏

License 📋

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].