What's the difference between setWebViewClient vs. setWebChromeClient?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
setWebViewClient and setWebChromeClient are not two ways to solve the same problem. They handle different parts of WebView behavior, and many real Android apps need both because one manages page navigation while the other manages browser-style UI features.
What WebViewClient Handles
WebViewClient is responsible for navigation-related behavior inside the WebView. This is where you keep links inside the app, observe page completion, react to load errors, and enforce URL handling rules.
If you do not set a WebViewClient, many links may open in the external browser instead of staying in your app's WebView.
What WebChromeClient Handles
WebChromeClient is responsible for browser-chrome behavior. That includes progress updates, page titles, JavaScript dialogs, permission prompts, file chooser flows, and custom full-screen content such as video.
If page titles never update or JavaScript dialogs do not appear, the missing piece is often WebChromeClient.
Real Apps Commonly Use Both Together
These two clients are complementary, not competing.
A simple way to remember the split is:
- '
WebViewClienthandles page transport and navigation' - '
WebChromeClienthandles browser-style UI callbacks'
Once that boundary is clear, the callback placement becomes much easier to remember.
Practical Examples
If you need to intercept a custom URL scheme such as myapp://checkout, that belongs in WebViewClient.
If the web page needs a file chooser for an upload field, that belongs in WebChromeClient.
Trying to solve upload handling in WebViewClient will not work because it is the wrong layer of responsibility.
Security and Policy Belong Closer to WebViewClient
Navigation policy, SSL behavior, and request trust decisions usually belong in WebViewClient.
That is another clue about the separation: request-level behavior lives closer to WebViewClient, while UI-like browser behavior lives closer to WebChromeClient.
Avoid Overriding Too Much
It is possible to break WebView behavior by intercepting everything. For example, always returning true from shouldOverrideUrlLoading without loading the URL yourself can stop normal navigation entirely.
The goal is to override only the behavior your app actually needs. Let the WebView handle the rest.
Common Pitfalls
A common mistake is expecting WebViewClient to handle JavaScript dialogs, upload prompts, or progress callbacks. Those belong to WebChromeClient.
Another is forgetting to set WebViewClient and then being surprised when taps open the external browser.
Developers also sometimes intercept every URL aggressively and accidentally block ordinary navigation. Override selectively.
Finally, do not weaken SSL handling just to make a broken site load during testing. That shortcut can become a production security problem very quickly.
Summary
- '
WebViewClienthandles navigation, loading lifecycle, and request-related behavior.' - '
WebChromeClienthandles browser-style UI features such as titles, dialogs, and progress.' - Most nontrivial WebView integrations need both on the same view.
- Put URL policy in
WebViewClientand UI callbacks inWebChromeClient. - Knowing the responsibility boundary makes WebView debugging much easier.
Related reading
- What's the difference between src/androidtest and src/test folders?
- What's the difference between the various methods to get an Android Context?
- What's the difference between 'weak' and 'assign' in delegate property declaration
- What's the dSYM and how to use it? iOS SDK
- What's the Kotlin equivalent of Java's String?
- What''s the point of NSAssert, actually?
- what's the purpose of double question mark in swift
- What's the UIScrollView contentInset property for?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.