@datadog/mobile-react-native-webview 2.13.2 → 2.14.0
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/android/build.gradle +8 -1
- package/android/src/newarch/com/datadog/reactnative/webview/DdSdkReactNativeWebViewManager.kt +125 -0
- package/android/src/newarch/com/datadog/reactnative/webview/DdSdkReactNativeWebViewPackage.kt +4 -4
- package/android/src/oldarch/com/datadog/reactnative/webview/DdSdkReactNativeWebViewManager.kt +5 -19
- package/android/src/test/kotlin/{com → main/com}/datadog/reactnative/tools/unit/GenericAssert.kt +1 -1
- package/android/src/test/{kotlin/com/datadog/reactnative/webview → webview}/DatadogWebViewTest.kt +2 -7
- package/android/src/testNewArch/kotlin/com/datadog/reactnative/webview/DatadogWebViewTest.kt +122 -0
- package/lib/commonjs/index.js +8 -10
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/specs/NativeDdWebView.js +1 -2
- package/lib/commonjs/specs/NativeDdWebView.js.map +1 -1
- package/lib/commonjs/utils/webview-js-utils.js +37 -53
- package/lib/commonjs/utils/webview-js-utils.js.map +1 -1
- package/lib/module/index.js +10 -12
- package/lib/module/index.js.map +1 -1
- package/lib/module/specs/NativeDdWebView.js +1 -2
- package/lib/module/specs/NativeDdWebView.js.map +1 -1
- package/lib/module/utils/webview-js-utils.js +34 -50
- package/lib/module/utils/webview-js-utils.js.map +1 -1
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/specs/NativeDdWebView.d.ts +1 -1
- package/lib/typescript/specs/NativeDdWebView.d.ts.map +1 -1
- package/lib/typescript/utils/webview-js-utils.d.ts +4 -9
- package/lib/typescript/utils/webview-js-utils.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/WebviewDatadogInjectedJS.test.tsx +27 -61
- package/src/__tests__/webview-js-utils.test.ts +151 -6
- package/src/index.tsx +17 -20
- package/src/specs/NativeDdWebView.ts +3 -5
- package/src/utils/webview-js-utils.ts +49 -57
- package/lib/commonjs/utils/env-utils.js +0 -17
- package/lib/commonjs/utils/env-utils.js.map +0 -1
- package/lib/module/utils/env-utils.js +0 -10
- package/lib/module/utils/env-utils.js.map +0 -1
- package/lib/typescript/utils/env-utils.d.ts +0 -2
- package/lib/typescript/utils/env-utils.d.ts.map +0 -1
- package/src/utils/env-utils.ts +0 -9
|
@@ -29,70 +29,59 @@ export type DatadogMessageFormat = {
|
|
|
29
29
|
};
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
|
-
* Wraps the given JS Code in a try and catch block
|
|
32
|
+
* Wraps the given JS Code in a try and catch block, including a
|
|
33
|
+
* comment with the given allowedHosts in JSON format
|
|
33
34
|
* @param javascriptCode The JS Code to wrap in a try and catch block.
|
|
34
35
|
* @returns the wrapped JS code.
|
|
35
36
|
*/
|
|
36
|
-
export
|
|
37
|
-
javascriptCode?: string
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
37
|
+
export function wrapJsCodeWithAllowedHosts(
|
|
38
|
+
javascriptCode?: string,
|
|
39
|
+
allowedHosts?: string[]
|
|
40
|
+
): string | undefined {
|
|
41
|
+
let jsCode = '';
|
|
42
|
+
const hosts = formatAllowedHosts(allowedHosts);
|
|
43
|
+
if (hosts) {
|
|
44
|
+
jsCode = `// #allowedHosts=${JSON.stringify(allowedHosts)}\n`;
|
|
43
45
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
message: errorMsg
|
|
50
|
-
}));
|
|
51
|
-
true;
|
|
52
|
-
}`
|
|
46
|
+
|
|
47
|
+
return javascriptCode
|
|
48
|
+
? `${jsCode}\n${wrapJsCodeInTryAndCatch(javascriptCode)}`
|
|
49
|
+
: jsCode.trim().length > 0
|
|
50
|
+
? jsCode
|
|
53
51
|
: undefined;
|
|
52
|
+
}
|
|
54
53
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
true;
|
|
74
|
-
},
|
|
75
|
-
getAllowedWebViewHosts() {
|
|
76
|
-
return ${formatAllowedHosts(allowedHosts)}
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
try{
|
|
80
|
-
${customJavaScriptCode}
|
|
81
|
-
}
|
|
82
|
-
catch (error) {
|
|
83
|
-
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
84
|
-
window.ReactNativeWebView.postMessage(JSON.stringify({
|
|
85
|
-
source: 'DATADOG',
|
|
86
|
-
type: 'ERROR',
|
|
87
|
-
message: errorMsg
|
|
88
|
-
}));
|
|
89
|
-
true;
|
|
90
|
-
}
|
|
91
|
-
`;
|
|
54
|
+
export function wrapJsCodeInTryAndCatch(
|
|
55
|
+
javascriptCode: string | undefined
|
|
56
|
+
): string | undefined {
|
|
57
|
+
return javascriptCode
|
|
58
|
+
? `try{
|
|
59
|
+
${javascriptCode}
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
63
|
+
window.ReactNativeWebView.postMessage(JSON.stringify({
|
|
64
|
+
source: 'DATADOG',
|
|
65
|
+
type: 'ERROR',
|
|
66
|
+
message: errorMsg
|
|
67
|
+
}));
|
|
68
|
+
true;
|
|
69
|
+
}`
|
|
70
|
+
: undefined;
|
|
71
|
+
}
|
|
92
72
|
|
|
93
|
-
function formatAllowedHosts(allowedHosts?: string[]): string {
|
|
73
|
+
function formatAllowedHosts(allowedHosts?: string[]): string | undefined {
|
|
94
74
|
try {
|
|
95
|
-
|
|
75
|
+
if (!allowedHosts) {
|
|
76
|
+
throw new Error('allowedHosts is undefined');
|
|
77
|
+
}
|
|
78
|
+
const jsonHosts = JSON.stringify(allowedHosts);
|
|
79
|
+
if (!jsonHosts) {
|
|
80
|
+
throw new Error(
|
|
81
|
+
"JSON.stringify returned 'undefined' for the given hosts"
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
return jsonHosts;
|
|
96
85
|
} catch (e: any) {
|
|
97
86
|
if (NativeDdSdk) {
|
|
98
87
|
NativeDdSdk.telemetryError(
|
|
@@ -101,7 +90,10 @@ function formatAllowedHosts(allowedHosts?: string[]): string {
|
|
|
101
90
|
'AllowedHostsError'
|
|
102
91
|
);
|
|
103
92
|
}
|
|
104
|
-
|
|
93
|
+
console.warn(
|
|
94
|
+
`[@datadog/mobile-react-native-webview] Invalid 'allowedHosts' format: ${e}`
|
|
95
|
+
);
|
|
96
|
+
return undefined;
|
|
105
97
|
}
|
|
106
98
|
}
|
|
107
99
|
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.isNewArchitecture = void 0;
|
|
7
|
-
/*
|
|
8
|
-
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
9
|
-
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
10
|
-
* Copyright 2016-Present Datadog, Inc.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
const isNewArchitecture = () => {
|
|
14
|
-
return global?.nativeFabricUIManager !== undefined;
|
|
15
|
-
};
|
|
16
|
-
exports.isNewArchitecture = isNewArchitecture;
|
|
17
|
-
//# sourceMappingURL=env-utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["isNewArchitecture","global","nativeFabricUIManager","undefined","exports"],"sourceRoot":"../../../src","sources":["utils/env-utils.ts"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;;AAEO,MAAMA,iBAAiB,GAAGA,CAAA,KAAe;EAC5C,OAAQC,MAAM,EAAUC,qBAAqB,KAAKC,SAAS;AAC/D,CAAC;AAACC,OAAA,CAAAJ,iBAAA,GAAAA,iBAAA","ignoreList":[]}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
3
|
-
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
4
|
-
* Copyright 2016-Present Datadog, Inc.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
export const isNewArchitecture = () => {
|
|
8
|
-
return global?.nativeFabricUIManager !== undefined;
|
|
9
|
-
};
|
|
10
|
-
//# sourceMappingURL=env-utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["isNewArchitecture","global","nativeFabricUIManager","undefined"],"sourceRoot":"../../../src","sources":["utils/env-utils.ts"],"mappings":"AAAA;AACA;AACA;AACA;AACA;;AAEA,OAAO,MAAMA,iBAAiB,GAAGA,CAAA,KAAe;EAC5C,OAAQC,MAAM,EAAUC,qBAAqB,KAAKC,SAAS;AAC/D,CAAC","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"env-utils.d.ts","sourceRoot":"","sources":["../../../src/utils/env-utils.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,iBAAiB,QAAO,OAEpC,CAAC"}
|
package/src/utils/env-utils.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
3
|
-
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
4
|
-
* Copyright 2016-Present Datadog, Inc.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
export const isNewArchitecture = (): boolean => {
|
|
8
|
-
return (global as any)?.nativeFabricUIManager !== undefined;
|
|
9
|
-
};
|