@webview-bridge/react-native 1.7.6 → 1.7.7
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/dist/index.cjs +9 -7
- package/dist/index.js +5 -3
- package/package.json +3 -3
- package/src/integrations/console.ts +10 -0
package/dist/index.cjs
CHANGED
|
@@ -435,7 +435,7 @@ __export(index_exports, {
|
|
|
435
435
|
});
|
|
436
436
|
module.exports = __toCommonJS(index_exports);
|
|
437
437
|
// src/createWebView.tsx
|
|
438
|
-
var
|
|
438
|
+
var import_utils4 = require("@webview-bridge/utils");
|
|
439
439
|
var import_react = require("react");
|
|
440
440
|
var import_react_native_webview = __toESM(require("react-native-webview"), 1);
|
|
441
441
|
// src/integrations/bridge.ts
|
|
@@ -571,7 +571,9 @@ var SAFE_NATIVE_EMITTER_THROW_BY_BRIDGE_ID = function(bridgeId, eventName) {
|
|
|
571
571
|
return "\nif (window.nativeEmitterMap && window.nativeEmitterMap['".concat(bridgeId, "']) {\n window.nativeEmitterMap['").concat(bridgeId, "'].emit('").concat(eventName, "', {}, true);\n} else if (window.nativeEmitter) {\n // @deprecated This version is not used after 1.7.2\n window.nativeEmitter.emit('").concat(eventName, "', {}, true);\n} else {\n window.nativeBatchedEvents = window.nativeBatchedEvents || [];\n window.nativeBatchedEvents.push(['").concat(eventName, "', {}, true]);\n}\ntrue;\n");
|
|
572
572
|
};
|
|
573
573
|
// src/integrations/console.ts
|
|
574
|
-
var
|
|
574
|
+
var import_utils2 = require("@webview-bridge/utils");
|
|
575
|
+
var injectionDetectKey = "__bridge_debug_injected_".concat((0, import_utils2.createRandomId)());
|
|
576
|
+
var INJECT_DEBUG = '\n{\n if (window["'.concat(injectionDetectKey, '"]) {\n return;\n }\n\n window["').concat(injectionDetectKey, '"] = true;\n const originalConsoleLog = console.log;\n const originalConsoleError = console.error;\n const originalConsoleWarn = console.warn;\n\n console.log = function() {\n var message = JSON.stringify(Array.from(arguments));\n window.ReactNativeWebView?.postMessage(\n JSON.stringify({ type: "log", body: { method: "log", args: message } }),\n );\n originalConsoleLog.apply(console, arguments);\n };\n\n console.error = function() {\n var message = JSON.stringify(Array.from(arguments));\n window.ReactNativeWebView?.postMessage(\n JSON.stringify({ type: "log", body: { method: "error", args: message } }),\n );\n originalConsoleError.apply(console, arguments);\n };\n\n console.warn = function() {\n var message = JSON.stringify(Array.from(arguments));\n window.ReactNativeWebView?.postMessage(\n JSON.stringify({ type: "log", body: { method: "warn", args: message } }),\n );\n originalConsoleWarn.apply(console, arguments);\n };\n};\n');
|
|
575
577
|
var handleLog = function(type, message) {
|
|
576
578
|
var _JSON_parse = _to_array(JSON.parse(message)), formatMessage = _JSON_parse[0], parsedMessage = _JSON_parse.slice(1);
|
|
577
579
|
var webviewMark = "(WebView) ";
|
|
@@ -603,7 +605,7 @@ var handleLog = function(type, message) {
|
|
|
603
605
|
}
|
|
604
606
|
};
|
|
605
607
|
// src/integrations/handleRegisterWebMethod.ts
|
|
606
|
-
var
|
|
608
|
+
var import_utils3 = require("@webview-bridge/utils");
|
|
607
609
|
// src/error.ts
|
|
608
610
|
var WebMethodError = /*#__PURE__*/ function(Error1) {
|
|
609
611
|
_inherits(WebMethodError, Error1);
|
|
@@ -628,11 +630,11 @@ var handleRegisterWebMethod = function(emitter, webview, bridgeNames, responseTi
|
|
|
628
630
|
for(_len = _arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
629
631
|
args[_key] = _arguments[_key];
|
|
630
632
|
}
|
|
631
|
-
eventId = (0,
|
|
633
|
+
eventId = (0, import_utils3.createRandomId)();
|
|
632
634
|
return [
|
|
633
635
|
2,
|
|
634
636
|
Promise.race([
|
|
635
|
-
(0,
|
|
637
|
+
(0, import_utils3.createResolver)({
|
|
636
638
|
emitter: emitter,
|
|
637
639
|
methodName: methodName,
|
|
638
640
|
eventId: eventId,
|
|
@@ -641,7 +643,7 @@ var handleRegisterWebMethod = function(emitter, webview, bridgeNames, responseTi
|
|
|
641
643
|
},
|
|
642
644
|
failHandler: new WebMethodError(methodName)
|
|
643
645
|
}),
|
|
644
|
-
(0,
|
|
646
|
+
(0, import_utils3.timeout)(responseTimeout)
|
|
645
647
|
])
|
|
646
648
|
];
|
|
647
649
|
});
|
|
@@ -659,7 +661,7 @@ var createWebView = function(param) {
|
|
|
659
661
|
}
|
|
660
662
|
};
|
|
661
663
|
var webviewRefList = [];
|
|
662
|
-
var emitter = (0,
|
|
664
|
+
var emitter = (0, import_utils4.createEvents)();
|
|
663
665
|
bridge2.subscribe(function(state) {
|
|
664
666
|
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
665
667
|
try {
|
package/dist/index.js
CHANGED
|
@@ -477,7 +477,9 @@ var SAFE_NATIVE_EMITTER_THROW_BY_BRIDGE_ID = function(bridgeId, eventName) {
|
|
|
477
477
|
return "\nif (window.nativeEmitterMap && window.nativeEmitterMap['".concat(bridgeId, "']) {\n window.nativeEmitterMap['").concat(bridgeId, "'].emit('").concat(eventName, "', {}, true);\n} else if (window.nativeEmitter) {\n // @deprecated This version is not used after 1.7.2\n window.nativeEmitter.emit('").concat(eventName, "', {}, true);\n} else {\n window.nativeBatchedEvents = window.nativeBatchedEvents || [];\n window.nativeBatchedEvents.push(['").concat(eventName, "', {}, true]);\n}\ntrue;\n");
|
|
478
478
|
};
|
|
479
479
|
// src/integrations/console.ts
|
|
480
|
-
|
|
480
|
+
import { createRandomId } from "@webview-bridge/utils";
|
|
481
|
+
var injectionDetectKey = "__bridge_debug_injected_".concat(createRandomId());
|
|
482
|
+
var INJECT_DEBUG = '\n{\n if (window["'.concat(injectionDetectKey, '"]) {\n return;\n }\n\n window["').concat(injectionDetectKey, '"] = true;\n const originalConsoleLog = console.log;\n const originalConsoleError = console.error;\n const originalConsoleWarn = console.warn;\n\n console.log = function() {\n var message = JSON.stringify(Array.from(arguments));\n window.ReactNativeWebView?.postMessage(\n JSON.stringify({ type: "log", body: { method: "log", args: message } }),\n );\n originalConsoleLog.apply(console, arguments);\n };\n\n console.error = function() {\n var message = JSON.stringify(Array.from(arguments));\n window.ReactNativeWebView?.postMessage(\n JSON.stringify({ type: "log", body: { method: "error", args: message } }),\n );\n originalConsoleError.apply(console, arguments);\n };\n\n console.warn = function() {\n var message = JSON.stringify(Array.from(arguments));\n window.ReactNativeWebView?.postMessage(\n JSON.stringify({ type: "log", body: { method: "warn", args: message } }),\n );\n originalConsoleWarn.apply(console, arguments);\n };\n};\n');
|
|
481
483
|
var handleLog = function(type, message) {
|
|
482
484
|
var _JSON_parse = _to_array(JSON.parse(message)), formatMessage = _JSON_parse[0], parsedMessage = _JSON_parse.slice(1);
|
|
483
485
|
var webviewMark = "(WebView) ";
|
|
@@ -509,7 +511,7 @@ var handleLog = function(type, message) {
|
|
|
509
511
|
}
|
|
510
512
|
};
|
|
511
513
|
// src/integrations/handleRegisterWebMethod.ts
|
|
512
|
-
import { createRandomId, createResolver, timeout } from "@webview-bridge/utils";
|
|
514
|
+
import { createRandomId as createRandomId2, createResolver, timeout } from "@webview-bridge/utils";
|
|
513
515
|
// src/error.ts
|
|
514
516
|
var WebMethodError = /*#__PURE__*/ function(Error1) {
|
|
515
517
|
"use strict";
|
|
@@ -535,7 +537,7 @@ var handleRegisterWebMethod = function(emitter, webview, bridgeNames, responseTi
|
|
|
535
537
|
for(_len = _arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
536
538
|
args[_key] = _arguments[_key];
|
|
537
539
|
}
|
|
538
|
-
eventId =
|
|
540
|
+
eventId = createRandomId2();
|
|
539
541
|
return [
|
|
540
542
|
2,
|
|
541
543
|
Promise.race([
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webview-bridge/react-native",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Fully Type-Safe Integration for React Native WebView and Web",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"react-native-webview": "*"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@webview-bridge/utils": "1.7.
|
|
43
|
-
"@webview-bridge/types": "1.7.
|
|
42
|
+
"@webview-bridge/utils": "1.7.7",
|
|
43
|
+
"@webview-bridge/types": "1.7.7",
|
|
44
44
|
"use-sync-external-store": "^1.2.0"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|
|
@@ -1,5 +1,15 @@
|
|
|
1
|
+
import { createRandomId } from "@webview-bridge/utils";
|
|
2
|
+
|
|
3
|
+
// prevent name collision with other libraries
|
|
4
|
+
const injectionDetectKey = `__bridge_debug_injected_${createRandomId()}`;
|
|
5
|
+
|
|
1
6
|
export const INJECT_DEBUG = `
|
|
2
7
|
{
|
|
8
|
+
if (window["${injectionDetectKey}"]) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
window["${injectionDetectKey}"] = true;
|
|
3
13
|
const originalConsoleLog = console.log;
|
|
4
14
|
const originalConsoleError = console.error;
|
|
5
15
|
const originalConsoleWarn = console.warn;
|