• Stars
    star
    104
  • Rank 330,604 (Top 7 %)
  • Language
    Objective-C
  • License
    MIT License
  • Created over 9 years ago
  • Updated over 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Display HTML in a UIWebView, optionally sanitizing it first

NOTE: There's not much point to this component now the built in WebView has more features. You might want to check out my (safe-html) library though if you want to make your untrusted HTML safe.

react-native-html-webview

Display (possibly untrusted) HTML using a UIWebView in React Native.

Uses an HTML Sanitizer to remove only let through a whitelist of tags and attributes (so it removes all javascript). Also supports automatically adjusting the height of the webview to contain the contents you give it.

Written by Thomas Parslow (almostobsolete.net and tomparslow.co.uk) as part of Active Inbox (activeinboxhq.com).

A couple of similar projects are HTMLText and HTMLView both of which render a subset of HTML as React Native views. This project takes a slightly different approach of using a UIWebView giving a full HTML renderer, but that means it has to rely on an HTML sanitizer to clean up untrusted HTML.

Installation

Install using npm with npm install --save react-native-html-webview

You then need to add the Objective C part to your XCode project. Drag AIBHTMLWebView.xcodeproj from the node_modules/react-native-html-webview folder into your XCode projec. Click on the your project in XCode, goto Build Phases then Link Binary With Libraries and add libAIBHTMLWebView.a.

NOTE: Make sure you don't have the AIBHTMLWebView project open seperately in XCode otherwise it won't work.

Usage

var HTMLWebView = require('react-native-html-webview');

var testView = React.createClass({
  render: function() {
    return (
      <View>
        <HTMLWebView
            style={{width: 300}}
            html={this.state.htmlContents}
            makeSafe={true}
            autoHeight={true}
            onLink={this.onLink}/>
      </View>
    );
  },
  onLink: function (href) {
    // Link was clicked!
  }
});

Properties

  • html : The html content to display as a string
  • makeSafe (default: true) : Run the HTML through an HTML sanitizer (safe-html) before inserting it to remove script tags and similar unsafe things. Pass in true to use the default options for safe-html, pass in false to turn it off, or pass in an object to set config options for safe-html.
  • autoHeight (default: false) : Automatically adjust the height of the webview to fit the contents (also turns off scrolling).
  • onLink : Pass in a function to be called when the user clicks a link, the function will be given the href.

Security Warning

This relies on HTML sanitization to protect you from executing JavaScript included in untrusted HTML. It's using my safe-html library which works based on a whitelist of allowed tags but it's still possbile someone could find a way round it.

If an attacker did find a way round the sanitizer they'd still only be running JavaScript inside a WebView. So they wouldn't automatically get access to the rest of your app, but they would be able to load other stuff into the webview and possibly other stuff that you may not want.

Feedback Welcome!

Feedback, questions, suggestions and most of all Pull Requests are very welcome. This is an early version and I want to figure out the best way to continue it.

I'm also available for freelance work!

I'm @almostobsolete on Twitter my email is [email protected] and you can find me on the web at tomparslow.co.uk and almostobsolete.net

More Repositories

1

react-native-sqlite

SQLite3 bindings for React Native
Objective-C
537
star
2

stream-template

An ES6 Tagged String Literal tag that can interpolate Node.JS streams, strings, arrays and Promises and produces a stream.
JavaScript
116
star
3

through2-concurrent

Simple Node.JS stream (streams2) Transform that runs the transform functions concurrently (with a set max concurrency)
JavaScript
74
star
4

org-daypage

Day pages for Emacs Org-Mode
Emacs Lisp
39
star
5

asyncboto

A small bit of code to make the Boto library for Amazon's AWS services work in an asynchronous (and extremely hacky) manner with Tornado. For a probably better approach see: http://blog.joshhaas.com/2011/06/marrying-boto-to-tornado-greenlets-bring-them-together/
Python
28
star
6

Haskell-Fun

Bits and pieces of Haskell code written for fun
Haskell
19
star
7

hubbub

Comments as GitHub pull requests for Jekyll (and other static site generator) websites.
JavaScript
16
star
8

react-native-sqlite-example

An example of how to read an SQLite database from React Native using react-native-sqlite
JavaScript
14
star
9

custom-ios-views-with-react-native

An example app showing a custom native component in React Native
Objective-C
13
star
10

safe-html

JavaScript
9
star
11

picprogrammer

Some minor fixes to Tetsujin's Python replacement for the PicPro programmer software.
Python
9
star
12

string-replace-stream

Replace one string with another string in a Node.js Stream.
JavaScript
9
star
13

regex-crossword-solver

A solver for a Regular Expression Crossword
Haskell
6
star
14

jquery-ebayshoppingapi

eBay Shopping API Plugin for jQuery
4
star
15

midiballs

OSX MIDI->OSC bridge for Felix's Machines
C++
3
star
16

tblc

Tiny PIC Boot Loader Command Line Tool
Python
3
star
17

sqs-readable-stream

Create a Readable Node.JS stream from an Amazon Simple Queue Service (SQS) Queue
JavaScript
3
star
18

mud.el

The beginings of a mud client using Circe's lui.el. Very basic and probably won't work for you right now.
Emacs Lisp
2
star
19

lhs-checkers

A literate Haskell program that plays Checkers.
Haskell
1
star
20

Data.Bloom

A Haskell implementation of a Bloom filter
Haskell
1
star
21

react-native-example-viewer

Component example viewer for React Native
JavaScript
1
star
22

dropbox-python

Fork of the Dropbox's Python API
Python
1
star
23

Marvin-Jabber-Client

This is a client for Jabber instant messenger servers that I wrote about 9 or 10 years ago. You probably don't want to use this, I just wanted to keep a hold of the code so I'm uploading it to Github.
Eiffel
1
star