Remote Debugging on Android with Chrome
https://developer.chrome.com/devtools/docs/remote-debugging
1. 안드로이드 폰 : 환경설정 > 개발자모드 선택 후 "USB Debugging" 모드 선택해야함.
2. PC 크롬 브라우저에 chrome://inspect. 입력.
3. PC 와 안드로이드폰을 USB로 연결.
4. PC 크롬 브라우저에 연결된 핸드폰 정보가 나온다. 브라우저에서 "inspect" 를 선택하면
안드로이드폰에서 접속한 크롬 브라우저의 내용이 나온다.
- 안드로이드폰의 크롬브라우저를 PC에서 보는 기능 구현.
=================================================================================
The way your web content behaves on mobile can be dramatically different from the desktop experience. Remote debugging with Chrome DevTools lets you debug live content on your Android device from your development machine.
Remote debugging on Android supports:
- Debugging websites in browser tabs.
- Debugging WebViews in native Android apps.
- Screencasting live to your development machine from your Android device.
- Accessing your development server on Android using port forwarding and virtual host mapping.
Requirements
To begin remote debugging, you need:
- Chrome 32 or later installed on your development machine.
- A USB cable to connect your Android device.
- For browser debugging: Android 4.0+ and Chrome for Android.
- For app debugging: Android 4.4+ and a WebView configured for debugging.
If at any time you encounter problems with remote debugging, refer to the Troubleshooting section.
Setting up your Android device
Follow these instructions to set up your Android device for remote debugging.
1. Enable USB debugging
On your Android device, select Settings > Developer options.
In Developer options, select the USB debugging checkbox:
An alert prompts you to allow USB debugging. Tap OK.
2. Connect your device
Connect the Android device to your development machine using a USB cable.
Discovering devices in Chrome
After setting up remote debugging on Android, discover your device in Chrome.
On your desktop Chrome browser, navigate to chrome://inspect. Confirm that Discover USB devices is checked:
On your device, an alert prompts you to allow USB debugging from your computer. Tap OK.
The message USB debugging connected displays in the device's notification drawer.
On your computer, the chrome://inspect page displays every connected device, along with its open tabs and debug-enabled WebViews.
If you have problems finding your device on the chrome://inspect page, see the Troubleshooting section.
Debugging remote browser tabs
From the chrome://inspect page, you can launch DevTools and debug your remote browser tabs.
To start debugging, click inspect below the browser tab you want to debug.
A new instance of Chrome DevTools launches on your computer. From this instance, you can interact with the selected browser tab on your device in real time.
For example, you can use DevTools to inspect web page elements on your device:
- When you mouse over an element in the Elements panel, DevTools highlights the element on your device.
- You can also click the Inspect Element icon in DevTools and tap your device screen. DevTools highlights the tapped element in the Elements panel.
Debugging tips
Here are a few tips to help get you started with remote debugging:
- Use F5 (or Cmd+r on Mac) to reload a remote page from the DevTools window.
- Keep the device on a cellular network. Use the Network panel to view the network waterfall under actual mobile conditions.
- Use the Timeline panel to analyze rendering and CPU usage. Hardware on mobile devices often runs much slower than on your development machine.
- If you’re running a local web server, use port forwarding or virtual host mapping to access the site on your device.
Debugging WebViews
On Android 4.4 (KitKat) or later, you can use DevTools to debug WebView content in native Android applications.
Configure WebViews for debugging
WebView debugging must be enabled from within your application. To enable WebView debugging, call the static method setWebContentsDebuggingEnabled on the WebView class.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { WebView.setWebContentsDebuggingEnabled(true); }
This setting applies to all of the application's WebViews.
Tip: WebView debugging is not affected by the state of the debuggable
flag in the application's manifest. If you want to enable WebView debugging only when debuggable
is true
, test the flag at runtime.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { if (0 != (getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE)) { WebView.setWebContentsDebuggingEnabled(true); } }
Open a WebView in DevTools
The chrome://inspect page displays a list of debug-enabled WebViews on your device.
To start debugging, click inspect below the WebView you want to debug. Use DevTools as you would for aremote browser tab.
The gray graphics listed with the WebView represent its size and position relative to the device's screen. If your WebViews have titles set, the titles are listed as well.
Live screencasting
Shifting your attention between screens isn’t always convenient. Screencast displays your device's screen right alongside DevTools on your development machine. You can interact with the content on your device from the screencast too.
As of KitKat 4.4.3, screencast is available for both browser tabs and Android WebViews.
Start a screencast session
To start screencasting, click the Screencast icon in the upper right corner of your remote debugging DevTools window.
The Screencast panel opens on the left and displays a live view of your device's screen.
Screencast only displays page content. Transparent portions of the screencast are covered by the omnibox, device keyboard, and other device interfaces.
Interact with your device using the screencast
When you interact with the screencast, clicks are translated into taps, firing proper touch events on the device. Keystrokes from your computer are sent to the device, so you can avoid typing with your thumbs.
Other DevTools work with the screencast too. For example, to inspect an element, click the Inspect Element icon and then click inside the screencast.
Tips: To simulate a pinch gesture, hold Shift while dragging. To scroll, use your trackpad or mouse wheel or fling with your pointer.
Port forwarding
Your phone can't always reach the content on your development server. They might be on different networks. Moreover, you might be developing on a restricted corporate network.
Port forwarding on Chrome for Android makes it easy to test your development site on mobile. It works by creating a listening TCP port on your mobile device that maps to a particular TCP port on your development machine. Traffic between these ports travels through USB, so the connection doesn't depend on your network configuration.
To enable port forwarding:
- Open chrome://inspect on your development machine.
- Click Port Forwarding. The port forwarding settings display.
- In the Device port field, enter the port number you want your Android device to listen on.
(The default port is 8080.) - In the Host field, enter the IP address (or hostname) and port number where your web application is running.
This address can be any local location accessible from your development machine. Currently, port numbers must be between 1024 and 32767 (inclusive). - Check Enable port forwarding.
- Click Done.
The port status indicators on chrome://inspect are green when port forwarding is successful.
Now you can open a new Chrome for Android tab and view the content of your local server on your device.
Virtual host mapping
Port forwarding works great when you're developing on localhost
. But there are cases when you might be using a customized local domain.
For example, suppose you're using a third party JavaScript SDK that only works on whitelisted domains. So you added an entry, such as 127.0.0.1 production.com
, to your hosts file. Or maybe you configured a customized domain using virtual hosts on your web server (MAMP).
If you want your phone to reach content on your customized domain, you can use port forwarding in combination with a proxy server. The proxy maps requests from your device to the correct location on the host machine.
Set up port forwarding to a proxy
Virtual host mapping requires you to run a proxy server on the host machine. All requests from your Android device will be forwarded to the proxy.
To set up port forwarding to a proxy:
- On the host machine, install proxy software such as Charles Proxy (free trial available) or Squid.
- Run the proxy server and note the port that it's using.
- In a Chrome browser, navigate to chrome://inspect.
- Click Port forwarding. The port forwarding settings display.
- In the Device port field, enter the port number that you want your Android device to listen on.
Use a port that Android allows, such as9000
. - In the Host field, enter
localhost:xxxx
, wherexxxx
is the port your proxy is running on. - Check Enable port forwarding.
- Click Done.
The proxy on the host machine is set up to make requests on behalf of your Android device.
Configure proxy settings on your device
Your Android device needs to communicate with the proxy on the host machine.
To configure the proxy settings on your device:
- Select Settings > Wi-Fi.
- Long-press the network that you are currently connected to.
- Tap Modify network.
- Select Advanced options.
The proxy settings display. - Tap the Proxy menu and select Manual.
- In the Proxy hostname field, enter
localhost
. - In the Proxy port field, enter
9000
. - Tap Save.
With these settings, your device forwards all of its requests to the proxy on the host machine. The proxy makes requests on behalf of your device, so requests to your customized local domain are properly resolved.
Now you can load local domains on Chrome for Android just as you would on the host machine.
Tip: To resume normal browsing, remember to revert the proxy settings on your device after you disconnect from the host.
Troubleshooting
I can't see my device on the chrome://inspect page.
- If you are developing on Windows, verify that the appropriate USB driver for your device is installed. SeeOEM USB Drivers on the Android Developers' site.
- Verify that the device is connected directly to your machine, bypassing any hubs.
- Verify that USB debugging is enabled on your device. Remember to accept the USB debugging permission alerts on your device.
- On your desktop browser, navigate to chrome://inspect and verify that Discover USB devices is checked.
- Remote debugging requires your version of desktop Chrome to be newer than the version of Chrome for Android on your device. Try using Chrome Canary (Mac/Windows) or the Chrome Dev channel release (Linux) on desktop.
If you still can't see your device, unplug it. On your device, select Settings > Developer options. Tap Revoke USB debugging authorizations. Then, retry the device setup and discovery processes.
I can't see my browser tabs on the chrome://inspect page.
- On your device, open the Chrome browser and navigate to the web page you want to debug. Then, refresh the chrome://inspect page.
I can't see my WebViews on the chrome://inspect page.
- Verify that WebView debugging is enabled for your app.
- On your device, open the app with the WebView you want to debug. Then, refresh the chrome://inspectpage.
I can't access my web server from my Android device.
- If network restrictions prevent your mobile device from accessing your development server, try enablingport forwarding or setting up a virtual host map.
Lastly, if remote debugging still isn't working, you can revert to the legacy workflow using the adb
binary from the Android SDK.
Additional information
Remote debugging and ADB
You no longer need to configure ADB or the ADB plugin to debug remote browser tabs and WebViews. Remote debugging for Android is now part of the standard Chrome DevTools. It works on all operating systems: Windows, Mac, Linux, and Chrome OS.
If you do encounter problems with remote debugging, you can try the legacy workflow using the adb
binary from the Android SDK.
Remote debugging for DevTools extension developers
For information about the remote debugging interaction protocol, refer to the Debugger Protocoldocumentation and chrome.debugger.
'프로그래밍 > Architect' 카테고리의 다른 글
neo4j - http://neo4j.com/developer/get-started/ (0) | 2015.10.29 |
---|---|
머신러닝의 미래 (0) | 2015.10.15 |
엑셀 하이퍼링크 함수 (0) | 2015.09.01 |
[iPad] iPad CSS Layout with landscape / portrait orientation modes (0) | 2015.08.20 |
모바일 기획 (0) | 2015.08.14 |