@datadog/mobile-react-native-webview 2.4.4 → 2.6.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/DatadogSDKReactNativeWebView.podspec +46 -0
- package/android/build.gradle +249 -0
- package/android/detekt.yml +572 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +11 -0
- package/android/src/newarch/com/datadog/reactnative/webview/DdSdkReactNativeWebViewPackage.kt +35 -0
- package/android/src/oldarch/com/datadog/reactnative/webview/DdSdkReactNativeWebViewManager.kt +112 -0
- package/android/src/oldarch/com/datadog/reactnative/webview/DdSdkReactNativeWebViewPackage.kt +36 -0
- package/android/src/test/kotlin/com/datadog/reactnative/tools/unit/GenericAssert.kt +18 -0
- package/android/src/test/kotlin/com/datadog/reactnative/webview/DatadogWebViewTest.kt +126 -0
- package/android/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +1 -0
- package/ios/DatadogSDKReactNativeWebView.xcodeproj/project.pbxproj +272 -0
- package/ios/DatadogSDKReactNativeWebView.xcodeproj/project.xcworkspace/contents.xcworkspacedata +4 -0
- package/ios/Sources/DatadogSDKReactNativeWebView.h +12 -0
- package/ios/Sources/RCTDatadogWebView.h +21 -0
- package/ios/Sources/RCTDatadogWebView.mm +53 -0
- package/ios/Sources/RCTDatadogWebViewManager.h +10 -0
- package/ios/Sources/RCTDatadogWebViewManager.mm +84 -0
- package/ios/Sources/RCTDatadogWebViewTracking.swift +67 -0
- package/lib/commonjs/ext-specs/NativeDdLogs.js +19 -0
- package/lib/commonjs/ext-specs/NativeDdLogs.js.map +1 -0
- package/lib/commonjs/ext-specs/NativeDdSdk.js.map +1 -0
- package/lib/commonjs/index.js +40 -7
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/specs/NativeDdWebView.js +16 -0
- package/lib/commonjs/specs/NativeDdWebView.js.map +1 -0
- package/lib/commonjs/utils/env-utils.js +17 -0
- package/lib/commonjs/utils/env-utils.js.map +1 -0
- package/lib/commonjs/utils/webview-js-utils.js +124 -0
- package/lib/commonjs/utils/webview-js-utils.js.map +1 -0
- package/lib/module/ext-specs/NativeDdLogs.js +17 -0
- package/lib/module/ext-specs/NativeDdLogs.js.map +1 -0
- package/lib/module/ext-specs/NativeDdSdk.js.map +1 -0
- package/lib/module/index.js +39 -7
- package/lib/module/index.js.map +1 -1
- package/lib/module/specs/NativeDdWebView.js +11 -0
- package/lib/module/specs/NativeDdWebView.js.map +1 -0
- package/lib/module/utils/env-utils.js +10 -0
- package/lib/module/utils/env-utils.js.map +1 -0
- package/lib/module/utils/webview-js-utils.js +115 -0
- package/lib/module/utils/webview-js-utils.js.map +1 -0
- package/lib/typescript/ext-specs/NativeDdLogs.d.ts +16 -0
- package/lib/typescript/ext-specs/NativeDdLogs.d.ts.map +1 -0
- package/lib/typescript/ext-specs/NativeDdSdk.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +20 -0
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/specs/NativeDdWebView.d.ts +4 -0
- package/lib/typescript/specs/NativeDdWebView.d.ts.map +1 -0
- package/lib/typescript/utils/env-utils.d.ts +2 -0
- package/lib/typescript/utils/env-utils.d.ts.map +1 -0
- package/lib/typescript/utils/webview-js-utils.d.ts +34 -0
- package/lib/typescript/utils/webview-js-utils.d.ts.map +1 -0
- package/package.json +22 -4
- package/src/__tests__/WebviewDatadog.test.tsx +39 -43
- package/src/__tests__/WebviewDatadogInjectedJS.test.tsx +200 -1
- package/src/__tests__/WebviewDatadogPerformance.test.tsx +12 -0
- package/src/__tests__/__utils__/string-utils.ts +13 -0
- package/src/__tests__/webview-js-utils.test.ts +51 -0
- package/src/ext-specs/NativeDdLogs.ts +25 -0
- package/src/{NativeDdSdk.ts → ext-specs/NativeDdSdk.ts} +1 -0
- package/src/index.tsx +70 -13
- package/src/specs/NativeDdWebView.ts +16 -0
- package/src/utils/env-utils.ts +9 -0
- package/src/utils/webview-js-utils.ts +150 -0
- package/lib/commonjs/NativeDdSdk.js.map +0 -1
- package/lib/commonjs/__utils__/formatAllowedHosts.js +0 -65
- package/lib/commonjs/__utils__/formatAllowedHosts.js.map +0 -1
- package/lib/commonjs/__utils__/getInjectedJavaScriptBeforeContentLoaded.js +0 -32
- package/lib/commonjs/__utils__/getInjectedJavaScriptBeforeContentLoaded.js.map +0 -1
- package/lib/module/NativeDdSdk.js.map +0 -1
- package/lib/module/__utils__/formatAllowedHosts.js +0 -58
- package/lib/module/__utils__/formatAllowedHosts.js.map +0 -1
- package/lib/module/__utils__/getInjectedJavaScriptBeforeContentLoaded.js +0 -24
- package/lib/module/__utils__/getInjectedJavaScriptBeforeContentLoaded.js.map +0 -1
- package/lib/typescript/NativeDdSdk.d.ts.map +0 -1
- package/lib/typescript/__utils__/formatAllowedHosts.d.ts +0 -2
- package/lib/typescript/__utils__/formatAllowedHosts.d.ts.map +0 -1
- package/lib/typescript/__utils__/getInjectedJavaScriptBeforeContentLoaded.d.ts +0 -3
- package/lib/typescript/__utils__/getInjectedJavaScriptBeforeContentLoaded.d.ts.map +0 -1
- package/src/__tests__/formatAllowedHosts.test.ts +0 -40
- package/src/__tests__/getInjectedJavaScriptBeforeContentLoaded.test.ts +0 -86
- package/src/__utils__/formatAllowedHosts.ts +0 -70
- package/src/__utils__/getInjectedJavaScriptBeforeContentLoaded.ts +0 -29
- /package/lib/commonjs/{NativeDdSdk.js → ext-specs/NativeDdSdk.js} +0 -0
- /package/lib/module/{NativeDdSdk.js → ext-specs/NativeDdSdk.js} +0 -0
- /package/lib/typescript/{NativeDdSdk.d.ts → ext-specs/NativeDdSdk.d.ts} +0 -0
|
@@ -1,86 +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
|
-
/* eslint-disable no-eval */
|
|
7
|
-
import {
|
|
8
|
-
getInjectedJavaScriptBeforeContentLoaded,
|
|
9
|
-
DATADOG_MESSAGE_PREFIX
|
|
10
|
-
} from '../__utils__/getInjectedJavaScriptBeforeContentLoaded';
|
|
11
|
-
|
|
12
|
-
describe('getInjectedJavaScriptBeforeContentLoaded', () => {
|
|
13
|
-
const DdMessage = 'custom datadog event';
|
|
14
|
-
let allowedHosts: string[];
|
|
15
|
-
let script: string;
|
|
16
|
-
beforeEach(() => {
|
|
17
|
-
jest.clearAllMocks();
|
|
18
|
-
Object.defineProperty(window, 'ReactNativeWebView', {
|
|
19
|
-
value: {
|
|
20
|
-
postMessage: jest.fn()
|
|
21
|
-
},
|
|
22
|
-
writable: true
|
|
23
|
-
});
|
|
24
|
-
delete (window as any).DatadogEventBridge;
|
|
25
|
-
});
|
|
26
|
-
it('posts the message and returns allowed webview hosts', () => {
|
|
27
|
-
allowedHosts = ['example.com', 'localhost'];
|
|
28
|
-
script = getInjectedJavaScriptBeforeContentLoaded(allowedHosts);
|
|
29
|
-
eval(script);
|
|
30
|
-
|
|
31
|
-
// Posting the message
|
|
32
|
-
(window as any).DatadogEventBridge.send(DdMessage);
|
|
33
|
-
expect((window as any).ReactNativeWebView.postMessage).toBeCalledWith(
|
|
34
|
-
`${DATADOG_MESSAGE_PREFIX} ${DdMessage}`
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
// Getting the allowed hosts
|
|
38
|
-
expect(
|
|
39
|
-
(window as any).DatadogEventBridge.getAllowedWebViewHosts()
|
|
40
|
-
).toBe('["example.com","localhost"]');
|
|
41
|
-
});
|
|
42
|
-
it('should return an empty array for getAllowedWebViewHosts if no hosts are given', () => {
|
|
43
|
-
allowedHosts = [];
|
|
44
|
-
script = getInjectedJavaScriptBeforeContentLoaded(allowedHosts);
|
|
45
|
-
eval(script);
|
|
46
|
-
|
|
47
|
-
expect(
|
|
48
|
-
(window as any).DatadogEventBridge.getAllowedWebViewHosts()
|
|
49
|
-
).toBe('[]');
|
|
50
|
-
});
|
|
51
|
-
it('uses our injected javascript and the user provided implementation', () => {
|
|
52
|
-
allowedHosts = ['example.com', 'localhost'];
|
|
53
|
-
const callfunction = jest.fn();
|
|
54
|
-
const injectedJavaScriptBeforeContentLoaded = 'callfunction()';
|
|
55
|
-
script = getInjectedJavaScriptBeforeContentLoaded(
|
|
56
|
-
allowedHosts,
|
|
57
|
-
injectedJavaScriptBeforeContentLoaded
|
|
58
|
-
);
|
|
59
|
-
eval(script);
|
|
60
|
-
expect(callfunction).toHaveBeenCalled();
|
|
61
|
-
// Posting the message
|
|
62
|
-
(window as any).DatadogEventBridge.send(DdMessage);
|
|
63
|
-
expect((window as any).ReactNativeWebView.postMessage).toBeCalledWith(
|
|
64
|
-
`${DATADOG_MESSAGE_PREFIX} ${DdMessage}`
|
|
65
|
-
);
|
|
66
|
-
});
|
|
67
|
-
it('executes our injected javascript when the user provided implementation throws an error', () => {
|
|
68
|
-
allowedHosts = ['example.com', 'localhost'];
|
|
69
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
70
|
-
const callfunction = jest.fn().mockImplementation(() => {
|
|
71
|
-
throw new Error('The user functions throws an error');
|
|
72
|
-
});
|
|
73
|
-
const injectedJavaScriptBeforeContentLoaded = 'callfunction()';
|
|
74
|
-
script = getInjectedJavaScriptBeforeContentLoaded(
|
|
75
|
-
allowedHosts,
|
|
76
|
-
injectedJavaScriptBeforeContentLoaded
|
|
77
|
-
);
|
|
78
|
-
eval(script);
|
|
79
|
-
expect(() => eval(injectedJavaScriptBeforeContentLoaded)).toThrow();
|
|
80
|
-
// Posting the message
|
|
81
|
-
(window as any).DatadogEventBridge.send(DdMessage);
|
|
82
|
-
expect((window as any).ReactNativeWebView.postMessage).toBeCalledWith(
|
|
83
|
-
`${DATADOG_MESSAGE_PREFIX} ${DdMessage}`
|
|
84
|
-
);
|
|
85
|
-
});
|
|
86
|
-
});
|
|
@@ -1,70 +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
|
-
import { NativeDdSdk } from '../NativeDdSdk';
|
|
7
|
-
|
|
8
|
-
export function formatAllowedHosts(allowedHosts?: string[]): string {
|
|
9
|
-
try {
|
|
10
|
-
return `'${JSON.stringify(allowedHosts)}'`;
|
|
11
|
-
} catch (e: any) {
|
|
12
|
-
if (NativeDdSdk) {
|
|
13
|
-
NativeDdSdk.telemetryError(
|
|
14
|
-
getErrorMessage(e),
|
|
15
|
-
getErrorStackTrace(e),
|
|
16
|
-
'AllowedHostsError'
|
|
17
|
-
);
|
|
18
|
-
}
|
|
19
|
-
return "'[]'";
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* The next section is copied from packages/core/src/errorUtils
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
const EMPTY_MESSAGE = 'Unknown Error';
|
|
28
|
-
const EMPTY_STACK_TRACE = '';
|
|
29
|
-
|
|
30
|
-
const getErrorMessage = (error: any | undefined): string => {
|
|
31
|
-
let message = EMPTY_MESSAGE;
|
|
32
|
-
if (error === undefined || error === null) {
|
|
33
|
-
message = EMPTY_MESSAGE;
|
|
34
|
-
} else if (typeof error === 'object' && 'message' in error) {
|
|
35
|
-
message = String(error.message);
|
|
36
|
-
} else {
|
|
37
|
-
message = String(error);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return message;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
const getErrorStackTrace = (error: any | undefined): string => {
|
|
44
|
-
let stack = EMPTY_STACK_TRACE;
|
|
45
|
-
|
|
46
|
-
try {
|
|
47
|
-
if (error === undefined || error === null) {
|
|
48
|
-
stack = EMPTY_STACK_TRACE;
|
|
49
|
-
} else if (typeof error === 'string') {
|
|
50
|
-
stack = EMPTY_STACK_TRACE;
|
|
51
|
-
} else if (typeof error === 'object') {
|
|
52
|
-
if ('stacktrace' in error) {
|
|
53
|
-
stack = String(error.stacktrace);
|
|
54
|
-
} else if ('stack' in error) {
|
|
55
|
-
stack = String(error.stack);
|
|
56
|
-
} else if ('componentStack' in error) {
|
|
57
|
-
stack = String(error.componentStack);
|
|
58
|
-
} else if (
|
|
59
|
-
'sourceURL' in error &&
|
|
60
|
-
'line' in error &&
|
|
61
|
-
'column' in error
|
|
62
|
-
) {
|
|
63
|
-
stack = `at ${error.sourceURL}:${error.line}:${error.column}`;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
} catch (e) {
|
|
67
|
-
// Do nothing
|
|
68
|
-
}
|
|
69
|
-
return stack;
|
|
70
|
-
};
|
|
@@ -1,29 +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
|
-
import { formatAllowedHosts } from './formatAllowedHosts';
|
|
7
|
-
|
|
8
|
-
export const DATADOG_MESSAGE_PREFIX = '[DATADOG]';
|
|
9
|
-
|
|
10
|
-
export const getInjectedJavaScriptBeforeContentLoaded = (
|
|
11
|
-
allowedHosts?: string[],
|
|
12
|
-
injectedJavaScriptBeforeContentLoaded?: string
|
|
13
|
-
): string =>
|
|
14
|
-
`
|
|
15
|
-
window.DatadogEventBridge = {
|
|
16
|
-
send(msg) {
|
|
17
|
-
window.ReactNativeWebView.postMessage("${DATADOG_MESSAGE_PREFIX} " + msg)
|
|
18
|
-
},
|
|
19
|
-
getAllowedWebViewHosts() {
|
|
20
|
-
return ${formatAllowedHosts(allowedHosts)}
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
try{
|
|
24
|
-
${injectedJavaScriptBeforeContentLoaded}
|
|
25
|
-
}
|
|
26
|
-
catch (error) {
|
|
27
|
-
// The user defined code has crashed
|
|
28
|
-
}
|
|
29
|
-
`;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|