Skip to content

Conversation

@jacksonhardaker
Copy link

@jacksonhardaker jacksonhardaker commented Dec 23, 2025


try {
val script = WebViewBridgeScript.SCRIPT
WebViewCompat.addDocumentStartJavaScript(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't we be calling this in addition to webview.addJavascriptInterface() for webviews that support both?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's what's happening at the moment. The instrument function hooks up the bridge via addJavascriptInterface, then calls this injectScript function which handles injecting all the OOTB javascript handlers.

I do see that AI left a spot for a fallback injection method, and then didn't implement it, so I'll do that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah I see, the 2 calls are needed. Yeah curious how it would behave if for some reason WebViewFeature.isFeatureSupported(WebViewFeature.DOCUMENT_START_SCRIPT) returns false

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the fallback approach: 005249a

Probably worth considering whether we even care to support the case where DOCUMENT_START_SCRIPT is unsupported? I'll add a discussion point in the PRD doc

val original = WebViewCompat.getWebViewClient(webview)
WebViewCapture(original, effectiveLogger, needsFallback)
} else {
WebViewCapture(WebViewClient(), effectiveLogger, needsFallback)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure how this all works but I worry that there might be cases where WebViewFeature.isFeatureSupported(WebViewFeature.GET_WEB_VIEW_CLIENT) returns false but the user still provided their own custom WebViewClient and we might be just blindly overriding it

Comment on lines +79 to +85
let navigationDelegate = WebViewNavigationDelegate(
original: webView.navigationDelegate,
logger: effectiveLogger,
messageHandler: capture.messageHandler
)
capture.navigationDelegate = navigationDelegate
webView.navigationDelegate = navigationDelegate
Copy link
Contributor

@kattrali kattrali Jan 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its not clear to me that this delegate object would not get garbage collected, particularly under memory pressure, since webView.navigationDelegate is a weak ref -- might have to hold on to these? Same for capture.

alternately there could be one delegate object that is always around and it keeps a reference to the various webviews and associated data like page load times.


/// Tracks instrumented WebViews to prevent double-instrumentation
private static var instrumentedWebViews = NSHashTable<WKWebView>.weakObjects()
private static let lock = NSLock()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd probably give this a more specific name, since its a lock for the instrumented web views collection in particular and who knows, might lock something else.

@github-actions
Copy link

github-actions bot commented Jan 9, 2026

Android Benchmark Results

Device: PR: Emulator - Android SDK built for x86_64 (API 31) | main: Emulator - Android SDK built for x86_64 (API 31)

Note: Benchmarks run on emulator. Results may vary between runs and may differ from physical devices.

Allocations

Test PR main Δ
logHttpNetworkLog50FieldsAndHeadersAndFieldProviders 1088 1095 -0.6%
logNotMatched10Fields 18 18 0.0%
logNotMatched5000Fields 160 160 0.0%
logNotMatched500Fields 160 158 +1.3%
logNotMatched5Fields 15 15 0.0%
logNotMatchedNoFields 1 1 0.0%
trackSpansWithFields 364 364 0.0%
trackSpansWithoutFields 56 56 0.0%

Timing

Test PR main Δ
logHttpNetworkLog50FieldsAndHeadersAndFieldProviders 229.24 us 238.06 us -3.7%
logNotMatched10Fields 5.63 us 5.66 us -0.6%
logNotMatched5000Fields 2.23 ms 2.27 ms -1.7%
logNotMatched500Fields 232.36 us 233.92 us -0.7%
logNotMatched5Fields 3.19 us 3.24 us -1.5%
logNotMatchedNoFields 415 ns 436 ns -4.7%
trackSpansWithFields 462.45 us 459.67 us +0.6%
trackSpansWithoutFields 7.45 us 7.53 us -1.0%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants