Tips for using Erdua, a mobile web debugging tool

Tips for using Erdua, a mobile web debugging tool

One of the biggest pain points in mobile web development is that you cannot view console.log logs and other information such as network requests and local storage when running on a real machine. If the webpage is running in a mobile browser, it is not bad. You can open the URL on a computer to view the console information. However, if you are developing an embedded H5 page for an APP, you can only rely on the browser simulation environment to avoid bugs during the development phase. However, once the H5 is launched, it will be more troublesome to report an error. Moreover, it is even more difficult to find problems for webpages that rely on the APP environment to run. Wouldn't it be nice if mobile terminals also had tools similar to Chrome DevTools?

[[206554]]

vConsole is such a great mobile DevTools tool, produced by the big company Penguin. But this article positions it as the second male lead, and today's protagonist is: Erdua! The same kind of vConsole. If you don't know how to debug web pages on mobile terminals, then this article will be very helpful to you. If you are a vConsole user, then you can also try Erdua. If you are a hardcore mobile web development player, then you can choose to ignore this article in a low-key manner.

Who is Erdua?

Hello everyone, let me introduce to you, this is my... Eruda is a debugging panel designed for mobile web front-ends, similar to a mini version of DevTools. Its main functions include: capturing console logs, checking element status, displaying performance indicators, capturing XHR requests, displaying local storage and cookie information, browser feature detection, etc.

The GitHub address is: https://github.com/liriliri/eruda, Erdua has great looks and skills:

Tips

This is the focus of this article.

The basic usage of Erdua is recommended to use CDN and configurable parameters. Introduce the following code on the page:

  1. ;( function (){
  2. var src = '//cdn.bootcss.com/eruda/1.2.4/eruda.min.js' ;
  3. if (!/eruda= true /.test(window.location) && localStorage.getItem( 'active-eruda' ) != 'true' ) return ;
  4. document.write( '<scr' + 'ipt src="' + src + '"></scr' + 'ipt>' );
  5. document.write( '<scr' + 'ipt>eruda.init();</scr' + 'ipt>' );
  6. })();

eruda.init(); You can pass in which panels to initialize, and all are loaded by default.

There is nothing wrong with this usage, but if Erdua is to be released online, then we should delete this code? Because in this way, Erdua will be loaded immediately regardless of whether you need to debug it or not, and the Erdua icon will appear on the page. My goal is that Erdua can be kept on the page, no matter what the environment is, it will appear only when we want it to appear, and when it is not needed, it is just a normal code that will not take effect.

The solution I thought of is: first put the src of the above imported code into the if, and change localStorage to sessionStorage. The active-eruda parameter can also be changed to a shorter name. The modified code is as follows:

  1. ;( function (){  
  2. if (!/eruda= true /.test(window.location) || sessionStorage.getItem( 'eruda' ) != '0' ) return ;  
  3. var src = '//cdn.bootcss.com/eruda/1.2.4/eruda.min.js' ;  
  4. document.write('  
  5. document.write('  
  6. })();

This code means that Erdua will be loaded only if the URL has the parameter eruda=true or the value of eruda in sessionStorage is greater than 0. The advantage of this is that when we need to debug, we can just add a parameter after the webpage URL, and it will not be loaded if debugging is not required.

However, this is fine in the development stage, but adding URL parameters may be troublesome in the online environment. So I thought of clicking an element on the page 10 times to load Erdua, click 10 times or more, then write eruda=yes in sessionStorage, and then refresh the current page. Conversely, click 10 more times to close Erdua. This more hidden way to turn Erdua on or off, so that the online environment can also turn Erdua on or off freely.

Example: If there is a page like this, there is a title text

  1. <h2>——Rules Details——</h2>
  2. <div>
  3. .....
  4. </div>

Then we can bind a click event to the h2 tag and add a method called showErdua

  1. <h2onclick= "showErdua" >——Rules details——</h2>
  2. <div>
  3. .....
  4. </div>
  5.  
  6. <script>
  7. var count = 0;
  8. function showErdua(){
  9. if ( count >= 10) {
  10. var erdua = sessionStorage.getItem( 'erdua' );
  11. if (!erdua || erdua === 'no' ){
  12. sessionStorage.setItem( 'eruda' , 'yes' )
  13. } else {
  14. sessionStorage.setItem( 'eruda' , 'no' )
  15. }
  16. location.reload()
  17. }
  18. count ++
  19. }
  20. </script>

In this way, you can call up Erdua by clicking the rule details 10 times, and close Erdua by clicking it 10 more times. Anyway, I think this is pretty good.

I don't know how everyone uses it?

<<:  Recommend several useful Linux e-book readers (Part 1)

>>:  On Android, what should a complete UDP communication module look like?

Recommend

21 questions and answers about Android View event mechanism

[[178693]] 1.What are the main coordinate paramet...

2021 social e-commerce gameplay guide!

Nowadays, more and more mobile Internet products,...

Baidu bidding promotion account optimization, how to optimize Baidu promotion?

How to grab traffic when placing Baidu bidding ad...

Operation system [Introduction]: How to do promotion and marketing?

Today I will talk about three points: 1. Third-pa...

New Channel for App Store Promotion: Mobile Video Advertising

As App promotion channels mature, CPs and publish...

The “User Cultivation” Model on the Internet (I)

Have you ever thought that you are being "cu...

Community operation, what exactly is it?

I have been engaged in community operations for P...

Why do men in TV dramas bleed from their noses when they see beautiful women?

This article was reviewed by Tao Ning, PhD, Assoc...

Rare! Very beautiful! 丨Base construction

Review expert: Gu Mingdi Lian (He Lin), a well-kn...

The correct way to open Zhihu promotion marketing

Zhihu 's algorithm is designed to help high-q...