Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Universal DevTools for all environments

Kohei Ueno
November 27, 2021

Universal DevTools for all environments

Universal DevTools enables use to debug WebViews with Chrome DevTools.

DEMO: https://youtu.be/5H3Sswp5qYg?t=5100

https://github.com/cola119/universal-devtools-poc

Kohei Ueno

November 27, 2021
Tweet

Other Decks in Technology

Transcript

  1. What I want to talk about today Chrome (PC) Safari

    (PC) Chrome DevTools Web Inspector
  2. What I want to talk about today Chrome (PC) Chrome

    (Android) Safari (iOS) Safari (PC) Chrome DevTools Web Inspector
  3. What I want to talk about today Chrome (PC) Chrome

    (Android) Safari (iOS) Safari (PC) Chrome DevTools Web Inspector WebView WebView WebView WebView
  4. What I want to talk about today Chrome (PC) Chrome

    (Android) Safari (iOS) Safari (PC) Chrome DevTools Web Inspector WebView WebView WebView WebView Cannot debug WebView 😢
  5. WebViews are widely used in native apps to render web

    content Chrome (PC) Chrome (Android) Safari (iOS) Safari (PC) WebView WebView WebView WebView Making WebViews Work for the Web Dominique Hazael-Massieux, TPAC2021 https://www.w3.org/2021/Talks/dhm-tpac-webviews/#5
  6. Contents 1. Anatomy of DevTools 2. Debug methods for mobile

    devices 3. Problem 4. Universal DevTools 5. Summary
  7. 1. Anatomy of DevTools 2. Debug methods for mobile devices

    3. Problem 4. Universal DevTools 5. Summary
  8. Client-server model Chrome DevTools Server Client Command Event Tell me

    the DOM tree of your site! Sure, here you are.
  9. Chrome DevTools blink V8 console API is called! index.js index.js

    Communication with DevTools JS engines notify API calls to DevTools (Event) OK, I’ll display them! Event
  10. Chrome DevTools blink V8 console API is called! fetch API

    is called! index.js index.js Communication with DevTools JS engines notify API calls to DevTools (Event) DOM tree is changed! OK, I’ll display them!
  11. Chrome DevTools blink index.js V8 Give me the DOM tree!

    index.js Communication with DevTools DevTools send commands to the browser
  12. Chrome DevTools blink index.js V8 DOM tree Give me the

    DOM tree! index.js Communication with DevTools JS engines send the response to the command Thank you!
  13. Chrome DevTools Protocol Hi, could you change <h1> text from

    “JSConf JP” to “Hello World”?
  14. Chrome DevTools Protocol Hi, could you change <h1> text from

    “JSConf JP” to “Hello World”?
  15. Chrome DevTools Protocol Hi, could you change <h1> text from

    “JSConf JP” to “Hello World”? OK, I changed.
  16. 1. Anatomy of DevTools 2. Debug methods for mobile devices

    3. Problem 4. Universal DevTools 5. Summary
  17. 1. Anatomy of DevTools 2. Debug methods for mobile devices

    3. Problem 4. Universal DevTools 5. Summary
  18. WebView Your website is broken when I view it in

    Twitter’s in-app browser! <
  19. WebView Your website is broken when I view it in

    Twitter’s in-app browser! < > Oops, let me check. > Wait, how can I debug in-app browser? I can’t inspect it with DevTools...
  20. In-app browser, LIFF, Mini app, Super app How do you

    debug WebView-based applications? WebView Your website is broken when I view it in Twitter’s in-app browser! < > Oops, let me check. > Wait, how can I debug in-app browser? I can’t inspect it with DevTools...
  21. In-app browser, LIFF, Mini app, Super app How do you

    debug WebView-based applications? WebView Your website is broken when I view it in Twitter’s in-app browser! < > Oops, let me check. > Wait, how can I debug in-app browser? I can’t inspect it with DevTools... Simulator? Remote debug?
  22. Simulator WKWebView WebView If you can run an app using

    WebView on your simulator, you can debug without any problem. Good! But you can’t run Facebook, LINE, Twitter on your simulator. (unless you are working there) Simulator
  23. Remote debug WKWebView WebView debugging must be enabled! Android: setWebContentsDebuggingEnabled(true)

    iOS: Debug build (beta version) Android: setWebContentsDebuggingEnabled(false) iOS: Production build (downloaded from App Store) WebView Your iPhone
  24. https://jsconf.jp/2021 develop hosting register • LINE Login • send messages

    • get friends list • ... https://liff.line.me/{liff_id} Your web app can use a variety of LINE-specific APIs Introduction to LIFF/LINE Mini App - Characteristics and Practical Development https://linedevday.linecorp.com/2021/en/sessions/151/ Example: LIFF
  25. https://jsconf.jp/2021 develop hosting register • LINE Login • send messages

    • get friends list • ... https://liff.line.me/{liff_id} Your web app can use a variety of LINE-specific APIs You can’t debug your web app running on LIFF Browser 😢 Android: setWebContentsDebuggingEnabled(false) iOS: Production build (downloaded from App Store) Example: LIFF For Improvement of Developer Experience of All LIFF App Developers https://linedevday.linecorp.com/2021/en/sessions/142/
  26. 1. Anatomy of DevTools 2. Debug methods for mobile devices

    3. Problem 4. Universal DevTools 5. Summary
  27. - Production build - setWebContentsDebuggingEnabled(false) DevTools can’t get information from

    JS engine. console, network logs, DOM tree, memory,... How debug a web app on WebView with debug options disabled? WebView
  28. How debug a web app on WebView with debug options

    disabled? - Production build - setWebContentsDebuggingEnabled(false) Well, then, Let’s send debug information using only JavaScript API! DevTools can’t get information from JS engine. console, network logs, DOM tree, memory,... WebView
  29. Reproduce client-server model with JavaScript DevTools client DevTools Protocol Server

    Client WebView Send events when an API is called (console, network request/response)
  30. Reproduce client-server model with JavaScript DevTools client DevTools Protocol Send

    events when an API is called (console, network request/response) DevTools Protocol Interpret commands (DOM manipulation) Server Client WebView
  31. Send events to the client DevTools client 1. Intercept API

    calls WebSocket server 2. Convert to DevTools Protocol WebView
  32. Chrome DevTools blink V8 index.js index.js index.js doesn’t have access

    to JS engine’s information How intercept API calls?
  33. Chrome DevTools blink V8 index.js index.js Intercept API calls with

    JavaScript fetch API is called! console API is called! DOM tree is changed! OK, let’s use JavaScript! index.js doesn’t have access to JS engine’s information
  34. Trap a function call with Proxy object index.js console.log fetch

    Execution Execution Send to DevTools Proxy object
  35. Trap a function call with Proxy object index.js console.log fetch

    Execution Execution Send to DevTools Proxy object No side effects 😊
  36. Trap a function call with Proxy object index.js console.log fetch

    Execution Execution Send to DevTools Send to DevTools
  37. Headless Inspector emits the corresponding event in response to the

    API call. https://github.com/cola119/universal-devtools-poc/tree/master/packages
  38. Headless Inspector emits the corresponding event in response to the

    API call. https://github.com/cola119/universal-devtools-poc/tree/master/packages
  39. Headless Inspector index.js headless-inspector-core Console fetch XHR DOM Storage sendBeacon

    Each API is wrapped by a Proxy object and emits events Network Elements Console Application
  40. Headless Inspector index.js headless-inspector-core Console fetch XHR DOM Storage sendBeacon

    Each API is wrapped by a Proxy object and emits events Network Elements Console Application
  41. Convert to DevTools protocol index.js headless-inspector-core Chrome DevTools Safari Web

    Inspector Chrome DevTools Protocol WebKit Inspector Protocol headless-inspector-cdp headless-inspector-wip
  42. Convert to DevTools protocol index.js headless-inspector-core Chrome DevTools Safari Web

    Inspector Chrome DevTools Protocol WebKit Inspector Protocol headless-inspector-cdp headless-inspector-wip I/F: https://www.npmjs.com/package/devtools-protocol
  43. Inspect DOM Give me the DOM information blink V8 Chrome

    DevTools index.js index.js OK, just a moment.
  44. Architecture DevTools client Command Command Event Event Intercept API calls

    Convert to DevTools Protocol headless-inspector-cdp headless-inspector-core headless-inspector-cdp WebView WebSocket server
  45. 1. Anatomy of DevTools 2. Debug methods for mobile devices

    3. Problem 4. Universal DevTools 5. Summary
  46. Summary 80% of native apps use WebViews 10+% of Web

    content is rendered on WebViews WebView But you cannot debug WebView 😢
  47. Summary 80% of native apps use WebViews 10+% of Web

    content is rendered on WebViews WebView But you cannot debug WebView 😢 All web applications can be debugged using any DevTools (Chrome DevTools, Safari Web Inspector, etc.) without any side effects 😄 Universal DevTools https://github.com/cola119/universal-devtools-poc
  48. Limitation, Challenges - Call Stack - Breakpoints - Variables -

    Analyze runtime performance There are some limitations because Universal DevTools is implemented in JavaScript. But at the same time, there are many challenges - Edit source files - Memory Usage - Record - Extension etc...