Go to Web Mobile app debugging tool--weinre

Source: Internet
Author: User

Now people are getting used to surfing the web on mobile phones, and the Web pages that are designed for desktop browsers are often miserable. Web application developers need to redesign the interface for the phone, but there is no satisfactory debugging tools (such as Firebug, Web Inspector) on the phone, and the redesign of the interface is often done with less effort. This article describes the debugging Tools Weinre is a good debugging tool to solve this problem.

What is Weinre?

Weinre represents the We b in Spector Re Mote, which is a remote debugging tool. For example, on a computer, you can instantly change the page element, style sheet, or view JavaScript variables on your phone, as well as see the error and warning messages on the page on your phone. Shown in the example, by running "Document.body.style.backgroundcolor = ' green ' in the console," instantly changes the background color of the page on the phone.

Figure 1: The debug client on the desktop and the corresponding page on the phone

Before using a tool, it is helpful to understand its rationale and structure. Weinre, as a remote debugging tool, is structurally divided into three layers:

    • Target page: The page is debugged, the page has been embedded weinre remote JS, the following will be introduced;
    • Debug client: Local Web Inspector Debug client;
    • Debug Service Side (Agent): An HTTP Server that establishes communication with the debug client for the target page.

The three-layer structure looks like this:

Figure 2:WEINRE Composition Structure

Weinre's debug client is based on Web Inspector Development, and the Web Inspector is only compatible with WebKit-centric browsers, so weinre clients can only be opened with Chrome or Safari.

Run Weinre

First you need to download weinre, Weinre currently supports Windows and MacOS, in this article, for example, Windows edition. After the download is complete, start the debug server for Weinre. Run the following command in the folder where the downloaded Weinre.jar is located:

Java-jar Weinre.jar--httpport 8081--boundhost-all-

This line of command initiates the Weinre debug server on the machine, with Port 8081. Open Chrome or Safari and visit localhost:8081 to see Weinre's basic information. (It is important to set Boundhost to-all-to access the debug server via IP)

The "Debug Client User Interface" in the Weinre is the debug clients, and you can see the target page that is not currently being tested when you click Enter.

How to make the webpage can be detected by the weinre on localhost:8081? Very simple, just add a JS file to the page surface. If the IP of this machine is 192.168.0.5, then add the following JS file. Target-script.js can get information from the debug server, change the current page style, or run the incoming JS, and return the results.

<script src= "Http://192.168.0.5:8081/target/target-script.js" ></script>

Note that for an asynchronous loading module such as Dojo, the above statically embedded JS will be incompatible, and in the case of an asynchronous loading module such as dojo, load target-script.js after the asynchronous loading is complete

Dojo.addonload (function () {
...
Dojo.create ("script", {
SRC: "Http://192.168.0.5:8081/target/target-script.js"
}, Dojo.body ());
})

When you open the page with the script added, you can see that the new target page is detected in the debug client.

We can then debug the remote page in the elements and console.

The corresponding HTML element in the debug client:

You can also view the JS object:

Reprint Source: http://blog.csdn.net/dojotoolkit/article/details/6280924

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.