react-native-inapp-inspector 1.0.4 → 1.0.6
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 +11 -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/package-lock.json +20 -4
- package/example/package.json +4 -3
- package/package.json +11 -1
|
@@ -33,274 +33,309 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.subscribeWebView = exports.clearWebViewData = exports.getWebViewHtmlUrl = exports.getWebViewJs = exports.getWebViewCss = exports.getWebViewHtml = exports.getWebViewNavHistory = exports.getWebViewLogs = exports.addWebViewHtml = exports.addWebViewNav = exports.addWebViewLog = void 0;
|
|
36
|
+
exports.subscribeWebView = exports.clearWebViewData = exports.getWebViewHtmlUrl = exports.getWebViewJs = exports.getWebViewCss = exports.getWebViewHtml = exports.getWebViewNavHistory = exports.getWebViewLogs = exports.addWebViewHtml = exports.addWebViewNav = exports.addWebViewLog = exports.WebView = void 0;
|
|
37
37
|
const react_1 = __importStar(require("react"));
|
|
38
|
-
|
|
38
|
+
const react_native_1 = require("react-native");
|
|
39
|
+
let OriginalWebView = null;
|
|
39
40
|
try {
|
|
40
41
|
const RNWebView = require('react-native-webview');
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
var messageStr = '';
|
|
55
|
-
try {
|
|
56
|
-
var argsList = [];
|
|
57
|
-
for (var i = 0; i < args.length; i++) {
|
|
58
|
-
var arg = args[i];
|
|
59
|
-
if (typeof arg === 'object') {
|
|
60
|
-
try {
|
|
61
|
-
argsList.push(JSON.stringify(arg));
|
|
62
|
-
} catch (e) {
|
|
63
|
-
argsList.push(String(arg));
|
|
64
|
-
}
|
|
65
|
-
} else {
|
|
66
|
-
argsList.push(String(arg));
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
messageStr = argsList.join(' ');
|
|
70
|
-
} catch (err) {
|
|
71
|
-
messageStr = String(args);
|
|
72
|
-
}
|
|
42
|
+
OriginalWebView = RNWebView.WebView || RNWebView.default;
|
|
43
|
+
}
|
|
44
|
+
catch (e) {
|
|
45
|
+
// Silent fail
|
|
46
|
+
}
|
|
47
|
+
const injectJS = `
|
|
48
|
+
(function() {
|
|
49
|
+
if (!window.__webview_console_overridden__) {
|
|
50
|
+
window.__webview_console_overridden__ = true;
|
|
51
|
+
var originalLog = console.log;
|
|
52
|
+
var originalWarn = console.warn;
|
|
53
|
+
var originalError = console.error;
|
|
54
|
+
var originalInfo = console.info;
|
|
73
55
|
|
|
56
|
+
var sendToRN = function(type, args) {
|
|
57
|
+
if (window.ReactNativeWebView && window.ReactNativeWebView.postMessage) {
|
|
58
|
+
var messageStr = '';
|
|
59
|
+
try {
|
|
60
|
+
var argsList = [];
|
|
61
|
+
for (var i = 0; i < args.length; i++) {
|
|
62
|
+
var arg = args[i];
|
|
63
|
+
if (typeof arg === 'object') {
|
|
74
64
|
try {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
message: messageStr
|
|
79
|
-
}));
|
|
80
|
-
} catch (postErr) {}
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
console.log = function() {
|
|
85
|
-
if (originalLog) {
|
|
86
|
-
originalLog.apply(console, arguments);
|
|
87
|
-
}
|
|
88
|
-
sendToRN('log', arguments);
|
|
89
|
-
};
|
|
90
|
-
console.warn = function() {
|
|
91
|
-
if (originalWarn) {
|
|
92
|
-
originalWarn.apply(console, arguments);
|
|
93
|
-
}
|
|
94
|
-
sendToRN('warn', arguments);
|
|
95
|
-
};
|
|
96
|
-
console.error = function() {
|
|
97
|
-
if (originalError) {
|
|
98
|
-
originalError.apply(console, arguments);
|
|
65
|
+
argsList.push(JSON.stringify(arg));
|
|
66
|
+
} catch (e) {
|
|
67
|
+
argsList.push(String(arg));
|
|
99
68
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
if (originalInfo) {
|
|
104
|
-
originalInfo.apply(console, arguments);
|
|
105
|
-
}
|
|
106
|
-
sendToRN('info', arguments);
|
|
107
|
-
};
|
|
69
|
+
} else {
|
|
70
|
+
argsList.push(String(arg));
|
|
71
|
+
}
|
|
108
72
|
}
|
|
73
|
+
messageStr = argsList.join(' ');
|
|
74
|
+
} catch (err) {
|
|
75
|
+
messageStr = String(args);
|
|
76
|
+
}
|
|
109
77
|
|
|
110
|
-
|
|
111
|
-
window.
|
|
78
|
+
try {
|
|
79
|
+
window.ReactNativeWebView.postMessage(JSON.stringify({
|
|
80
|
+
type: 'webview-log',
|
|
81
|
+
logType: type,
|
|
82
|
+
message: messageStr
|
|
83
|
+
}));
|
|
84
|
+
} catch (postErr) {}
|
|
85
|
+
}
|
|
86
|
+
};
|
|
112
87
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
88
|
+
console.log = function() {
|
|
89
|
+
if (originalLog) {
|
|
90
|
+
originalLog.apply(console, arguments);
|
|
91
|
+
}
|
|
92
|
+
sendToRN('log', arguments);
|
|
93
|
+
};
|
|
94
|
+
console.warn = function() {
|
|
95
|
+
if (originalWarn) {
|
|
96
|
+
originalWarn.apply(console, arguments);
|
|
97
|
+
}
|
|
98
|
+
sendToRN('warn', arguments);
|
|
99
|
+
};
|
|
100
|
+
console.error = function() {
|
|
101
|
+
if (originalError) {
|
|
102
|
+
originalError.apply(console, arguments);
|
|
103
|
+
}
|
|
104
|
+
sendToRN('error', arguments);
|
|
105
|
+
};
|
|
106
|
+
console.info = function() {
|
|
107
|
+
if (originalInfo) {
|
|
108
|
+
originalInfo.apply(console, arguments);
|
|
109
|
+
}
|
|
110
|
+
sendToRN('info', arguments);
|
|
111
|
+
};
|
|
112
|
+
}
|
|
123
113
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
try {
|
|
127
|
-
var sheets = document.styleSheets;
|
|
128
|
-
if (sheets) {
|
|
129
|
-
for (var i = 0; i < sheets.length; i++) {
|
|
130
|
-
var sheet = sheets[i];
|
|
131
|
-
try {
|
|
132
|
-
var rules = sheet.cssRules || sheet.rules;
|
|
133
|
-
if (rules) {
|
|
134
|
-
for (var j = 0; j < rules.length; j++) {
|
|
135
|
-
css += rules[j].cssText + String.fromCharCode(10);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
} catch (e) {
|
|
139
|
-
if (sheet.href) {
|
|
140
|
-
css += '/* External stylesheet: ' + sheet.href + ' */' + String.fromCharCode(10);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
} catch (e) {}
|
|
114
|
+
if (!window.__webview_html_capture_setup__) {
|
|
115
|
+
window.__webview_html_capture_setup__ = true;
|
|
146
116
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
} catch (e) {}
|
|
117
|
+
var sendHtmlRetries = 0;
|
|
118
|
+
window.__webview_send_html__ = function() {
|
|
119
|
+
if (window.ReactNativeWebView && window.ReactNativeWebView.postMessage) {
|
|
120
|
+
try {
|
|
121
|
+
var html = '';
|
|
122
|
+
try {
|
|
123
|
+
if (document && document.documentElement) {
|
|
124
|
+
html = document.documentElement.outerHTML || '';
|
|
125
|
+
}
|
|
126
|
+
} catch (e) {}
|
|
160
127
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
}
|
|
128
|
+
// Get CSS
|
|
129
|
+
var css = '';
|
|
130
|
+
try {
|
|
131
|
+
var sheets = document.styleSheets;
|
|
132
|
+
if (sheets) {
|
|
133
|
+
for (var i = 0; i < sheets.length; i++) {
|
|
134
|
+
var sheet = sheets[i];
|
|
135
|
+
try {
|
|
136
|
+
var rules = sheet.cssRules || sheet.rules;
|
|
137
|
+
if (rules) {
|
|
138
|
+
for (var j = 0; j < rules.length; j++) {
|
|
139
|
+
css += rules[j].cssText + String.fromCharCode(10);
|
|
176
140
|
}
|
|
177
|
-
} catch (e) {}
|
|
178
|
-
|
|
179
|
-
try {
|
|
180
|
-
window.ReactNativeWebView.postMessage(JSON.stringify({
|
|
181
|
-
type: 'webview-html',
|
|
182
|
-
html: html,
|
|
183
|
-
css: css,
|
|
184
|
-
js: js,
|
|
185
|
-
url: window.location.href
|
|
186
|
-
}));
|
|
187
|
-
} catch (postError) {
|
|
188
|
-
try {
|
|
189
|
-
window.ReactNativeWebView.postMessage(JSON.stringify({
|
|
190
|
-
type: 'webview-html',
|
|
191
|
-
html: html,
|
|
192
|
-
css: '/* CSS truncated due to size limit */',
|
|
193
|
-
js: '/* JS truncated due to size limit */',
|
|
194
|
-
url: window.location.href
|
|
195
|
-
}));
|
|
196
|
-
} catch (htmlOnlyError) {
|
|
197
|
-
window.ReactNativeWebView.postMessage(JSON.stringify({
|
|
198
|
-
type: 'webview-html',
|
|
199
|
-
html: '<h1>Page source too large to capture</h1>',
|
|
200
|
-
url: window.location.href
|
|
201
|
-
}));
|
|
202
141
|
}
|
|
142
|
+
} catch (e) {
|
|
143
|
+
if (sheet.href) {
|
|
144
|
+
css += '/* External stylesheet: ' + sheet.href + ' */' + String.fromCharCode(10);
|
|
203
145
|
}
|
|
204
|
-
} catch (err) {}
|
|
205
|
-
} else if (sendHtmlRetries < 50) {
|
|
206
|
-
sendHtmlRetries++;
|
|
207
|
-
setTimeout(window.__webview_send_html__, 100);
|
|
208
146
|
}
|
|
209
|
-
};
|
|
210
|
-
|
|
211
|
-
var debounceTimeout = null;
|
|
212
|
-
window.__webview_debounced_send_html__ = function() {
|
|
213
|
-
if (debounceTimeout) {
|
|
214
|
-
clearTimeout(debounceTimeout);
|
|
215
147
|
}
|
|
216
|
-
|
|
217
|
-
}
|
|
148
|
+
}
|
|
149
|
+
} catch (e) {}
|
|
218
150
|
|
|
219
|
-
// Setup MutationObserver for SPAs
|
|
220
151
|
try {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
152
|
+
var styles = document.querySelectorAll('style');
|
|
153
|
+
if (styles) {
|
|
154
|
+
for (var i = 0; i < styles.length; i++) {
|
|
155
|
+
var style = styles[i];
|
|
156
|
+
if (style && style.textContent) {
|
|
157
|
+
if (css.indexOf(style.textContent) === -1) {
|
|
158
|
+
css += style.textContent + String.fromCharCode(10);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
229
163
|
} catch (e) {}
|
|
230
164
|
|
|
231
|
-
//
|
|
165
|
+
// Get JS
|
|
166
|
+
var js = '';
|
|
232
167
|
try {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
168
|
+
var scripts = document.querySelectorAll('script');
|
|
169
|
+
if (scripts) {
|
|
170
|
+
for (var i = 0; i < scripts.length; i++) {
|
|
171
|
+
var script = scripts[i];
|
|
172
|
+
if (script) {
|
|
173
|
+
if (script.src) {
|
|
174
|
+
js += '// External Script: ' + script.src + String.fromCharCode(10);
|
|
175
|
+
} else if (script.textContent) {
|
|
176
|
+
js += script.textContent + String.fromCharCode(10);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
245
181
|
} catch (e) {}
|
|
246
182
|
|
|
247
|
-
|
|
248
|
-
window.
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
183
|
+
try {
|
|
184
|
+
window.ReactNativeWebView.postMessage(JSON.stringify({
|
|
185
|
+
type: 'webview-html',
|
|
186
|
+
html: html,
|
|
187
|
+
css: css,
|
|
188
|
+
js: js,
|
|
189
|
+
url: window.location.href
|
|
190
|
+
}));
|
|
191
|
+
} catch (postError) {
|
|
192
|
+
try {
|
|
193
|
+
window.ReactNativeWebView.postMessage(JSON.stringify({
|
|
194
|
+
type: 'webview-html',
|
|
195
|
+
html: html,
|
|
196
|
+
css: '/* CSS truncated due to size limit */',
|
|
197
|
+
js: '/* JS truncated due to size limit */',
|
|
198
|
+
url: window.location.href
|
|
199
|
+
}));
|
|
200
|
+
} catch (htmlOnlyError) {
|
|
201
|
+
window.ReactNativeWebView.postMessage(JSON.stringify({
|
|
202
|
+
type: 'webview-html',
|
|
203
|
+
html: '<h1>Page source too large to capture</h1>',
|
|
204
|
+
url: window.location.href
|
|
205
|
+
}));
|
|
255
206
|
}
|
|
256
207
|
}
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
const handleNavigationStateChange = (navState) => {
|
|
277
|
-
(0, exports.addWebViewNav)(navState.url, navState.title);
|
|
278
|
-
if (props.onNavigationStateChange) {
|
|
279
|
-
props.onNavigationStateChange(navState);
|
|
280
|
-
}
|
|
281
|
-
};
|
|
282
|
-
// Register initial URL
|
|
283
|
-
react_1.default.useEffect(() => {
|
|
284
|
-
if (props.source && props.source.uri) {
|
|
285
|
-
(0, exports.addWebViewNav)(props.source.uri, 'Initial Page');
|
|
286
|
-
}
|
|
287
|
-
}, [props.source?.uri]);
|
|
288
|
-
const combinedInjectedJSBefore = props.injectedJavaScriptBeforeContentLoaded
|
|
289
|
-
? `${injectJS}\n${props.injectedJavaScriptBeforeContentLoaded}`
|
|
290
|
-
: injectJS;
|
|
291
|
-
const combinedInjectedJS = props.injectedJavaScript
|
|
292
|
-
? `${injectJS}\n${props.injectedJavaScript}`
|
|
293
|
-
: injectJS;
|
|
294
|
-
return react_1.default.createElement(OriginalWebView, {
|
|
295
|
-
...props,
|
|
296
|
-
ref: ref,
|
|
297
|
-
injectedJavaScriptBeforeContentLoaded: combinedInjectedJSBefore,
|
|
298
|
-
injectedJavaScript: combinedInjectedJS,
|
|
299
|
-
onMessage: handleMessage,
|
|
300
|
-
onNavigationStateChange: handleNavigationStateChange,
|
|
301
|
-
});
|
|
208
|
+
} catch (err) {}
|
|
209
|
+
} else if (sendHtmlRetries < 50) {
|
|
210
|
+
sendHtmlRetries++;
|
|
211
|
+
setTimeout(window.__webview_send_html__, 100);
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
var debounceTimeout = null;
|
|
216
|
+
window.__webview_debounced_send_html__ = function() {
|
|
217
|
+
if (debounceTimeout) {
|
|
218
|
+
clearTimeout(debounceTimeout);
|
|
219
|
+
}
|
|
220
|
+
debounceTimeout = setTimeout(window.__webview_send_html__, 500);
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
// Setup MutationObserver for SPAs
|
|
224
|
+
try {
|
|
225
|
+
var observer = new MutationObserver(function() {
|
|
226
|
+
window.__webview_debounced_send_html__();
|
|
302
227
|
});
|
|
303
|
-
|
|
228
|
+
observer.observe(document.documentElement, {
|
|
229
|
+
attributes: true,
|
|
230
|
+
childList: true,
|
|
231
|
+
subtree: true
|
|
232
|
+
});
|
|
233
|
+
} catch (e) {}
|
|
234
|
+
|
|
235
|
+
// Setup SPA router state changes
|
|
236
|
+
try {
|
|
237
|
+
var originalPushState = history.pushState;
|
|
238
|
+
history.pushState = function() {
|
|
239
|
+
originalPushState.apply(this, arguments);
|
|
240
|
+
window.__webview_debounced_send_html__();
|
|
241
|
+
};
|
|
242
|
+
var originalReplaceState = history.replaceState;
|
|
243
|
+
history.replaceState = function() {
|
|
244
|
+
originalReplaceState.apply(this, arguments);
|
|
245
|
+
window.__webview_debounced_send_html__();
|
|
246
|
+
};
|
|
247
|
+
window.addEventListener('popstate', window.__webview_debounced_send_html__);
|
|
248
|
+
window.addEventListener('hashchange', window.__webview_debounced_send_html__);
|
|
249
|
+
} catch (e) {}
|
|
250
|
+
|
|
251
|
+
window.addEventListener('DOMContentLoaded', window.__webview_send_html__);
|
|
252
|
+
window.addEventListener('load', window.__webview_send_html__);
|
|
253
|
+
if (document.readyState === 'interactive' || document.readyState === 'complete') {
|
|
254
|
+
window.__webview_send_html__();
|
|
255
|
+
}
|
|
256
|
+
} else {
|
|
257
|
+
if (window.__webview_send_html__) {
|
|
258
|
+
window.__webview_send_html__();
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
})();
|
|
262
|
+
true;
|
|
263
|
+
`;
|
|
264
|
+
exports.WebView = (0, react_1.forwardRef)((props, ref) => {
|
|
265
|
+
if (!OriginalWebView) {
|
|
266
|
+
console.warn('[NetworkInspector] react-native-webview not found. Make sure it is installed.');
|
|
267
|
+
return null;
|
|
268
|
+
}
|
|
269
|
+
const [loading, setLoading] = (0, react_1.useState)(false);
|
|
270
|
+
const handleMessage = (event) => {
|
|
271
|
+
try {
|
|
272
|
+
const data = JSON.parse(event.nativeEvent.data);
|
|
273
|
+
if (data.type === 'webview-log') {
|
|
274
|
+
(0, exports.addWebViewLog)(data.logType, data.message);
|
|
275
|
+
}
|
|
276
|
+
else if (data.type === 'webview-html') {
|
|
277
|
+
(0, exports.addWebViewHtml)(data.url, data.html, data.css, data.js);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
catch (e) { }
|
|
281
|
+
if (props.onMessage) {
|
|
282
|
+
props.onMessage(event);
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
const handleNavigationStateChange = (navState) => {
|
|
286
|
+
(0, exports.addWebViewNav)(navState.url, navState.title);
|
|
287
|
+
if (props.onNavigationStateChange) {
|
|
288
|
+
props.onNavigationStateChange(navState);
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
const handleLoadStart = (syntheticEvent) => {
|
|
292
|
+
setLoading(true);
|
|
293
|
+
if (props.onLoadStart) {
|
|
294
|
+
props.onLoadStart(syntheticEvent);
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
const handleLoadEnd = (syntheticEvent) => {
|
|
298
|
+
setLoading(false);
|
|
299
|
+
if (props.onLoadEnd) {
|
|
300
|
+
props.onLoadEnd(syntheticEvent);
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
// Register initial URL
|
|
304
|
+
react_1.default.useEffect(() => {
|
|
305
|
+
if (props.source && props.source.uri) {
|
|
306
|
+
(0, exports.addWebViewNav)(props.source.uri, 'Initial Page');
|
|
307
|
+
}
|
|
308
|
+
}, [props.source?.uri]);
|
|
309
|
+
const combinedInjectedJSBefore = props.injectedJavaScriptBeforeContentLoaded
|
|
310
|
+
? `${injectJS}\n${props.injectedJavaScriptBeforeContentLoaded}`
|
|
311
|
+
: injectJS;
|
|
312
|
+
const combinedInjectedJS = props.injectedJavaScript
|
|
313
|
+
? `${injectJS}\n${props.injectedJavaScript}`
|
|
314
|
+
: injectJS;
|
|
315
|
+
const showLoader = props.showLoader !== false;
|
|
316
|
+
return react_1.default.createElement(react_native_1.View, { style: props.style || { flex: 1 } }, react_1.default.createElement(OriginalWebView, {
|
|
317
|
+
...props,
|
|
318
|
+
style: { flex: 1 },
|
|
319
|
+
ref: ref,
|
|
320
|
+
injectedJavaScriptBeforeContentLoaded: combinedInjectedJSBefore,
|
|
321
|
+
injectedJavaScript: combinedInjectedJS,
|
|
322
|
+
onMessage: handleMessage,
|
|
323
|
+
onNavigationStateChange: handleNavigationStateChange,
|
|
324
|
+
onLoadStart: handleLoadStart,
|
|
325
|
+
onLoadEnd: handleLoadEnd,
|
|
326
|
+
}), loading && showLoader && react_1.default.createElement(react_native_1.View, {
|
|
327
|
+
style: {
|
|
328
|
+
...react_native_1.StyleSheet.absoluteFill,
|
|
329
|
+
justifyContent: 'center',
|
|
330
|
+
alignItems: 'center',
|
|
331
|
+
backgroundColor: 'rgba(255, 255, 255, 0.4)',
|
|
332
|
+
},
|
|
333
|
+
}, react_1.default.createElement(react_native_1.ActivityIndicator, { size: 'large', color: '#684B9B' })));
|
|
334
|
+
});
|
|
335
|
+
// Perform monkey-patching to intercept react-native-webview exports globally
|
|
336
|
+
try {
|
|
337
|
+
const RNWebView = require('react-native-webview');
|
|
338
|
+
if (RNWebView) {
|
|
304
339
|
const defineProp = (obj, prop, value) => {
|
|
305
340
|
try {
|
|
306
341
|
Object.defineProperty(obj, prop, {
|
|
@@ -318,18 +353,18 @@ try {
|
|
|
318
353
|
}
|
|
319
354
|
};
|
|
320
355
|
if (RNWebView.WebView) {
|
|
321
|
-
defineProp(RNWebView, 'WebView',
|
|
356
|
+
defineProp(RNWebView, 'WebView', exports.WebView);
|
|
322
357
|
}
|
|
323
358
|
if (RNWebView.default) {
|
|
324
359
|
if (RNWebView.default.WebView) {
|
|
325
|
-
defineProp(RNWebView.default, 'WebView',
|
|
360
|
+
defineProp(RNWebView.default, 'WebView', exports.WebView);
|
|
326
361
|
}
|
|
327
|
-
defineProp(RNWebView, 'default',
|
|
362
|
+
defineProp(RNWebView, 'default', exports.WebView);
|
|
328
363
|
}
|
|
329
364
|
}
|
|
330
365
|
}
|
|
331
366
|
catch (e) {
|
|
332
|
-
// Silent fail
|
|
367
|
+
// Silent fail
|
|
333
368
|
}
|
|
334
369
|
let logs = [];
|
|
335
370
|
let navHistory = [];
|
|
@@ -369,7 +404,7 @@ const addWebViewNav = (url, title) => {
|
|
|
369
404
|
title,
|
|
370
405
|
timestamp: Date.now(),
|
|
371
406
|
});
|
|
372
|
-
navHistory = navHistory.slice(0,
|
|
407
|
+
navHistory = navHistory.slice(0, 5);
|
|
373
408
|
notify();
|
|
374
409
|
};
|
|
375
410
|
exports.addWebViewNav = addWebViewNav;
|
|
@@ -61,7 +61,8 @@ const getSize = (data) => {
|
|
|
61
61
|
};
|
|
62
62
|
exports.getSize = getSize;
|
|
63
63
|
const copyToClipboard = (value, label) => {
|
|
64
|
-
const
|
|
64
|
+
const resolved = typeof value === 'function' ? value() : value;
|
|
65
|
+
const text = typeof resolved === 'string' ? resolved : JSON.stringify(resolved, null, 2);
|
|
65
66
|
react_native_1.Clipboard.setString(text ?? '');
|
|
66
67
|
if (react_native_1.Platform.OS === 'android') {
|
|
67
68
|
react_native_1.ToastAndroid.show(`${label} copied`, react_native_1.ToastAndroid.SHORT);
|
package/dist/commonjs/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';
|