react-native-inapp-inspector 1.0.3 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/commonjs/components/AnalyticsEventCard.js +10 -10
- package/dist/commonjs/components/CodeSnippet.js +233 -10
- package/dist/commonjs/components/ConsoleLogCard.js +55 -9
- package/dist/commonjs/components/CopyButton.js +2 -1
- package/dist/commonjs/components/ErrorBoundary.d.ts +20 -0
- package/dist/commonjs/components/ErrorBoundary.js +332 -0
- package/dist/commonjs/components/NetworkIcons.d.ts +5 -0
- package/dist/commonjs/components/NetworkIcons.js +45 -1
- package/dist/commonjs/customHooks/reduxLogger.d.ts +4 -0
- package/dist/commonjs/customHooks/reduxLogger.js +30 -0
- package/dist/commonjs/customHooks/webViewLogger.d.ts +2 -0
- package/dist/commonjs/customHooks/webViewLogger.js +281 -246
- package/dist/commonjs/helpers/index.js +2 -1
- package/dist/commonjs/index.d.ts +5 -3
- package/dist/commonjs/index.js +685 -911
- package/dist/commonjs/styles/AppColors.d.ts +29 -1
- package/dist/commonjs/styles/AppColors.js +38 -2
- package/dist/commonjs/styles/index.d.ts +438 -229
- package/dist/commonjs/styles/index.js +448 -209
- package/dist/commonjs/types/index.d.ts +2 -2
- package/dist/esm/components/AnalyticsEventCard.js +10 -10
- package/dist/esm/components/CodeSnippet.js +232 -12
- package/dist/esm/components/ConsoleLogCard.js +55 -9
- package/dist/esm/components/CopyButton.js +2 -1
- package/dist/esm/components/ErrorBoundary.d.ts +20 -0
- package/dist/esm/components/ErrorBoundary.js +295 -0
- package/dist/esm/components/NetworkIcons.d.ts +5 -0
- package/dist/esm/components/NetworkIcons.js +39 -0
- package/dist/esm/customHooks/reduxLogger.d.ts +4 -0
- package/dist/esm/customHooks/reduxLogger.js +23 -0
- package/dist/esm/customHooks/webViewLogger.d.ts +2 -0
- package/dist/esm/customHooks/webViewLogger.js +281 -246
- package/dist/esm/helpers/index.js +2 -1
- package/dist/esm/index.d.ts +5 -3
- package/dist/esm/index.js +683 -914
- package/dist/esm/styles/AppColors.d.ts +29 -1
- package/dist/esm/styles/AppColors.js +35 -1
- package/dist/esm/styles/index.d.ts +438 -229
- package/dist/esm/styles/index.js +412 -209
- package/dist/esm/types/index.d.ts +2 -2
- package/example/App.tsx +351 -127
- package/example/ios/Podfile.lock +26 -0
- package/example/metro.config.js +1 -1
- package/example/package-lock.json +20 -4
- package/example/package.json +4 -3
- package/package.json +1 -1
|
@@ -1,270 +1,305 @@
|
|
|
1
|
-
import React, { forwardRef } from 'react';
|
|
2
|
-
|
|
1
|
+
import React, { forwardRef, useState } from 'react';
|
|
2
|
+
import { View, ActivityIndicator, StyleSheet } from 'react-native';
|
|
3
|
+
let OriginalWebView = null;
|
|
3
4
|
try {
|
|
4
5
|
const RNWebView = require('react-native-webview');
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
var messageStr = '';
|
|
19
|
-
try {
|
|
20
|
-
var argsList = [];
|
|
21
|
-
for (var i = 0; i < args.length; i++) {
|
|
22
|
-
var arg = args[i];
|
|
23
|
-
if (typeof arg === 'object') {
|
|
24
|
-
try {
|
|
25
|
-
argsList.push(JSON.stringify(arg));
|
|
26
|
-
} catch (e) {
|
|
27
|
-
argsList.push(String(arg));
|
|
28
|
-
}
|
|
29
|
-
} else {
|
|
30
|
-
argsList.push(String(arg));
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
messageStr = argsList.join(' ');
|
|
34
|
-
} catch (err) {
|
|
35
|
-
messageStr = String(args);
|
|
36
|
-
}
|
|
6
|
+
OriginalWebView = RNWebView.WebView || RNWebView.default;
|
|
7
|
+
}
|
|
8
|
+
catch (e) {
|
|
9
|
+
// Silent fail
|
|
10
|
+
}
|
|
11
|
+
const injectJS = `
|
|
12
|
+
(function() {
|
|
13
|
+
if (!window.__webview_console_overridden__) {
|
|
14
|
+
window.__webview_console_overridden__ = true;
|
|
15
|
+
var originalLog = console.log;
|
|
16
|
+
var originalWarn = console.warn;
|
|
17
|
+
var originalError = console.error;
|
|
18
|
+
var originalInfo = console.info;
|
|
37
19
|
|
|
20
|
+
var sendToRN = function(type, args) {
|
|
21
|
+
if (window.ReactNativeWebView && window.ReactNativeWebView.postMessage) {
|
|
22
|
+
var messageStr = '';
|
|
23
|
+
try {
|
|
24
|
+
var argsList = [];
|
|
25
|
+
for (var i = 0; i < args.length; i++) {
|
|
26
|
+
var arg = args[i];
|
|
27
|
+
if (typeof arg === 'object') {
|
|
38
28
|
try {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
message: messageStr
|
|
43
|
-
}));
|
|
44
|
-
} catch (postErr) {}
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
console.log = function() {
|
|
49
|
-
if (originalLog) {
|
|
50
|
-
originalLog.apply(console, arguments);
|
|
51
|
-
}
|
|
52
|
-
sendToRN('log', arguments);
|
|
53
|
-
};
|
|
54
|
-
console.warn = function() {
|
|
55
|
-
if (originalWarn) {
|
|
56
|
-
originalWarn.apply(console, arguments);
|
|
57
|
-
}
|
|
58
|
-
sendToRN('warn', arguments);
|
|
59
|
-
};
|
|
60
|
-
console.error = function() {
|
|
61
|
-
if (originalError) {
|
|
62
|
-
originalError.apply(console, arguments);
|
|
29
|
+
argsList.push(JSON.stringify(arg));
|
|
30
|
+
} catch (e) {
|
|
31
|
+
argsList.push(String(arg));
|
|
63
32
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if (originalInfo) {
|
|
68
|
-
originalInfo.apply(console, arguments);
|
|
69
|
-
}
|
|
70
|
-
sendToRN('info', arguments);
|
|
71
|
-
};
|
|
33
|
+
} else {
|
|
34
|
+
argsList.push(String(arg));
|
|
35
|
+
}
|
|
72
36
|
}
|
|
37
|
+
messageStr = argsList.join(' ');
|
|
38
|
+
} catch (err) {
|
|
39
|
+
messageStr = String(args);
|
|
40
|
+
}
|
|
73
41
|
|
|
74
|
-
|
|
75
|
-
window.
|
|
42
|
+
try {
|
|
43
|
+
window.ReactNativeWebView.postMessage(JSON.stringify({
|
|
44
|
+
type: 'webview-log',
|
|
45
|
+
logType: type,
|
|
46
|
+
message: messageStr
|
|
47
|
+
}));
|
|
48
|
+
} catch (postErr) {}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
76
51
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
52
|
+
console.log = function() {
|
|
53
|
+
if (originalLog) {
|
|
54
|
+
originalLog.apply(console, arguments);
|
|
55
|
+
}
|
|
56
|
+
sendToRN('log', arguments);
|
|
57
|
+
};
|
|
58
|
+
console.warn = function() {
|
|
59
|
+
if (originalWarn) {
|
|
60
|
+
originalWarn.apply(console, arguments);
|
|
61
|
+
}
|
|
62
|
+
sendToRN('warn', arguments);
|
|
63
|
+
};
|
|
64
|
+
console.error = function() {
|
|
65
|
+
if (originalError) {
|
|
66
|
+
originalError.apply(console, arguments);
|
|
67
|
+
}
|
|
68
|
+
sendToRN('error', arguments);
|
|
69
|
+
};
|
|
70
|
+
console.info = function() {
|
|
71
|
+
if (originalInfo) {
|
|
72
|
+
originalInfo.apply(console, arguments);
|
|
73
|
+
}
|
|
74
|
+
sendToRN('info', arguments);
|
|
75
|
+
};
|
|
76
|
+
}
|
|
87
77
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
try {
|
|
91
|
-
var sheets = document.styleSheets;
|
|
92
|
-
if (sheets) {
|
|
93
|
-
for (var i = 0; i < sheets.length; i++) {
|
|
94
|
-
var sheet = sheets[i];
|
|
95
|
-
try {
|
|
96
|
-
var rules = sheet.cssRules || sheet.rules;
|
|
97
|
-
if (rules) {
|
|
98
|
-
for (var j = 0; j < rules.length; j++) {
|
|
99
|
-
css += rules[j].cssText + String.fromCharCode(10);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
} catch (e) {
|
|
103
|
-
if (sheet.href) {
|
|
104
|
-
css += '/* External stylesheet: ' + sheet.href + ' */' + String.fromCharCode(10);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
} catch (e) {}
|
|
78
|
+
if (!window.__webview_html_capture_setup__) {
|
|
79
|
+
window.__webview_html_capture_setup__ = true;
|
|
110
80
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
} catch (e) {}
|
|
81
|
+
var sendHtmlRetries = 0;
|
|
82
|
+
window.__webview_send_html__ = function() {
|
|
83
|
+
if (window.ReactNativeWebView && window.ReactNativeWebView.postMessage) {
|
|
84
|
+
try {
|
|
85
|
+
var html = '';
|
|
86
|
+
try {
|
|
87
|
+
if (document && document.documentElement) {
|
|
88
|
+
html = document.documentElement.outerHTML || '';
|
|
89
|
+
}
|
|
90
|
+
} catch (e) {}
|
|
124
91
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
92
|
+
// Get CSS
|
|
93
|
+
var css = '';
|
|
94
|
+
try {
|
|
95
|
+
var sheets = document.styleSheets;
|
|
96
|
+
if (sheets) {
|
|
97
|
+
for (var i = 0; i < sheets.length; i++) {
|
|
98
|
+
var sheet = sheets[i];
|
|
99
|
+
try {
|
|
100
|
+
var rules = sheet.cssRules || sheet.rules;
|
|
101
|
+
if (rules) {
|
|
102
|
+
for (var j = 0; j < rules.length; j++) {
|
|
103
|
+
css += rules[j].cssText + String.fromCharCode(10);
|
|
140
104
|
}
|
|
141
|
-
} catch (e) {}
|
|
142
|
-
|
|
143
|
-
try {
|
|
144
|
-
window.ReactNativeWebView.postMessage(JSON.stringify({
|
|
145
|
-
type: 'webview-html',
|
|
146
|
-
html: html,
|
|
147
|
-
css: css,
|
|
148
|
-
js: js,
|
|
149
|
-
url: window.location.href
|
|
150
|
-
}));
|
|
151
|
-
} catch (postError) {
|
|
152
|
-
try {
|
|
153
|
-
window.ReactNativeWebView.postMessage(JSON.stringify({
|
|
154
|
-
type: 'webview-html',
|
|
155
|
-
html: html,
|
|
156
|
-
css: '/* CSS truncated due to size limit */',
|
|
157
|
-
js: '/* JS truncated due to size limit */',
|
|
158
|
-
url: window.location.href
|
|
159
|
-
}));
|
|
160
|
-
} catch (htmlOnlyError) {
|
|
161
|
-
window.ReactNativeWebView.postMessage(JSON.stringify({
|
|
162
|
-
type: 'webview-html',
|
|
163
|
-
html: '<h1>Page source too large to capture</h1>',
|
|
164
|
-
url: window.location.href
|
|
165
|
-
}));
|
|
166
105
|
}
|
|
106
|
+
} catch (e) {
|
|
107
|
+
if (sheet.href) {
|
|
108
|
+
css += '/* External stylesheet: ' + sheet.href + ' */' + String.fromCharCode(10);
|
|
167
109
|
}
|
|
168
|
-
} catch (err) {}
|
|
169
|
-
} else if (sendHtmlRetries < 50) {
|
|
170
|
-
sendHtmlRetries++;
|
|
171
|
-
setTimeout(window.__webview_send_html__, 100);
|
|
172
110
|
}
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
var debounceTimeout = null;
|
|
176
|
-
window.__webview_debounced_send_html__ = function() {
|
|
177
|
-
if (debounceTimeout) {
|
|
178
|
-
clearTimeout(debounceTimeout);
|
|
179
111
|
}
|
|
180
|
-
|
|
181
|
-
}
|
|
112
|
+
}
|
|
113
|
+
} catch (e) {}
|
|
182
114
|
|
|
183
|
-
// Setup MutationObserver for SPAs
|
|
184
115
|
try {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
116
|
+
var styles = document.querySelectorAll('style');
|
|
117
|
+
if (styles) {
|
|
118
|
+
for (var i = 0; i < styles.length; i++) {
|
|
119
|
+
var style = styles[i];
|
|
120
|
+
if (style && style.textContent) {
|
|
121
|
+
if (css.indexOf(style.textContent) === -1) {
|
|
122
|
+
css += style.textContent + String.fromCharCode(10);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
193
127
|
} catch (e) {}
|
|
194
128
|
|
|
195
|
-
//
|
|
129
|
+
// Get JS
|
|
130
|
+
var js = '';
|
|
196
131
|
try {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
132
|
+
var scripts = document.querySelectorAll('script');
|
|
133
|
+
if (scripts) {
|
|
134
|
+
for (var i = 0; i < scripts.length; i++) {
|
|
135
|
+
var script = scripts[i];
|
|
136
|
+
if (script) {
|
|
137
|
+
if (script.src) {
|
|
138
|
+
js += '// External Script: ' + script.src + String.fromCharCode(10);
|
|
139
|
+
} else if (script.textContent) {
|
|
140
|
+
js += script.textContent + String.fromCharCode(10);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
209
145
|
} catch (e) {}
|
|
210
146
|
|
|
211
|
-
|
|
212
|
-
window.
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
147
|
+
try {
|
|
148
|
+
window.ReactNativeWebView.postMessage(JSON.stringify({
|
|
149
|
+
type: 'webview-html',
|
|
150
|
+
html: html,
|
|
151
|
+
css: css,
|
|
152
|
+
js: js,
|
|
153
|
+
url: window.location.href
|
|
154
|
+
}));
|
|
155
|
+
} catch (postError) {
|
|
156
|
+
try {
|
|
157
|
+
window.ReactNativeWebView.postMessage(JSON.stringify({
|
|
158
|
+
type: 'webview-html',
|
|
159
|
+
html: html,
|
|
160
|
+
css: '/* CSS truncated due to size limit */',
|
|
161
|
+
js: '/* JS truncated due to size limit */',
|
|
162
|
+
url: window.location.href
|
|
163
|
+
}));
|
|
164
|
+
} catch (htmlOnlyError) {
|
|
165
|
+
window.ReactNativeWebView.postMessage(JSON.stringify({
|
|
166
|
+
type: 'webview-html',
|
|
167
|
+
html: '<h1>Page source too large to capture</h1>',
|
|
168
|
+
url: window.location.href
|
|
169
|
+
}));
|
|
219
170
|
}
|
|
220
171
|
}
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
};
|
|
246
|
-
// Register initial URL
|
|
247
|
-
React.useEffect(() => {
|
|
248
|
-
if (props.source && props.source.uri) {
|
|
249
|
-
addWebViewNav(props.source.uri, 'Initial Page');
|
|
250
|
-
}
|
|
251
|
-
}, [props.source?.uri]);
|
|
252
|
-
const combinedInjectedJSBefore = props.injectedJavaScriptBeforeContentLoaded
|
|
253
|
-
? `${injectJS}\n${props.injectedJavaScriptBeforeContentLoaded}`
|
|
254
|
-
: injectJS;
|
|
255
|
-
const combinedInjectedJS = props.injectedJavaScript
|
|
256
|
-
? `${injectJS}\n${props.injectedJavaScript}`
|
|
257
|
-
: injectJS;
|
|
258
|
-
return React.createElement(OriginalWebView, {
|
|
259
|
-
...props,
|
|
260
|
-
ref: ref,
|
|
261
|
-
injectedJavaScriptBeforeContentLoaded: combinedInjectedJSBefore,
|
|
262
|
-
injectedJavaScript: combinedInjectedJS,
|
|
263
|
-
onMessage: handleMessage,
|
|
264
|
-
onNavigationStateChange: handleNavigationStateChange,
|
|
265
|
-
});
|
|
172
|
+
} catch (err) {}
|
|
173
|
+
} else if (sendHtmlRetries < 50) {
|
|
174
|
+
sendHtmlRetries++;
|
|
175
|
+
setTimeout(window.__webview_send_html__, 100);
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
var debounceTimeout = null;
|
|
180
|
+
window.__webview_debounced_send_html__ = function() {
|
|
181
|
+
if (debounceTimeout) {
|
|
182
|
+
clearTimeout(debounceTimeout);
|
|
183
|
+
}
|
|
184
|
+
debounceTimeout = setTimeout(window.__webview_send_html__, 500);
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
// Setup MutationObserver for SPAs
|
|
188
|
+
try {
|
|
189
|
+
var observer = new MutationObserver(function() {
|
|
190
|
+
window.__webview_debounced_send_html__();
|
|
191
|
+
});
|
|
192
|
+
observer.observe(document.documentElement, {
|
|
193
|
+
attributes: true,
|
|
194
|
+
childList: true,
|
|
195
|
+
subtree: true
|
|
266
196
|
});
|
|
267
|
-
|
|
197
|
+
} catch (e) {}
|
|
198
|
+
|
|
199
|
+
// Setup SPA router state changes
|
|
200
|
+
try {
|
|
201
|
+
var originalPushState = history.pushState;
|
|
202
|
+
history.pushState = function() {
|
|
203
|
+
originalPushState.apply(this, arguments);
|
|
204
|
+
window.__webview_debounced_send_html__();
|
|
205
|
+
};
|
|
206
|
+
var originalReplaceState = history.replaceState;
|
|
207
|
+
history.replaceState = function() {
|
|
208
|
+
originalReplaceState.apply(this, arguments);
|
|
209
|
+
window.__webview_debounced_send_html__();
|
|
210
|
+
};
|
|
211
|
+
window.addEventListener('popstate', window.__webview_debounced_send_html__);
|
|
212
|
+
window.addEventListener('hashchange', window.__webview_debounced_send_html__);
|
|
213
|
+
} catch (e) {}
|
|
214
|
+
|
|
215
|
+
window.addEventListener('DOMContentLoaded', window.__webview_send_html__);
|
|
216
|
+
window.addEventListener('load', window.__webview_send_html__);
|
|
217
|
+
if (document.readyState === 'interactive' || document.readyState === 'complete') {
|
|
218
|
+
window.__webview_send_html__();
|
|
219
|
+
}
|
|
220
|
+
} else {
|
|
221
|
+
if (window.__webview_send_html__) {
|
|
222
|
+
window.__webview_send_html__();
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
})();
|
|
226
|
+
true;
|
|
227
|
+
`;
|
|
228
|
+
export const WebView = forwardRef((props, ref) => {
|
|
229
|
+
if (!OriginalWebView) {
|
|
230
|
+
console.warn('[NetworkInspector] react-native-webview not found. Make sure it is installed.');
|
|
231
|
+
return null;
|
|
232
|
+
}
|
|
233
|
+
const [loading, setLoading] = useState(false);
|
|
234
|
+
const handleMessage = (event) => {
|
|
235
|
+
try {
|
|
236
|
+
const data = JSON.parse(event.nativeEvent.data);
|
|
237
|
+
if (data.type === 'webview-log') {
|
|
238
|
+
addWebViewLog(data.logType, data.message);
|
|
239
|
+
}
|
|
240
|
+
else if (data.type === 'webview-html') {
|
|
241
|
+
addWebViewHtml(data.url, data.html, data.css, data.js);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
catch (e) { }
|
|
245
|
+
if (props.onMessage) {
|
|
246
|
+
props.onMessage(event);
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
const handleNavigationStateChange = (navState) => {
|
|
250
|
+
addWebViewNav(navState.url, navState.title);
|
|
251
|
+
if (props.onNavigationStateChange) {
|
|
252
|
+
props.onNavigationStateChange(navState);
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
const handleLoadStart = (syntheticEvent) => {
|
|
256
|
+
setLoading(true);
|
|
257
|
+
if (props.onLoadStart) {
|
|
258
|
+
props.onLoadStart(syntheticEvent);
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
const handleLoadEnd = (syntheticEvent) => {
|
|
262
|
+
setLoading(false);
|
|
263
|
+
if (props.onLoadEnd) {
|
|
264
|
+
props.onLoadEnd(syntheticEvent);
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
// Register initial URL
|
|
268
|
+
React.useEffect(() => {
|
|
269
|
+
if (props.source && props.source.uri) {
|
|
270
|
+
addWebViewNav(props.source.uri, 'Initial Page');
|
|
271
|
+
}
|
|
272
|
+
}, [props.source?.uri]);
|
|
273
|
+
const combinedInjectedJSBefore = props.injectedJavaScriptBeforeContentLoaded
|
|
274
|
+
? `${injectJS}\n${props.injectedJavaScriptBeforeContentLoaded}`
|
|
275
|
+
: injectJS;
|
|
276
|
+
const combinedInjectedJS = props.injectedJavaScript
|
|
277
|
+
? `${injectJS}\n${props.injectedJavaScript}`
|
|
278
|
+
: injectJS;
|
|
279
|
+
const showLoader = props.showLoader !== false;
|
|
280
|
+
return React.createElement(View, { style: props.style || { flex: 1 } }, React.createElement(OriginalWebView, {
|
|
281
|
+
...props,
|
|
282
|
+
style: { flex: 1 },
|
|
283
|
+
ref: ref,
|
|
284
|
+
injectedJavaScriptBeforeContentLoaded: combinedInjectedJSBefore,
|
|
285
|
+
injectedJavaScript: combinedInjectedJS,
|
|
286
|
+
onMessage: handleMessage,
|
|
287
|
+
onNavigationStateChange: handleNavigationStateChange,
|
|
288
|
+
onLoadStart: handleLoadStart,
|
|
289
|
+
onLoadEnd: handleLoadEnd,
|
|
290
|
+
}), loading && showLoader && React.createElement(View, {
|
|
291
|
+
style: {
|
|
292
|
+
...StyleSheet.absoluteFill,
|
|
293
|
+
justifyContent: 'center',
|
|
294
|
+
alignItems: 'center',
|
|
295
|
+
backgroundColor: 'rgba(255, 255, 255, 0.4)',
|
|
296
|
+
},
|
|
297
|
+
}, React.createElement(ActivityIndicator, { size: 'large', color: '#684B9B' })));
|
|
298
|
+
});
|
|
299
|
+
// Perform monkey-patching to intercept react-native-webview exports globally
|
|
300
|
+
try {
|
|
301
|
+
const RNWebView = require('react-native-webview');
|
|
302
|
+
if (RNWebView) {
|
|
268
303
|
const defineProp = (obj, prop, value) => {
|
|
269
304
|
try {
|
|
270
305
|
Object.defineProperty(obj, prop, {
|
|
@@ -282,18 +317,18 @@ try {
|
|
|
282
317
|
}
|
|
283
318
|
};
|
|
284
319
|
if (RNWebView.WebView) {
|
|
285
|
-
defineProp(RNWebView, 'WebView',
|
|
320
|
+
defineProp(RNWebView, 'WebView', WebView);
|
|
286
321
|
}
|
|
287
322
|
if (RNWebView.default) {
|
|
288
323
|
if (RNWebView.default.WebView) {
|
|
289
|
-
defineProp(RNWebView.default, 'WebView',
|
|
324
|
+
defineProp(RNWebView.default, 'WebView', WebView);
|
|
290
325
|
}
|
|
291
|
-
defineProp(RNWebView, 'default',
|
|
326
|
+
defineProp(RNWebView, 'default', WebView);
|
|
292
327
|
}
|
|
293
328
|
}
|
|
294
329
|
}
|
|
295
330
|
catch (e) {
|
|
296
|
-
// Silent fail
|
|
331
|
+
// Silent fail
|
|
297
332
|
}
|
|
298
333
|
let logs = [];
|
|
299
334
|
let navHistory = [];
|
|
@@ -332,7 +367,7 @@ export const addWebViewNav = (url, title) => {
|
|
|
332
367
|
title,
|
|
333
368
|
timestamp: Date.now(),
|
|
334
369
|
});
|
|
335
|
-
navHistory = navHistory.slice(0,
|
|
370
|
+
navHistory = navHistory.slice(0, 5);
|
|
336
371
|
notify();
|
|
337
372
|
};
|
|
338
373
|
export const addWebViewHtml = (url, html, css, js) => {
|
|
@@ -53,7 +53,8 @@ export const getSize = (data) => {
|
|
|
53
53
|
}
|
|
54
54
|
};
|
|
55
55
|
export const copyToClipboard = (value, label) => {
|
|
56
|
-
const
|
|
56
|
+
const resolved = typeof value === 'function' ? value() : value;
|
|
57
|
+
const text = typeof resolved === 'string' ? resolved : JSON.stringify(resolved, null, 2);
|
|
57
58
|
Clipboard.setString(text ?? '');
|
|
58
59
|
if (Platform.OS === 'android') {
|
|
59
60
|
ToastAndroid.show(`${label} copied`, ToastAndroid.SHORT);
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
declare const
|
|
3
|
-
export default
|
|
2
|
+
declare const NetworkInspectorWrapper: (props: any) => React.JSX.Element;
|
|
3
|
+
export default NetworkInspectorWrapper;
|
|
4
4
|
export { setupNetworkLogger, clearNetworkLogs, subscribeNetworkLogs, } from './customHooks/networkLogger';
|
|
5
5
|
export { setupConsoleLogger, clearConsoleLogs, subscribeConsoleLogs, } from './customHooks/consoleLogger';
|
|
6
6
|
export { setupAnalyticsLogger, logAnalyticsEvent, subscribeAnalyticsEvents, clearAnalyticsEvents, } from './customHooks/analyticsLogger';
|
|
7
|
-
export { getWebViewLogs, getWebViewNavHistory, getWebViewHtml, getWebViewCss, getWebViewJs, getWebViewHtmlUrl, clearWebViewData, subscribeWebView, } from './customHooks/webViewLogger';
|
|
7
|
+
export { WebView, getWebViewLogs, getWebViewNavHistory, getWebViewHtml, getWebViewCss, getWebViewJs, getWebViewHtmlUrl, clearWebViewData, subscribeWebView, } from './customHooks/webViewLogger';
|
|
8
|
+
export { default as ErrorBoundary } from './components/ErrorBoundary';
|
|
9
|
+
export { connectReduxStore, getReduxState, subscribeReduxState, } from './customHooks/reduxLogger';
|