DEV Community

Hrishikesh Sharma
Hrishikesh Sharma

Posted on

5 1

How to debug React Native WebView

Assuming that you have already started working with React Native and possibly began to check how to debug code in and out using the debug menu in devices.
Keeping aside the traditional code and bringing focus on the WebView component only. Recently, React Native Dev made some changes in the web view repo and replaced UIWebView with WKWebView in iOS 8.0.
Then the next change happened, if you are reading this, then you probably must know this, React Native removed WebView from its repository and made it a self-supported import. Now it exists in,

React Native Web View

Now, coming back to the main agenda of debugging HTML in iOS and Android devices.

...

For iOS
We need probably two things, an app running in any iOS device/iOS simulator with the app in debug state and Safari Developer Toolkit.

To enable "Develop" mode in Safari Browser:

  • Open Safari Browser
  • Under the Safari option, click on 'Preferences'
  • Under the 'Advanced' tab, enable check "Show Develop menu in menu bar"

Steps for debugging:

  • Run the React Native app with WebView in iOS device/ iOS simulator in debug mode
  • Open Safari, from the menu bar, we need to click on 'Develop' option, 'Develop' > {Device Name} > {Application Name} > {Title}
  • Now you can debug the HTML rendered within the WebView

...

For Android
We can debug the contents of the WebView in Chrome directly.

Steps for debugging:

  • Firstly, we need to make some edits in the "MainApplication.java" file so that we can enable debugging, see below-attached image for importing

image

  • Run the React Native app with WebView in Android device or Android emulator
  • Open Chrome, and follow the links, DevTools > 3 dot menu > More tools > Remote devices
  • Select the current device and then hit 'Inspect'
  • Now you can debug the HTML content of the WebView

Note: USB debugging must be enabled in your device settings.

...

I was stuck at debugging the content for a while and then I referred this link. I hope it'll be a great help to you.

Happy Coding :)

Do your career a big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started

Community matters

Top comments (2)

Collapse
 
joweltisso profile image
Jowel Tisso

Thanks for this guide, I was looking for the exact clarity. Please keep up the good work.

Collapse
 
hrishikeshps profile image
Hrishikesh Sharma

@joweltisso Awesome! Sounds so good that it helped you.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay