@metamask/react-native-webview
Advanced tools
| package com.reactnativecommunity.webview.extension.file | ||
| /** | ||
| * JavaScript code to detect all iFrames in the page and report their URLs | ||
| * This script runs after page load and also monitors for dynamically added iFrames | ||
| */ | ||
| fun getIFrameDetectorScript(): String = """ | ||
| (function() { | ||
| if (window.iframeDetectorInjected) return; | ||
| window.iframeDetectorInjected = true; | ||
| function collectIFrameUrls() { | ||
| const iframes = document.getElementsByTagName('iframe'); | ||
| const urls = []; | ||
| for (let i = 0; i < iframes.length; i++) { | ||
| const iframe = iframes[i]; | ||
| const src = iframe.src; | ||
| if (src && src.trim() !== '' && (src.startsWith('http://') || src.startsWith('https://') || src.startsWith('//'))) { | ||
| const normalizedUrl = src.startsWith('//') ? 'https:' + src : src; | ||
| urls.push(normalizedUrl); | ||
| } | ||
| } | ||
| return urls; | ||
| } | ||
| function reportIFrames() { | ||
| try { | ||
| const urls = collectIFrameUrls(); | ||
| if (urls.length > 0) { | ||
| const message = { | ||
| type: 'IFRAME_DETECTED', | ||
| iframeUrls: urls | ||
| }; | ||
| if (window.ReactNativeWebView && window.ReactNativeWebView.postMessage) { | ||
| window.ReactNativeWebView.postMessage(JSON.stringify(message)); | ||
| } | ||
| } | ||
| } catch (e) { | ||
| console.error('Error reporting iFrames:', e); | ||
| } | ||
| } | ||
| // Initial check for iFrames | ||
| if (document.readyState === 'loading') { | ||
| document.addEventListener('DOMContentLoaded', reportIFrames); | ||
| } else { | ||
| // Document already loaded | ||
| setTimeout(reportIFrames, 100); | ||
| } | ||
| // Monitor for dynamically added iFrames | ||
| const observer = new MutationObserver(function(mutations) { | ||
| let shouldCheck = false; | ||
| mutations.forEach(function(mutation) { | ||
| if (mutation.type === 'childList') { | ||
| mutation.addedNodes.forEach(function(node) { | ||
| if (node.nodeType === Node.ELEMENT_NODE) { | ||
| if (node.tagName === 'IFRAME' || node.querySelector('iframe')) { | ||
| shouldCheck = true; | ||
| } | ||
| } | ||
| }); | ||
| } | ||
| }); | ||
| if (shouldCheck) { | ||
| setTimeout(reportIFrames, 100); | ||
| } | ||
| }); | ||
| observer.observe(document.body || document.documentElement, { | ||
| childList: true, | ||
| subtree: true | ||
| }); | ||
| // Also check periodically as a fallback | ||
| setInterval(reportIFrames, 5000); | ||
| })(); | ||
| """.trimIndent() |
@@ -50,2 +50,3 @@ package com.reactnativecommunity.webview; | ||
| import com.reactnativecommunity.webview.extension.file.BlobFileDownloader; | ||
| import com.reactnativecommunity.webview.extension.file.IFrameDetectorKt; | ||
@@ -347,2 +348,6 @@ import org.json.JSONException; | ||
| public void injectIFrameDetectorScript() { | ||
| evaluateJavascriptWithFallback(IFrameDetectorKt.getIFrameDetectorScript()); | ||
| } | ||
| public void callInjectedJavaScriptBeforeContentLoaded() { | ||
@@ -349,0 +354,0 @@ if (getSettings().getJavaScriptEnabled() && |
@@ -79,2 +79,4 @@ package com.reactnativecommunity.webview; | ||
| reactWebView.injectIFrameDetectorScript(); | ||
| emitFinishEvent(webView, url); | ||
@@ -81,0 +83,0 @@ } |
+1
-1
@@ -13,3 +13,3 @@ { | ||
| "license": "MIT", | ||
| "version": "14.2.1", | ||
| "version": "14.2.2", | ||
| "homepage": "https://github.com/MetaMask/react-native-webview-mm#readme", | ||
@@ -16,0 +16,0 @@ "scripts": { |
Sorry, the diff of this file is too big to display
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
707583
0.5%139
0.72%7296
0.07%