PierfrancescoSoffritti / android-youtube-player

YouTube Player library for Android and Chromecast, stable and customizable.
https://pierfrancescosoffritti.github.io/android-youtube-player/
MIT License
3.44k stars 765 forks source link

Can We Access the Underlying WebView? #1149

Closed HamzaIsrar12 closed 5 months ago

HamzaIsrar12 commented 5 months ago

Question

Hi Pier,

Is it possible to access the underlying WebView? I have an SDK that runs JavaScript on all WebViews, but I need to disable it for this particular WebView. This SDK is preventing me from opening YouTube videos in the external browser. Specifically, I need to call a disableInjection(webView: WebView) method and pass this WebView instance.

Thank you!

PierfrancescoSoffritti commented 5 months ago

Currently the webview is not exposed through the API. Could you clarify why you need to access it?

HamzaIsrar12 commented 5 months ago

Sure, I have an Analytics SDK that injects JavaScript into webviews to automatically capture relevant events. However, this feature is somewhat buggy for certain webviews, and in our case, it's conflicting with the YouTube Player View.

When I tap the "YouTube" button in the player, instead of redirecting me to the external browser, it opens the content within the webview, which then crashes in some way.

PierfrancescoSoffritti commented 5 months ago

So disableInjection is a method from your analytics SDK? are you sure they don't have other ways to do exclude webviews? I assume they are using reflection to inject code in all webviews?

Technically you could also use reflection to access the webview. Not optimal, but maybe enough to have a workaround.

Let me know.

HamzaIsrar12 commented 5 months ago

Yes, the disableInjection method is a feature of the analytics SDK. I've contacted their support team about this issue, and they are aware of it, but there hasn't been an update yet.

I experimented with reflection, and it seems to be functioning correctly for me now. I'm just ensuring that it won't create any issues when Proguard is applied. 👍🏻

Thank you for your help, Peir. 😄

HamzaIsrar12 commented 5 months ago

It encountered a Proguard issue, but I resolved it by incorporating the following keep rule:

-keep class com.pierfrancescosoffritti.androidyoutubeplayer.core.player.views.** { *; }

✨ 🚀

PierfrancescoSoffritti commented 5 months ago

Nice, I'm glad it worked :)