Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
describe('WebView methods', () => {
const instanceWebView = new WebView({});
it('should passes when use properly', () => {
WebView.extraNativeComponentConfig();
(instanceWebView.goBack(): void);
(instanceWebView.goForward(): void);
(instanceWebView.reload(): void);
(instanceWebView.stopLoading(): void);
(instanceWebView.injectJavaScript('alert(1);'): void);
});
it('should raises an error when call injectJavaScript without arguments', () => {
// $ExpectError: first argument is required
instanceWebView.injectJavaScript();
});
it('should passes when use properly', () => {
WebView.extraNativeComponentConfig();
(instanceWebView.goBack(): void);
(instanceWebView.goForward(): void);
(instanceWebView.reload(): void);
(instanceWebView.stopLoading(): void);
(instanceWebView.injectJavaScript('alert(1);'): void);
});
render() {
return React.createElement(react_native_1.View, { style: { flex: 0.0001, width: 0, height: 0 } },
React.createElement(react_native_webview_1.WebView, { ref: (ref) => {
this._webViewRef = ref;
}, javaScriptEnabled: true, originWhitelist: ['about:blank'], automaticallyAdjustContentInsets: true, mixedContentMode: 'always', injectedJavaScript: patchPostMessageJsCode, source: {
html: getInvisibleRecaptchaContent(this.props.siteKey),
baseUrl: this.props.captchaDomain
}, onMessage: (e) => {
this.props.onReceiveToken(e.nativeEvent.data);
} }));
}
}
}
__dispatchCommand(commandName, args) {
const ref = this.webViewRef.current.webViewRef.current
UIManager.dispatchViewManagerCommand(
ReactNative.findNodeHandle(ref),
UIManager.getViewManagerConfig('ProtocolWebView').Commands[commandName],
args,
);
}
}
const ProtocolWebViewNative = requireNativeComponent(
'ProtocolWebView',
ProtocolWebView,
WebView.extraNativeComponentConfig
);
import React, { Component } from 'react'
import ReactNative, { UIManager, requireNativeComponent } from 'react-native'
import { WebView } from 'react-native-webview'
export class ProtocolWebView extends Component {
static propTypes = WebView.propTypes;
static protocolHandlers = {};
static registerStreamProtocol = (scheme, handler, completion) => {
ProtocolWebView.protocolHandlers[scheme] = (url, method, id, webview) => {
handler({url, method}, (response) => {
let stream = response;
let mimeType = response.mimeType;
if(response.data) {
stream = response.data
}
if(!mimeType) {
mimeType = stream.mimeType
}