@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
package/android/build.gradle
CHANGED
|
@@ -134,7 +134,13 @@ android {
|
|
|
134
134
|
}
|
|
135
135
|
|
|
136
136
|
test {
|
|
137
|
-
java.srcDir(
|
|
137
|
+
java.srcDir('src/test/kotlin')
|
|
138
|
+
|
|
139
|
+
if (isNewArchitectureEnabled()) {
|
|
140
|
+
java.srcDirs += ['src/testNewArch/kotlin']
|
|
141
|
+
} else {
|
|
142
|
+
java.srcDirs += ['src/testOldArch/kotlin']
|
|
143
|
+
}
|
|
138
144
|
}
|
|
139
145
|
}
|
|
140
146
|
|
|
@@ -208,6 +214,7 @@ dependencies {
|
|
|
208
214
|
testImplementation "com.github.xgouchet.Elmyr:jvm:1.3.1"
|
|
209
215
|
testImplementation "org.mockito.kotlin:mockito-kotlin:5.1.0"
|
|
210
216
|
testImplementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
|
|
217
|
+
testImplementation 'org.json:json:20160810'
|
|
211
218
|
|
|
212
219
|
detektPlugins "io.gitlab.arturbosch.detekt:detekt-formatting:1.23.8"
|
|
213
220
|
detektPlugins "io.gitlab.arturbosch.detekt:detekt-rules-libraries:1.23.8"
|
|
@@ -0,0 +1,125 @@
|
|
|
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
|
+
package com.datadog.reactnative.webview
|
|
8
|
+
|
|
9
|
+
import android.annotation.SuppressLint
|
|
10
|
+
import com.datadog.android.api.SdkCore
|
|
11
|
+
import com.datadog.android.webview.WebViewTracking
|
|
12
|
+
import com.datadog.reactnative.DatadogSDKWrapperStorage
|
|
13
|
+
import com.facebook.react.bridge.ReactContext
|
|
14
|
+
import com.facebook.react.uimanager.ThemedReactContext
|
|
15
|
+
import com.reactnativecommunity.webview.RNCWebView
|
|
16
|
+
import com.reactnativecommunity.webview.RNCWebViewClient
|
|
17
|
+
import com.reactnativecommunity.webview.RNCWebViewManager
|
|
18
|
+
import com.reactnativecommunity.webview.RNCWebViewWrapper
|
|
19
|
+
import org.json.JSONArray
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The entry point to use Datadog auto-instrumented WebView feature.
|
|
23
|
+
*/
|
|
24
|
+
class DdSdkReactNativeWebViewManager(
|
|
25
|
+
private val reactContext: ReactContext
|
|
26
|
+
) : RNCWebViewManager() {
|
|
27
|
+
// The name used to reference this custom View from React Native.
|
|
28
|
+
override fun getName(): String {
|
|
29
|
+
return VIEW_NAME
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The instance of Datadog SDK Core.
|
|
34
|
+
*/
|
|
35
|
+
@Volatile private var _datadogCore: SdkCore? = null
|
|
36
|
+
val datadogCore: SdkCore?
|
|
37
|
+
get() = _datadogCore
|
|
38
|
+
|
|
39
|
+
init {
|
|
40
|
+
DatadogSDKWrapperStorage.addOnInitializedListener { core ->
|
|
41
|
+
_datadogCore = core
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Intercepts the WebView wrapper instance before it is returned and ensures that
|
|
47
|
+
* JavaScript is enabled on the underlying WebView. JavaScript must be enabled
|
|
48
|
+
* for Datadog WebView tracking to function correctly.
|
|
49
|
+
*/
|
|
50
|
+
@SuppressLint("SetJavaScriptEnabled")
|
|
51
|
+
override fun createViewInstance(context: ThemedReactContext): RNCWebViewWrapper {
|
|
52
|
+
val viewInstance = super.createViewInstance(context)
|
|
53
|
+
viewInstance.webView.settings.javaScriptEnabled = true
|
|
54
|
+
return viewInstance
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Intercepts the JavaScript injected before the WebView loads.
|
|
59
|
+
*
|
|
60
|
+
* In the New Architecture, WebView props from React Native are ignored,
|
|
61
|
+
* so this callback is the only reliable place to extract the
|
|
62
|
+
* `// #allowedHosts=<JSON>` configuration and apply Datadog WebView tracking.
|
|
63
|
+
*/
|
|
64
|
+
override fun setInjectedJavaScriptBeforeContentLoaded(
|
|
65
|
+
view: RNCWebViewWrapper?,
|
|
66
|
+
value: String?
|
|
67
|
+
) {
|
|
68
|
+
val allowedHosts = value?.let { extractAllowedHosts(it) }
|
|
69
|
+
val webView = view?.webView
|
|
70
|
+
|
|
71
|
+
if (allowedHosts != null && webView != null) {
|
|
72
|
+
configureWebViewTracking(webView, allowedHosts)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
super.setInjectedJavaScriptBeforeContentLoaded(view, value)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
private fun configureWebViewTracking(webView: RNCWebView, allowedHosts: List<String>) {
|
|
79
|
+
val datadogCore = _datadogCore
|
|
80
|
+
if (datadogCore != null) {
|
|
81
|
+
WebViewTracking.enable(
|
|
82
|
+
webView,
|
|
83
|
+
allowedHosts = allowedHosts,
|
|
84
|
+
sdkCore = datadogCore
|
|
85
|
+
)
|
|
86
|
+
} else {
|
|
87
|
+
DatadogSDKWrapperStorage.addOnInitializedListener { core ->
|
|
88
|
+
reactContext.runOnUiQueueThread {
|
|
89
|
+
WebViewTracking.enable(
|
|
90
|
+
webView,
|
|
91
|
+
allowedHosts = allowedHosts,
|
|
92
|
+
sdkCore = core
|
|
93
|
+
)
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
override fun addEventEmitters(
|
|
100
|
+
reactContext: ThemedReactContext,
|
|
101
|
+
view: RNCWebViewWrapper
|
|
102
|
+
) {
|
|
103
|
+
view.webView.webViewClient = RNCWebViewClient()
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
companion object {
|
|
107
|
+
// The name used to reference this custom View from React Native.
|
|
108
|
+
const val VIEW_NAME = "DdReactNativeWebView"
|
|
109
|
+
|
|
110
|
+
private fun extractAllowedHosts(input: String): List<String>? {
|
|
111
|
+
// Regex that captures everything after "// #allowedHosts="
|
|
112
|
+
val regex = Regex("""//\s*#allowedHosts\s*=\s*(.+)""")
|
|
113
|
+
|
|
114
|
+
val match = regex.find(input) ?: return null
|
|
115
|
+
val jsonString = match.groupValues[1].trim()
|
|
116
|
+
|
|
117
|
+
return try {
|
|
118
|
+
val jsonArray = JSONArray(jsonString)
|
|
119
|
+
(0 until jsonArray.length()).map { jsonArray.getString(it) }
|
|
120
|
+
} catch (e: Exception) {
|
|
121
|
+
null
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
package/android/src/newarch/com/datadog/reactnative/webview/DdSdkReactNativeWebViewPackage.kt
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
4
4
|
* Copyright 2016-Present Datadog, Inc.
|
|
5
5
|
*/
|
|
6
|
-
|
|
7
6
|
package com.datadog.reactnative.webview
|
|
8
7
|
|
|
9
8
|
import com.facebook.react.TurboReactPackage
|
|
@@ -12,17 +11,18 @@ import com.facebook.react.bridge.ReactApplicationContext
|
|
|
12
11
|
import com.facebook.react.module.model.ReactModuleInfo
|
|
13
12
|
import com.facebook.react.module.model.ReactModuleInfoProvider
|
|
14
13
|
import com.facebook.react.uimanager.ViewManager
|
|
15
|
-
import com.reactnativecommunity.webview.
|
|
14
|
+
import com.reactnativecommunity.webview.RNCWebViewModule
|
|
15
|
+
import com.reactnativecommunity.webview.RNCWebViewModuleImpl
|
|
16
16
|
|
|
17
17
|
class DdSdkReactNativeWebViewPackage : TurboReactPackage() {
|
|
18
18
|
override fun createViewManagers(
|
|
19
19
|
reactContext: ReactApplicationContext
|
|
20
20
|
): MutableList<ViewManager<*,*>> {
|
|
21
21
|
return mutableListOf(
|
|
22
|
-
|
|
22
|
+
DdSdkReactNativeWebViewManager(reactContext)
|
|
23
23
|
)
|
|
24
24
|
}
|
|
25
|
-
|
|
25
|
+
|
|
26
26
|
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
|
|
27
27
|
return null
|
|
28
28
|
}
|
package/android/src/oldarch/com/datadog/reactnative/webview/DdSdkReactNativeWebViewManager.kt
CHANGED
|
@@ -26,10 +26,9 @@ class DdSdkReactNativeWebViewManager(
|
|
|
26
26
|
private val reactContext: ReactContext
|
|
27
27
|
) : RNCWebViewManager() {
|
|
28
28
|
// The name used to reference this custom View from React Native.
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
override fun getName(): String {
|
|
30
|
+
return VIEW_NAME
|
|
31
31
|
}
|
|
32
|
-
|
|
33
32
|
/**
|
|
34
33
|
* The instance of Datadog SDK Core.
|
|
35
34
|
*/
|
|
@@ -37,13 +36,6 @@ class DdSdkReactNativeWebViewManager(
|
|
|
37
36
|
val datadogCore: SdkCore?
|
|
38
37
|
get() = _datadogCore
|
|
39
38
|
|
|
40
|
-
/**
|
|
41
|
-
* Whether WebView tracking has been enabled or not.
|
|
42
|
-
*/
|
|
43
|
-
@Volatile private var _isWebViewTrackingEnabled: Boolean = false
|
|
44
|
-
val isWebViewTrackingEnabled: Boolean
|
|
45
|
-
get() = _isWebViewTrackingEnabled
|
|
46
|
-
|
|
47
39
|
init {
|
|
48
40
|
DatadogSDKWrapperStorage.addOnInitializedListener { core ->
|
|
49
41
|
_datadogCore = core
|
|
@@ -92,21 +84,15 @@ class DdSdkReactNativeWebViewManager(
|
|
|
92
84
|
sdkCore: SdkCore,
|
|
93
85
|
allowedHosts: List<String>
|
|
94
86
|
) {
|
|
95
|
-
if (_isWebViewTrackingEnabled) {
|
|
96
|
-
return
|
|
97
|
-
}
|
|
98
|
-
|
|
99
87
|
WebViewTracking.enable(
|
|
100
88
|
webView,
|
|
101
89
|
allowedHosts = allowedHosts,
|
|
102
90
|
sdkCore = sdkCore
|
|
103
91
|
)
|
|
104
|
-
|
|
105
|
-
_isWebViewTrackingEnabled = true
|
|
106
92
|
}
|
|
107
93
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
94
|
+
companion object {
|
|
95
|
+
// The name used to reference this custom View from React Native.
|
|
96
|
+
const val VIEW_NAME = "DdReactNativeWebView"
|
|
111
97
|
}
|
|
112
98
|
}
|
package/android/src/test/{kotlin/com/datadog/reactnative/webview → webview}/DatadogWebViewTest.kt
RENAMED
|
@@ -10,7 +10,8 @@ import com.datadog.android.api.SdkCore
|
|
|
10
10
|
import com.datadog.android.core.InternalSdkCore
|
|
11
11
|
import com.datadog.android.webview.WebViewTracking
|
|
12
12
|
import com.datadog.reactnative.DatadogSDKWrapperStorage
|
|
13
|
-
import com.datadog.reactnative.
|
|
13
|
+
import com.datadog.reactnative.webview.DdSdkReactNativeWebViewManager
|
|
14
|
+
import main.reactnative.tools.unit.GenericAssert.Companion.assertThat
|
|
14
15
|
import com.facebook.react.bridge.JavaOnlyArray
|
|
15
16
|
import com.facebook.react.uimanager.ThemedReactContext
|
|
16
17
|
import com.reactnativecommunity.webview.RNCWebView
|
|
@@ -90,9 +91,6 @@ internal class DatadogWebViewTest {
|
|
|
90
91
|
// When first initialized, the WebView manager core should be null
|
|
91
92
|
assertThat(manager.datadogCore).isNull()
|
|
92
93
|
|
|
93
|
-
// When first initialized, the WebView tracking should be disabled
|
|
94
|
-
assertThat(manager.isWebViewTrackingEnabled).isEqualTo(false)
|
|
95
|
-
|
|
96
94
|
// =========
|
|
97
95
|
// When
|
|
98
96
|
// =========
|
|
@@ -119,8 +117,5 @@ internal class DatadogWebViewTest {
|
|
|
119
117
|
webViewTrackingMockedStatic.verify {
|
|
120
118
|
WebViewTracking.enable(rncWebView, listOf("example.com"), 100.0f, datadogCore)
|
|
121
119
|
}
|
|
122
|
-
|
|
123
|
-
// At this point 'isWebViewTrackingEnabled' should be true.
|
|
124
|
-
assertThat(manager.isWebViewTrackingEnabled).isEqualTo(true)
|
|
125
120
|
}
|
|
126
121
|
}
|
|
@@ -0,0 +1,122 @@
|
|
|
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
|
+
package com.datadog.reactnative.webview
|
|
8
|
+
|
|
9
|
+
import com.datadog.android.api.SdkCore
|
|
10
|
+
import com.datadog.android.core.InternalSdkCore
|
|
11
|
+
import com.datadog.android.webview.WebViewTracking
|
|
12
|
+
import com.datadog.reactnative.DatadogSDKWrapperStorage
|
|
13
|
+
import main.reactnative.tools.unit.GenericAssert.Companion.assertThat
|
|
14
|
+
import com.facebook.react.bridge.JavaOnlyArray
|
|
15
|
+
import com.facebook.react.uimanager.ThemedReactContext
|
|
16
|
+
import com.reactnativecommunity.webview.RNCWebView
|
|
17
|
+
import com.reactnativecommunity.webview.RNCWebViewWrapper
|
|
18
|
+
import org.junit.jupiter.api.AfterEach
|
|
19
|
+
import org.junit.jupiter.api.BeforeEach
|
|
20
|
+
import org.junit.jupiter.api.Test
|
|
21
|
+
import org.junit.jupiter.api.extension.ExtendWith
|
|
22
|
+
import org.junit.jupiter.api.extension.Extensions
|
|
23
|
+
import org.mockito.Mock
|
|
24
|
+
import org.mockito.MockedStatic
|
|
25
|
+
import org.mockito.Mockito
|
|
26
|
+
import org.mockito.Mockito.mock
|
|
27
|
+
import org.mockito.junit.jupiter.MockitoExtension
|
|
28
|
+
import org.mockito.junit.jupiter.MockitoSettings
|
|
29
|
+
import org.mockito.kotlin.any
|
|
30
|
+
import org.mockito.kotlin.doReturn
|
|
31
|
+
import org.mockito.kotlin.verify
|
|
32
|
+
import org.mockito.kotlin.whenever
|
|
33
|
+
import org.mockito.quality.Strictness
|
|
34
|
+
|
|
35
|
+
@Extensions(
|
|
36
|
+
ExtendWith(MockitoExtension::class)
|
|
37
|
+
)
|
|
38
|
+
@MockitoSettings(strictness = Strictness.LENIENT)
|
|
39
|
+
internal class DatadogWebViewTest {
|
|
40
|
+
|
|
41
|
+
@Mock
|
|
42
|
+
lateinit var themedReactContext: ThemedReactContext
|
|
43
|
+
|
|
44
|
+
@Mock
|
|
45
|
+
lateinit var datadogCore: InternalSdkCore
|
|
46
|
+
|
|
47
|
+
private lateinit var webViewTrackingMockedStatic: MockedStatic<WebViewTracking>
|
|
48
|
+
|
|
49
|
+
@BeforeEach
|
|
50
|
+
fun `set up`() {
|
|
51
|
+
whenever(themedReactContext.runOnUiQueueThread(any())).thenAnswer { answer ->
|
|
52
|
+
answer.getArgument<Runnable>(0).run()
|
|
53
|
+
true
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
webViewTrackingMockedStatic = Mockito.mockStatic(WebViewTracking::class.java)
|
|
57
|
+
webViewTrackingMockedStatic.`when`<Unit> {
|
|
58
|
+
WebViewTracking.enable(
|
|
59
|
+
webView = any(), // Mock the WebView parameter
|
|
60
|
+
allowedHosts = any(), // Mock the list of allowed hosts
|
|
61
|
+
logsSampleRate = any(), // Mock the logsSampleRate parameter
|
|
62
|
+
sdkCore = any() // Mock the SdkCore parameter
|
|
63
|
+
)
|
|
64
|
+
}.then {} // Return Unit as the function has no return value
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
@AfterEach
|
|
68
|
+
fun `tear down`() {
|
|
69
|
+
webViewTrackingMockedStatic.close()
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
@Test
|
|
73
|
+
fun `Datadog Core is set once initialized`() {
|
|
74
|
+
val manager = DdSdkReactNativeWebViewManager(themedReactContext)
|
|
75
|
+
assertThat(manager.datadogCore).isNull()
|
|
76
|
+
|
|
77
|
+
DatadogSDKWrapperStorage.notifyOnInitializedListeners(datadogCore)
|
|
78
|
+
|
|
79
|
+
assertThat(manager.datadogCore).isNotNull()
|
|
80
|
+
assertThat(manager.datadogCore).isInstanceOf(SdkCore::class.java)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
@Test
|
|
84
|
+
fun `Registers to SdkCore listener if the SDK is not initialized`() {
|
|
85
|
+
// =========
|
|
86
|
+
// Given
|
|
87
|
+
// =========
|
|
88
|
+
val manager = DdSdkReactNativeWebViewManager(themedReactContext)
|
|
89
|
+
|
|
90
|
+
// When first initialized, the WebView manager core should be null
|
|
91
|
+
assertThat(manager.datadogCore).isNull()
|
|
92
|
+
|
|
93
|
+
// =========
|
|
94
|
+
// When
|
|
95
|
+
// =========
|
|
96
|
+
val rncWebView = mock(RNCWebView::class.java)
|
|
97
|
+
val rncWebViewWrapper = mock(RNCWebViewWrapper::class.java)
|
|
98
|
+
whenever(rncWebViewWrapper.webView) doReturn rncWebView
|
|
99
|
+
|
|
100
|
+
// When JS sends allowedHosts through 'injectedJavaScriptBeforeContentLoaded' prop
|
|
101
|
+
manager.setInjectedJavaScriptBeforeContentLoaded(
|
|
102
|
+
rncWebViewWrapper,
|
|
103
|
+
"// #allowedHosts=[\"example.com\",\"test.com\"]"
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
// =========
|
|
107
|
+
// Then
|
|
108
|
+
// =========
|
|
109
|
+
|
|
110
|
+
// When we notify listeners that the core is available...
|
|
111
|
+
DatadogSDKWrapperStorage.notifyOnInitializedListeners(datadogCore)
|
|
112
|
+
|
|
113
|
+
// ...the WebView should enable WebView tracking in the UI Thread.
|
|
114
|
+
verify(themedReactContext).runOnUiQueueThread(any())
|
|
115
|
+
|
|
116
|
+
// Native WebView tracking should be called
|
|
117
|
+
val arrayList = ArrayList(listOf("example.com", "test.com"))
|
|
118
|
+
webViewTrackingMockedStatic.verify {
|
|
119
|
+
WebViewTracking.enable(rncWebView, arrayList, 100.0f, datadogCore)
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
package/lib/commonjs/index.js
CHANGED
|
@@ -9,7 +9,6 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
9
9
|
var _NativeDdLogs = _interopRequireDefault(require("./ext-specs/NativeDdLogs"));
|
|
10
10
|
var _NativeDdSdk = require("./ext-specs/NativeDdSdk");
|
|
11
11
|
var _NativeDdWebView = require("./specs/NativeDdWebView");
|
|
12
|
-
var _envUtils = require("./utils/env-utils");
|
|
13
12
|
var _webviewJsUtils = require("./utils/webview-js-utils");
|
|
14
13
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
15
14
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -45,13 +44,12 @@ const WebViewComponent = (props, ref) => {
|
|
|
45
44
|
userDefinedOnMessage?.(event);
|
|
46
45
|
}
|
|
47
46
|
}, [userDefinedOnMessage, props.logUserCodeErrors]);
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
};
|
|
47
|
+
const injectedJavascript = (0, _react.useMemo)(() => {
|
|
48
|
+
return (0, _webviewJsUtils.wrapJsCodeInTryAndCatch)(props.injectedJavaScript);
|
|
49
|
+
}, [props.injectedJavaScript]);
|
|
50
|
+
const injectedJavascriptBeforeContentLoaded = (0, _react.useMemo)(() => {
|
|
51
|
+
return (0, _webviewJsUtils.wrapJsCodeWithAllowedHosts)(props.injectedJavaScriptBeforeContentLoaded, props.allowedHosts);
|
|
52
|
+
}, [props.injectedJavaScriptBeforeContentLoaded, props.allowedHosts]);
|
|
55
53
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeWebview.WebView, {
|
|
56
54
|
...props,
|
|
57
55
|
onMessage: onMessage,
|
|
@@ -61,8 +59,8 @@ const WebViewComponent = (props, ref) => {
|
|
|
61
59
|
allowedHosts: props.allowedHosts
|
|
62
60
|
}
|
|
63
61
|
},
|
|
64
|
-
injectedJavaScript:
|
|
65
|
-
injectedJavaScriptBeforeContentLoaded:
|
|
62
|
+
injectedJavaScript: injectedJavascript,
|
|
63
|
+
injectedJavaScriptBeforeContentLoaded: injectedJavascriptBeforeContentLoaded,
|
|
66
64
|
ref: ref
|
|
67
65
|
});
|
|
68
66
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNativeWebview","require","_react","_interopRequireWildcard","_NativeDdLogs","_interopRequireDefault","_NativeDdSdk","_NativeDdWebView","
|
|
1
|
+
{"version":3,"names":["_reactNativeWebview","require","_react","_interopRequireWildcard","_NativeDdLogs","_interopRequireDefault","_NativeDdSdk","_NativeDdWebView","_webviewJsUtils","_jsxRuntime","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","WebViewComponent","props","ref","userDefinedOnMessage","onMessage","useCallback","event","handleDatadogMessage","ddMessage","type","message","logUserCodeErrors","NativeDdLogs","error","NativeDdSdk","consumeWebviewEvent","nativeEvent","data","jsonMsg","JSON","parse","source","err","injectedJavascript","useMemo","wrapJsCodeInTryAndCatch","injectedJavaScript","injectedJavascriptBeforeContentLoaded","wrapJsCodeWithAllowedHosts","injectedJavaScriptBeforeContentLoaded","allowedHosts","jsx","WebView","nativeConfig","component","NativeDdWebView","exports","forwardRef","_default"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;;AAMA,IAAAA,mBAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAC,uBAAA,CAAAF,OAAA;AAEA,IAAAG,aAAA,GAAAC,sBAAA,CAAAJ,OAAA;AACA,IAAAK,YAAA,GAAAL,OAAA;AACA,IAAAM,gBAAA,GAAAN,OAAA;AACA,IAAAO,eAAA,GAAAP,OAAA;AAGkC,IAAAQ,WAAA,GAAAR,OAAA;AAAA,SAAAI,uBAAAK,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAA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KAAK,CAAC6B,YAAY,CAAC,CAAC;EAErE,oBACI,IAAAlD,WAAA,CAAAmD,GAAA,EAAC5D,mBAAA,CAAA6D,OAAS;IAAA,GACF/B,KAAK;IACTG,SAAS,EAAEA,SAAU;IACrB6B,YAAY,EAAE;MACVC,SAAS,EAAEC,gCAAe;MAC1BlC,KAAK,EAAE;QACH6B,YAAY,EAAE7B,KAAK,CAAC6B;MACxB;IACJ,CAAE;IACFJ,kBAAkB,EAAEH,kBAAmB;IACvCM,qCAAqC,EACjCF,qCACH;IACDzB,GAAG,EAAEA;EAAI,CACZ,CAAC;AAEV,CAAC;AAEM,MAAM8B,OAAO,GAAAI,OAAA,CAAAJ,OAAA,gBAAG,IAAAK,iBAAU,EAACrC,gBAAgB,CAAC;;AAEnD;AAAA,IAAAsC,QAAA,GAAAF,OAAA,CAAArD,OAAA,GACeiD,OAAO","ignoreList":[]}
|
|
@@ -5,12 +5,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.NativeDdWebView = void 0;
|
|
7
7
|
var _reactNative = require("react-native");
|
|
8
|
-
var _envUtils = require("../utils/env-utils");
|
|
9
8
|
/*
|
|
10
9
|
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
11
10
|
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
12
11
|
* Copyright 2016-Present Datadog, Inc.
|
|
13
12
|
*/
|
|
14
13
|
|
|
15
|
-
const NativeDdWebView = exports.NativeDdWebView =
|
|
14
|
+
const NativeDdWebView = exports.NativeDdWebView = (0, _reactNative.requireNativeComponent)('DdReactNativeWebView');
|
|
16
15
|
//# sourceMappingURL=NativeDdWebView.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNative","require","
|
|
1
|
+
{"version":3,"names":["_reactNative","require","NativeDdWebView","exports","requireNativeComponent"],"sourceRoot":"../../../src","sources":["specs/NativeDdWebView.ts"],"mappings":";;;;;;AAOA,IAAAA,YAAA,GAAAC,OAAA;AAPA;AACA;AACA;AACA;AACA;;AAKA,MAAMC,eAAe,GAAAC,OAAA,CAAAD,eAAA,GAAG,IAAAE,mCAAsB,EAC1C,sBACJ,CAAC","ignoreList":[]}
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.DATADOG_MESSAGE_PREFIX = void 0;
|
|
7
|
+
exports.wrapJsCodeInTryAndCatch = wrapJsCodeInTryAndCatch;
|
|
8
|
+
exports.wrapJsCodeWithAllowedHosts = wrapJsCodeWithAllowedHosts;
|
|
7
9
|
var _NativeDdSdk = require("../ext-specs/NativeDdSdk");
|
|
8
10
|
/*
|
|
9
11
|
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
@@ -22,67 +24,49 @@ const DATADOG_MESSAGE_PREFIX = exports.DATADOG_MESSAGE_PREFIX = '[DATADOG]';
|
|
|
22
24
|
*/
|
|
23
25
|
|
|
24
26
|
/**
|
|
25
|
-
* Wraps the given JS Code in a try and catch block
|
|
27
|
+
* Wraps the given JS Code in a try and catch block, including a
|
|
28
|
+
* comment with the given allowedHosts in JSON format
|
|
26
29
|
* @param javascriptCode The JS Code to wrap in a try and catch block.
|
|
27
30
|
* @returns the wrapped JS code.
|
|
28
31
|
*/
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
window.DatadogEventBridge = {
|
|
52
|
-
send(msg) {
|
|
53
|
-
window.ReactNativeWebView.postMessage(JSON.stringify({
|
|
54
|
-
source: 'DATADOG',
|
|
55
|
-
type: 'NATIVE_EVENT',
|
|
56
|
-
message: msg
|
|
57
|
-
}));
|
|
58
|
-
true;
|
|
59
|
-
},
|
|
60
|
-
getAllowedWebViewHosts() {
|
|
61
|
-
return ${formatAllowedHosts(allowedHosts)}
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
try{
|
|
65
|
-
${customJavaScriptCode}
|
|
66
|
-
}
|
|
67
|
-
catch (error) {
|
|
68
|
-
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
69
|
-
window.ReactNativeWebView.postMessage(JSON.stringify({
|
|
70
|
-
source: 'DATADOG',
|
|
71
|
-
type: 'ERROR',
|
|
72
|
-
message: errorMsg
|
|
73
|
-
}));
|
|
74
|
-
true;
|
|
75
|
-
}
|
|
76
|
-
`;
|
|
77
|
-
exports.getWebViewEventBridgingJS = getWebViewEventBridgingJS;
|
|
32
|
+
function wrapJsCodeWithAllowedHosts(javascriptCode, allowedHosts) {
|
|
33
|
+
let jsCode = '';
|
|
34
|
+
const hosts = formatAllowedHosts(allowedHosts);
|
|
35
|
+
if (hosts) {
|
|
36
|
+
jsCode = `// #allowedHosts=${JSON.stringify(allowedHosts)}\n`;
|
|
37
|
+
}
|
|
38
|
+
return javascriptCode ? `${jsCode}\n${wrapJsCodeInTryAndCatch(javascriptCode)}` : jsCode.trim().length > 0 ? jsCode : undefined;
|
|
39
|
+
}
|
|
40
|
+
function wrapJsCodeInTryAndCatch(javascriptCode) {
|
|
41
|
+
return javascriptCode ? `try{
|
|
42
|
+
${javascriptCode}
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
46
|
+
window.ReactNativeWebView.postMessage(JSON.stringify({
|
|
47
|
+
source: 'DATADOG',
|
|
48
|
+
type: 'ERROR',
|
|
49
|
+
message: errorMsg
|
|
50
|
+
}));
|
|
51
|
+
true;
|
|
52
|
+
}` : undefined;
|
|
53
|
+
}
|
|
78
54
|
function formatAllowedHosts(allowedHosts) {
|
|
79
55
|
try {
|
|
80
|
-
|
|
56
|
+
if (!allowedHosts) {
|
|
57
|
+
throw new Error('allowedHosts is undefined');
|
|
58
|
+
}
|
|
59
|
+
const jsonHosts = JSON.stringify(allowedHosts);
|
|
60
|
+
if (!jsonHosts) {
|
|
61
|
+
throw new Error("JSON.stringify returned 'undefined' for the given hosts");
|
|
62
|
+
}
|
|
63
|
+
return jsonHosts;
|
|
81
64
|
} catch (e) {
|
|
82
65
|
if (_NativeDdSdk.NativeDdSdk) {
|
|
83
66
|
_NativeDdSdk.NativeDdSdk.telemetryError(getErrorMessage(e), getErrorStackTrace(e), 'AllowedHostsError');
|
|
84
67
|
}
|
|
85
|
-
|
|
68
|
+
console.warn(`[@datadog/mobile-react-native-webview] Invalid 'allowedHosts' format: ${e}`);
|
|
69
|
+
return undefined;
|
|
86
70
|
}
|
|
87
71
|
}
|
|
88
72
|
const getErrorMessage = error => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_NativeDdSdk","require","DATADOG_MESSAGE_PREFIX","exports","
|
|
1
|
+
{"version":3,"names":["_NativeDdSdk","require","DATADOG_MESSAGE_PREFIX","exports","wrapJsCodeWithAllowedHosts","javascriptCode","allowedHosts","jsCode","hosts","formatAllowedHosts","JSON","stringify","wrapJsCodeInTryAndCatch","trim","length","undefined","Error","jsonHosts","e","NativeDdSdk","telemetryError","getErrorMessage","getErrorStackTrace","console","warn","error","EMPTY_MESSAGE","message","String","EMPTY_STACK_TRACE","stack","stacktrace","componentStack","sourceURL","line","column"],"sourceRoot":"../../../src","sources":["utils/webview-js-utils.ts"],"mappings":";;;;;;;;AAKA,IAAAA,YAAA,GAAAC,OAAA;AALA;AACA;AACA;AACA;AACA;;AAGO,MAAMC,sBAAsB,GAAAC,OAAA,CAAAD,sBAAA,GAAG,WAAW;;AAEjD;AACA;AACA;;AAWA;AACA;AACA;;AAMA;AACA;AACA;AACA;AACA;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AAOjB,CAAC,EAAE;IACR;EAAA;EAEJ,OAAOY,KAAK;AAChB,CAAC","ignoreList":[]}
|
package/lib/module/index.js
CHANGED
|
@@ -5,12 +5,11 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { WebView as RNWebView } from 'react-native-webview';
|
|
8
|
-
import React, { forwardRef, useCallback } from 'react';
|
|
8
|
+
import React, { forwardRef, useCallback, useMemo } from 'react';
|
|
9
9
|
import NativeDdLogs from './ext-specs/NativeDdLogs';
|
|
10
10
|
import { NativeDdSdk } from './ext-specs/NativeDdSdk';
|
|
11
11
|
import { NativeDdWebView } from './specs/NativeDdWebView';
|
|
12
|
-
import {
|
|
13
|
-
import { getWebViewEventBridgingJS, wrapJsCodeInTryAndCatch } from './utils/webview-js-utils';
|
|
12
|
+
import { wrapJsCodeInTryAndCatch, wrapJsCodeWithAllowedHosts } from './utils/webview-js-utils';
|
|
14
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
15
14
|
const WebViewComponent = (props, ref) => {
|
|
16
15
|
const userDefinedOnMessage = props.onMessage;
|
|
@@ -37,13 +36,12 @@ const WebViewComponent = (props, ref) => {
|
|
|
37
36
|
userDefinedOnMessage?.(event);
|
|
38
37
|
}
|
|
39
38
|
}, [userDefinedOnMessage, props.logUserCodeErrors]);
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
};
|
|
39
|
+
const injectedJavascript = useMemo(() => {
|
|
40
|
+
return wrapJsCodeInTryAndCatch(props.injectedJavaScript);
|
|
41
|
+
}, [props.injectedJavaScript]);
|
|
42
|
+
const injectedJavascriptBeforeContentLoaded = useMemo(() => {
|
|
43
|
+
return wrapJsCodeWithAllowedHosts(props.injectedJavaScriptBeforeContentLoaded, props.allowedHosts);
|
|
44
|
+
}, [props.injectedJavaScriptBeforeContentLoaded, props.allowedHosts]);
|
|
47
45
|
return /*#__PURE__*/_jsx(RNWebView, {
|
|
48
46
|
...props,
|
|
49
47
|
onMessage: onMessage,
|
|
@@ -53,8 +51,8 @@ const WebViewComponent = (props, ref) => {
|
|
|
53
51
|
allowedHosts: props.allowedHosts
|
|
54
52
|
}
|
|
55
53
|
},
|
|
56
|
-
injectedJavaScript:
|
|
57
|
-
injectedJavaScriptBeforeContentLoaded:
|
|
54
|
+
injectedJavaScript: injectedJavascript,
|
|
55
|
+
injectedJavaScriptBeforeContentLoaded: injectedJavascriptBeforeContentLoaded,
|
|
58
56
|
ref: ref
|
|
59
57
|
});
|
|
60
58
|
};
|