A mini-program code detection method, device and system

By dynamically running applet code, combined with browser engine and script language engine, the problem of inaccurate detection of applet codes in the existing technology is solved, and more accurate detection results are achieved.

CN114153511BActive Publication Date: 2025-08-22TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202010824595.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-08-17
Publication Date
2025-08-22
Estimated Expiration
2040-08-17

AI Technical Summary

Technical Problem

The existing technology of mini-program code detection methods cannot accurately determine the data at the code runtime, resulting in the inability to fully detect the standardization, security and reliability of mini-programs.

Method used

By dynamically running applet code, the browser engine and script language engine combine to obtain the dynamic code running results and match them with the preset target results to determine the detection results.

Benefits of technology

It realizes accurate detection of mini program code, can more accurately determine the matching between dynamic code operation results and detection tasks, and improves the accuracy and comprehensiveness of detection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114153511B_ABST
    Figure CN114153511B_ABST
Patent Text Reader

Abstract

The embodiments of the present application provide a method, device, and system for detecting mini-program code, which relate to the field of computer technology. The method includes: obtaining mini-program code detection data for a target mini-program, wherein the mini-program code detection data includes a code package of the target mini-program and a detection task; executing the code package according to the detection task to obtain a code execution result; and determining that the detection result of the mini-program code detection task is a pass upon determining that the code execution result matches a target result preset for the detection task. More accurate determination of whether the dynamic code execution result matches the target result preset for the detection task can also result in a more accurate detection result.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present invention relate to the field of computer technology, and in particular to a method, device, and system for detecting mini-program code. Background Art

[0002] With the development of the internet, various mini-programs and micro-programs have emerged. Mini-programs are a new open capability that allows developers to quickly develop a small program. They can be easily accessed and distributed within WeChat, while offering an excellent user experience. Apps that can be used without downloading or installing realize the dream of "apps at your fingertips." Users can open apps with a simple scan or search, embodying the "use and go" concept, eliminating the need to worry about installing too many apps.

[0003] Before a mini program is launched, the mini program code needs to be tested to determine the security of the mini program. Therefore, a method for accurately testing the mini program code is urgently needed. Summary of the Invention

[0004] The embodiments of the present application provide a method, device, and system for detecting mini-program code to accurately detect mini-program code.

[0005] In one aspect, an embodiment of the present application provides a method for detecting mini-program code, the method comprising:

[0006] Obtaining mini-program code detection data for a target mini-program, where the mini-program code detection data includes the target mini-program's code package and detection tasks;

[0007] According to the detection task, run the code package and obtain the code running results;

[0008] When it is determined that the code running result matches the target result preset in the detection task, the detection result of the mini program code detection task is determined to be detection passed.

[0009] In one aspect, an embodiment of the present application provides a mini-program code detection device, comprising:

[0010] An acquisition unit, configured to acquire mini-program code detection data for a target mini-program, wherein the mini-program code detection data includes a code package of the target mini-program and a detection task;

[0011] The code running unit is used to run the code package according to the detection task and obtain the code running results;

[0012] The detection result determination unit is used to determine that the detection result of the mini-program code detection task is a passed detection when it is determined that the code running result matches the target result preset in the detection task.

[0013] Optionally, the code includes logic layer code, and the detection task includes determining whether preset data information is included;

[0014] The code execution unit is specifically used for:

[0015] Calling the scripting language engine to run the logic layer code, determining the logic layer running data generated during the running of the logic layer code, and using the logic layer running data as the code running result;

[0016] The detection result determination unit is further configured to:

[0017] Determine the matching relationship between the logical layer operation data and the preset data information.

[0018] Optionally, the code also includes view layer code, and the detection task also includes determining whether preset web page information is included;

[0019] The code execution unit is specifically used for:

[0020] Calling the browser engine, running the view layer code, determining the view web page information generated during the running of the view layer code, and using the view web page information as the code running result;

[0021] The detection result determination unit is further configured to:

[0022] A matching relationship between the view web page information and preset web page information is determined.

[0023] Optionally, the detection task specifically includes determining whether each display page of the target applet includes preset web page information corresponding to each display page;

[0024] The code execution unit is also used to:

[0025] Calling the browser engine to run the view layer codes corresponding to the display pages of the target applet, determining the display page information of the target applet, and using the display page information as the code running result;

[0026] The detection result determination unit is specifically used for:

[0027] Determine a matching relationship between each display page information of the target applet and each corresponding preset web page information to obtain each first matching result;

[0028] A matching relationship between the view web page information and the preset web page information is determined according to the first matching results.

[0029] Optionally, the detection result determination unit is further configured to:

[0030] Obtain the detection record method corresponding to the detection task;

[0031] Record code execution results based on the detection recording method.

[0032] Optionally, the code execution unit is specifically used to:

[0033] The scripting language engine is called to parse the code package according to the detection task to obtain the logic layer code and the logic layer code.

[0034] Optionally, the code execution unit is specifically used to:

[0035] After determining that the scripting language engine has parsed the view layer code corresponding to any target applet display page, the browser engine is called to run the view layer code.

[0036] Optionally, the code package also includes configuration information code;

[0037] The code execution unit is also used to:

[0038] Calling the scripting language engine to determine the configuration information code in the code package;

[0039] Call the browser engine to create a new browsing interface;

[0040] Based on the configuration information code, the newly created browsing interface is configured and initialized in the browser to obtain a configuration initialization interface;

[0041] Run the view layer code in the configuration initialization interface.

[0042] Optionally, the browser engine is a headless browser engine, the scripting language engine is a JavaScript engine, and the headless browser engine and the JavaScript engine communicate with each other through inter-process communication.

[0043] On the one hand, an embodiment of the present application provides a mini-program code detection system, the system comprising: a detection module, a browser engine, and a scripting language engine;

[0044] The detection module is used to issue a mini-program code detection task, which at least includes mini-program code detection data for a target mini-program;

[0045] The browser engine is used to obtain applet code detection data for the target applet, where the applet code detection data includes the target applet's code package and detection tasks;

[0046] The browser engine and the scripting language engine are used to run the code package of the target applet and obtain the code running results;

[0047] The detection module is also used to determine that the detection result of the mini-program code detection task is a passed detection when it is determined that the code running result matches the target result preset in the detection task.

[0048] Optionally, the detection task specifically includes determining whether each display page of the target applet includes preset web page information corresponding to each display page;

[0049] Browser engines are specifically used to:

[0050] Run the view layer codes corresponding to the display pages of the target applet, determine the display page information of the target applet, and use the display page information as the code running result;

[0051] The detection module is specifically used for:

[0052] Determine a matching relationship between each display page information of the target applet and each corresponding preset web page information to obtain each first matching result;

[0053] A matching relationship between the view web page information and the preset web page information is determined according to the first matching results.

[0054] Optionally, the detection module is further configured to:

[0055] Obtain the detection record method corresponding to the detection task;

[0056] Record code execution results based on the detection recording method.

[0057] Optionally, the scripting language engine is also used to:

[0058] The scripting language engine is called to parse the code package according to the detection task to obtain the logic layer code and the logic layer code.

[0059] Optionally, the browser engine is used to:

[0060] After determining that the scripting language engine has parsed the view layer code corresponding to any target applet display page, the view layer code is run.

[0061] Optionally, the code package also includes configuration information code;

[0062] Scripting language engines are also used to:

[0063] Determine the configuration information code in the code package;

[0064] Browser engines are specifically used to:

[0065] Create a new browsing interface;

[0066] Based on the configuration information code, the newly created browsing interface is configured and initialized to obtain a configuration initialization interface;

[0067] Run the view layer code in the configuration initialization interface.

[0068] Optionally, the browser engine is a headless browser engine, the scripting language engine is a JavaScript engine, and the headless browser engine and the JavaScript engine communicate with each other through inter-process communication.

[0069] On the one hand, an embodiment of the present application provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the mini-program code detection method when executing the program.

[0070] On the one hand, an embodiment of the present application provides a computer-readable storage medium, which stores a computer program that can be executed by a computer device. When the program runs on the computer device, the computer device executes the applet code detection method.

[0071] On the one hand, an embodiment of the present application provides a computer program product, including a computer program or instructions. When the computer program or instructions are executed, at least one processor is enabled to execute the above-mentioned mini-program code detection method.

[0072] In an embodiment of the present application, detection data for the target applet that needs to be detected can be obtained. The detection data includes the code package of the target applet and the detection task. The code package in the detection data is the code of the target applet. The detection task is set for the target applet. The detection tasks corresponding to different target applet can be the same or different, which can realize dynamic and flexible configuration of the detection tasks.

[0073] And by running the code package according to the detection task, dynamic code running results can be obtained. These dynamic code running results are different from static codes and can obtain dynamic information, such as the calling relationship between codes, etc. Therefore, in the embodiment of the present application, it is possible to more accurately determine whether the dynamic code running results match the target results preset in the detection task, and more accurate detection results can also be obtained. BRIEF DESCRIPTION OF THE DRAWINGS

[0074] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0075] Figure 1 A schematic diagram of a scenario for static analysis of mini-program code in the prior art;

[0076] Figure 2 A schematic diagram of the structure of a mini-program code detection system provided in an embodiment of the present application;

[0077] Figure 3 A schematic diagram of the structure of a mini-program code detection system provided in an embodiment of the present application;

[0078] Figure 4 A schematic diagram of an application scenario corresponding to a mini-program code detection method provided in an embodiment of the present application;

[0079] Figure 5 A flowchart of a method for detecting mini-program code provided in an embodiment of the present application;

[0080] Figure 6 A flowchart of a method for detecting mini-program code provided in an embodiment of the present application;

[0081] Figure 7 A schematic diagram of the recorded content of a mini-program code detection provided in an embodiment of the present application;

[0082] Figure 8 A schematic diagram of the recorded content of a mini-program code detection provided in an embodiment of the present application;

[0083] Figure 9 A flowchart of a method for detecting mini-program code provided in an embodiment of the present application;

[0084] Figure 10 A schematic diagram of the structure of a mini-program code detection device provided in an embodiment of the present application;

[0085] Figure 11 A schematic structural diagram of a computer device provided in an embodiment of the present invention. DETAILED DESCRIPTION

[0086] In order to make the purpose, technical solutions and beneficial effects of this application more clear, the following further describes this application in detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain this application and are not intended to limit this application.

[0087] For ease of understanding, the terms involved in the embodiments of this application are explained below.

[0088] Mini Program: It is a new form of Internet application provided by WeChat. It focuses on the "use it and go" user experience. Users do not need to worry about the installation of the application. They can start the mini program by simply "scanning" or "searching".

[0089] Mini Program Development: Mini Programs provide a simple and efficient application development framework with a rich set of components and APIs, helping developers create services within WeChat that deliver a native app experience. During the mini program development process, developers edit code, generating a mini program code package upon completion. The mini program's runtime environment is divided into a view layer and a logic layer, so the mini program code package includes both view and logic layer code.

[0090] Browser engine: refers to a browser-based core tool. In the embodiment of the present application, the browser engine is a browser tool. The types of browser engines include ordinary browsers and headless browsers. A headless browser is a browser without a graphical user interface (GUI) and is usually controlled by programming or a command line interface. It can run directly on the server side and provide a service interface to the client. It is implemented through a command line interface or network communication. It can simulate real browser usage scenarios. Run UI-based browser tests without displaying the browser UI. The present application does not make specific limitations on the browser kernel of the browser engine. For example, the headless browser kernel of the present application can be Gecko (the kernel developed by the Firefox browser), Trident (the kernel developed by the IE browser), or Blink (the kernel developed by Google Chrome). In a preferred embodiment, the headless browser kernel used in the method of generating videos in the present application can be Webkit (the kernel developed by the Apple APPLE browser).

[0091] They are able to render and understand HTML in the same way as a browser, including style elements such as page layout, color, font selection, and the execution of JavaScript and AJAX.

[0092] Scripting language engine: refers to a tool for processing scripting languages. Different scripting language engines can be used for different scripting languages. For example, when processing JavaScript scripting language, a JavaScript scripting language engine can be used. An optional JavaScript scripting language engine is the V8 engine.

[0093] A process is a computer program's execution of a data set. It is the fundamental unit of resource allocation and scheduling, and the foundation of operating system architecture. By calling a process, you can access a subset of the functionality of an application or utility.

[0094] During the specific practice, the inventors of this application found that with the surge in mini-programs, an accurate and comprehensive detection method is needed to detect the mini-program code packages to ensure the standardization, security, reliability, etc. of the mini-programs during operation.

[0095] The inventors of this application first conceived a method for detecting mini-program code using static analysis. Without running the code, this code analysis technique scans the program code through lexical analysis, syntax analysis, control flow, and data flow analysis to verify whether the code meets standards such as compliance, security, reliability, and maintainability. Static analysis techniques can detect symbolic execution, abstract interpretation, and value dependency analysis in program code.

[0096] like Figure 1 As shown, in the prior art, after the developer submits the review, the mini program code will be displayed in the reviewer's client, and the reviewer will review the mini program code without running the code.

[0097] However, the inventors of this application further discovered that since static analysis technology does not run the mini-program code package, it cannot determine the data obtained when the code is running. For example, when the code is running, a request is triggered to the background and the request data is obtained. It is necessary to determine whether the request data meets the standardization, security, and reliability. Therefore, the static analysis detection method in the existing technology cannot accurately and comprehensively detect the mini-program code package.

[0098] Based on the above problems, a method for detecting applet code is proposed in the embodiment of the present application. By dynamically running the applet, accurate detection results can be obtained. Specifically, in the embodiment of the present application, detection data for the target applet that needs to be detected can be obtained. The detection data includes the code package of the target applet and the detection task. The code package in the detection data is the code of the target applet. The detection task is set for the target applet. The detection tasks corresponding to different target applets can be the same or different, which can realize dynamic and flexible configuration of the detection task.

[0099] And by running the code package according to the detection task, dynamic code running results can be obtained. These dynamic code running results are different from static codes and can obtain dynamic information, such as the calling relationship between codes, etc. Therefore, in the embodiment of the present application, it is possible to more accurately determine whether the dynamic code running results match the target results preset in the detection task, and more accurate detection results can also be obtained.

[0100] After introducing the design concepts of the embodiments of this application, the following briefly introduces the application scenarios to which the technical solutions of the embodiments of this application can be applied. It should be noted that the application scenarios introduced below are only used to illustrate the embodiments of this application and are not limiting. In specific implementations, the technical solutions provided by the embodiments of this application can be flexibly applied according to actual needs.

[0101] To further illustrate the technical solutions provided by the embodiments of the present application, the following is a detailed description of the technical solutions in conjunction with the accompanying drawings and specific implementation methods. Although the embodiments of the present application provide the method operation steps as shown in the following embodiments or drawings, more or fewer operation steps may be included in the method based on routine or no creative work. In steps where there is no necessary causal relationship logically, the execution order of these steps is not limited to the execution order provided in the embodiments of the present application.

[0102] refer to Figure 2 It is a mini-program code detection system applicable to the embodiment of the present application, including a detection module 201 and a code running module 202. Specifically, in the embodiment of the present application, the detection module 201 is used to send detection data, that is, to determine whether there is a mini-program code that needs to be detected. The detection data includes the code package of the target mini-program and the detection task.

[0103] The code running module 202 runs the code package according to the detection task to obtain the code running result. The detection module 201 determines the detection result based on the code running result and the preset target result.

[0104] In another optional embodiment, since the mini-program code package includes at least logic layer code and view layer code, when running the code, a tool that can run the logic layer code and the view layer code can be called.

[0105] like Figure 3 As shown, in the embodiment of the present application, the code execution module 202 includes a browser engine 20201 and a scripting language engine 20202. The browser engine 20201 is used to execute the view layer code, and the scripting language engine 20202 is used to execute the logic layer code.

[0106] In an embodiment of the present application, the detection module 201 sends the detection data to the browser engine 20201, the browser engine 20201 sends the detection data to the scripting language engine 20202, the scripting language engine 20202 performs code parsing, and sends the parsed view layer code to the browser engine 20201, and the browser engine 20201 runs the view layer code.

[0107] In an embodiment of the present application, after the browser engine 2201 and the scripting language engine 20202 run the code in the code package, the code running result can be obtained, and the detection result can be determined by the matching relationship between the code running result and the target result corresponding to the detection task.

[0108] Optionally, the test result may include two results: test passed or test failed.

[0109] In the above embodiment, the browser engine 20201 and the scripting language engine 20202 can communicate with each other through inter-process communication, and the inter-process communication can be IPC.

[0110] The detection module 201 can call the browser engine 20201 through a process. Similarly, the browser engine 20201 can call the scripting language engine 20202 through a process.

[0111] In the above embodiment, the browser engine 20201 can be a browser engine with a display interface or a headless browser engine, which is not limited here; the scripting language engine 20202 can be an engine of various scripting languages, such as a JavaScript engine, and specifically a V8 engine can be used.

[0112] like Figure 4 As shown, in the embodiment of the present application, an application scenario corresponding to the applet code detection method is also provided, and the application scenario includes at least M terminal devices 401 and a backend server 402, and the M terminal devices 401 are Figure 4 The terminal devices 401-1 to 401-M ​​shown in FIG, M is a positive integer, and the value of M is not limited in the embodiment of the present application.

[0113] The terminal device 401 is installed with a client, which is used to provide a development interface to the developer and display the development content based on the data provided by the backend server 402. The developer develops the mini-program based on the client.

[0114] The terminal device 401 may include one or more processors 4011, a memory 4012, an I / O interface 4013 for interacting with the backend server 402, and a display panel 4014. The terminal device 401 may be a smartphone, a tablet computer, a laptop computer, a desktop computer, a smart speaker, a smart watch, etc., but is not limited thereto.

[0115] The backend server 402 is capable of receiving data requests from the terminal device 401 and returning data. When the backend server 402 determines that the mini-program code package needs to be detected, it detects the code package and determines the detection result. The backend server 402 may include one or more processors 4021, a memory 4022, and an I / O interface 4023 that interacts with the terminal device 401. In addition, the backend server 402 may also be configured with a database 4024. The backend server 402 may be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms. The terminal device 401 and the backend server 402 can be directly or indirectly connected via wired or wireless communication, and this application is not limited here.

[0116] Developers can access the backend server 402 through the client installed in the terminal device 401, so that they can develop small programs in the client. When the developer completes the development, the detection data is sent to the backend server 402 through the terminal device 401. The backend server 402 performs detection based on the detection data and determines the detection results.

[0117] Of course, the method provided in the embodiment of the present application is not limited to Figure 2-Figure 4 The application scenarios shown can also be used in other possible application scenarios, and the embodiments of the present application are not limited thereto. Figure 2-Figure 4 The functions that can be implemented by each device in the application scenario shown will be described in subsequent method embodiments and will not be described in detail here.

[0118] The following describes the technical solutions provided by the embodiments of the present application in combination with the above application scenarios. Figure 5 As shown, specifically including:

[0119] Step S501: Obtain mini-program code detection data for a target mini-program. The mini-program code detection data includes a code package and a detection task of the target mini-program.

[0120] Specifically, in an embodiment of the present application, the mini program code detection data is edited and saved by the developer, and the mini program code detection data may be generated when the developer submits it for review.

[0121] In an embodiment of the present application, the applet that needs to be detected is taken as the target applet, and the code of the target applet constitutes a code package.

[0122] When conducting a test, you can configure a test task. The test task can be to determine whether the code in the code package is compliant and meets security requirements, etc., or to determine whether the interactive data in the code package is compliant and meets security requirements during operation, or the test task can be to determine whether the display interface of the target applet meets security requirements, etc.

[0123] The above are just some examples of the specific contents of the detection tasks. There are other specific contents of the detection tasks, which are not limited here.

[0124] Step S502: Run the code package according to the detection task to obtain a code running result.

[0125] In the embodiment of the present application, the code package is run according to the detection task. Different detection tasks may have different ways of running the code package and the obtained code running results may also be different.

[0126] For example, in an embodiment of the present application, the detection task may be targeted at the code level, and when the code package is run, all the codes may be run; or the detection task may be targeted at the code of certain set paragraphs, and the code of the set paragraphs may be run; in another optional embodiment, the detection task may be targeted at the various functional controls of the mini program, and the codes corresponding to the various functional controls may be run.

[0127] In an embodiment of the present application, the code execution result may include multiple data generated by the code during the execution process. For example, a request is sent during the code execution process, and the request is the code execution result. If feedback data is received, the feedback data is also the code execution result.

[0128] Step S503: When it is determined that the code running result matches the target result preset in the detection task, the detection result of the mini program code detection task is determined to be detection passed.

[0129] Specifically, in an embodiment of the present application, after obtaining the code running results, they are matched with the target results preset for the detection task. If they match, it can be determined that the detection result of the mini-program code detection task is passed. If they do not match, it can be determined that the detection result of the mini-program code detection task is failed.

[0130] The target result preset for a detection task is determined based on the specific detection task, and different detection tasks may have different target results. For example, if the detection task is to detect whether the information on each page of the target mini-program is secure, the target result may be that the information on each page of the mini-program is secure. In another optional embodiment, if the detection task is to detect whether the code of the target mini-program contains prohibited information, the target result may be that the mini-program code contains no prohibited information.

[0131] The target result corresponding to the detection task can be saved in advance, and the corresponding relationship between the target result and the detection task is saved. For example, if the detection task is the first detection task, the corresponding target result is determined to be the first target result based on the first detection task.

[0132] Alternatively, the target result preset in the detection task is stored in the detection data, and the target result is determined after the detection data is acquired.

[0133] The above steps briefly describe the detection method for mini program code packages. The following describes the detection process in detail.

[0134] In step S501 , since the development of a mini-program involves the development of the view layer and the development of the logic layer, there are at least view layer codes and logic layer codes in the code package.

[0135] The entire mini-program development framework is divided into two parts: the logic layer (App Service) and the view layer (View). Mini-programs offer their own view layer description languages, WXML and WXSS, as well as a JavaScript-based logic layer framework. They also provide data transmission and an event system between the view and logic layers, allowing developers to focus on data and logic.

[0136] The view layer is written in WXML and WXSS. Its function is to transform data from the logic layer into views and send events from the view layer to the logic layer. WXML is used to describe the structure of the page. WXS is a scripting language for mini-programs. Combined with WXML, it can build the page structure. WXSS is used to describe the page style. Components are the basic building blocks of views.

[0137] Therefore, the code package should at least include the WXML, WXSS, and WXS codes of the target applet.

[0138] Furthermore, the logic layer of the mini-program development framework uses a JavaScript engine to provide a runtime environment for developers' JavaScript code and the unique features of WeChat mini-programs. The logic layer processes data and sends it to the view layer, while also receiving event feedback from the view layer. Therefore, the code package also includes the logic layer code, namely JavaScript code.

[0139] Optionally, in the above embodiment, since the target applet is usually composed of multiple pages, the view layer code includes the code corresponding to each page in the target applet. Similarly, the logic layer code also includes the code corresponding to each page.

[0140] That is to say, in the embodiment of the present application, the code package includes at least the logic layer code and the view layer code of each page of the target applet.

[0141] In an optional embodiment, the code package is obtained based on the code package path, that is, the mini-program code detection data includes the code package path of the target mini-program, and the code package of the target mini-program can be obtained through the code package path.

[0142] In step S502, when the code package is run according to the detection task, a tool can be called to run the code. Since the developer used the applet development framework during the development process, and the applet development framework is part of the same core as the browser, the browser engine can be used to run the view layer code. The logic layer code is written in JavaScript, so it can be run through the scripting language engine.

[0143] In an optional embodiment, the code package needs to be parsed. The developer packages the code into a JavaScript file, so the code package is parsed by a scripting language engine to obtain logic layer code and view layer code.

[0144] In an embodiment of the present application, specifically, the view layer code includes the code corresponding to each page in the target applet, so a browser engine is used to run the code corresponding to each page in the target applet to obtain information about each page in the target applet.

[0145] Optionally, in an embodiment of the present application, since a scripting language engine needs to be called to parse the code package, after the scripting language engine parses the view layer code corresponding to any target applet display page, the browser engine is called to run the view layer code.

[0146] Exemplarily, the target applet includes page 1, page 2, and page 3. The scripting language engine parses the code package, obtains the view layer code and the corresponding logic layer code of page 1, sends the code of page 1 to the browser engine, and the browser engine runs the code of page 1 to obtain the view layer running result. At the same time, the scripting language engine runs the logic layer code to obtain the logic layer code running result.

[0147] In the embodiment of the present application, due to different detection tasks, it is possible to obtain only the view layer code running results, or only the logic layer code running results, or both the view layer code running results and the logic layer code running results.

[0148] In an optional embodiment, the browser engine can be called first to create a new browser interface, which can be a new tag interface. Then, the scripting language engine can be called to parse the code package to obtain the view layer code and the logic layer code. At the same time, since page configuration information is required when the browser engine is running, the code package also includes configuration information code. The scripting language engine is called to parse the code package to obtain the configuration information code. In the new tag interface of the browser engine, the configuration information is obtained according to the configuration information code, and the new tag interface is initialized to obtain the configuration initialization interface. The view layer code is run in the configuration initialization interface.

[0149] In the embodiment of the present application, after calling the browser engine to create a new tag interface, communication can be carried out through inter-process communication, so the process of calling the scripting language engine can be called through the browser engine. Figure 6 As shown, in Figure 6 In , the browser engine and the scripting language engine can communicate through inter-process communication.

[0150] After receiving the mini-program code detection data, the mini-program code detection data includes the code package path and detection tasks of the target mini-program. The detection tasks include a first detection task for the view layer code and a second detection task for the logic layer code.

[0151] The browser engine first creates a new tag interface, and then sends the code package path of the target applet and the second detection task to the scripting language engine. The scripting language engine obtains the code package of the target applet according to the code package path of the target applet, and then parses the configuration information code, logic layer code and view layer code related to the logic layer code.

[0152] Optionally, the first detection task may also be sent to a scripting language engine, and the scripting language engine parses the logic layer code and / or the view layer code based on the first detection task.

[0153] In an embodiment of the present application, the target applet includes multiple display pages, the scripting language engine parses the logic layer code, executes the logic layer code, determines the display page corresponding to the logic layer code, parses the view layer code corresponding to the display page, sends the configuration information code and the view layer code to the browser engine, and the browser engine runs the view layer code.

[0154] In an embodiment of the present application, after the view layer code of a display page is parsed using a scripting language engine, the view layer of the display page is sent to the browser engine, and the browser engine runs the view layer code.

[0155] In an embodiment of the present application, when the scripting language engine executes the logic layer code, it will execute all processing processes in the logic layer code, including calling processing processes and interacting with the network. For example, the logic layer code includes sending a data request to a third-party background server and receiving data returned by the third-party background server.

[0156] In an optional embodiment, when the scripting language engine runs the logic layer code, it runs the logic layer code corresponding to the second detection task. For example, the second detection task is to determine whether the interaction data between the logic layer code and the third-party server contains preset data information. After obtaining the second detection task, the scripting language engine can parse the logic layer code and run the logic layer code that interacts with the third-party server to obtain the code running result.

[0157] In another optional embodiment, when the browser engine runs the view layer code, it runs the view layer code corresponding to the first detection task. Therefore, when the scripting language engine parses the view layer code, it can send the view layer code corresponding to the first detection task to the browser engine based on the first detection task. The browser engine runs the view layer code corresponding to the first detection task and obtains the code running results.

[0158] Exemplarily, the detection content of the first detection task is to detect only the display style of the applet page. When the scripting language engine parses the view layer code, it sends the view layer code corresponding to the page display style to the browser engine. The browser engine runs the code to obtain the code running result.

[0159] In an embodiment of the present application, the first detection task can also be to detect the view layer code of a certain page of the mini program, so when the scripting language engine parses the code, it sends the view layer code of the page to the browser engine, and the browser engine runs the view layer code of the page to obtain the code running results.

[0160] Similarly, in the embodiment of the present application, the second detection task may also be to determine whether the logic layer code of the setting processing process has setting data information, so when the scripting language engine parses the code, it runs the setting processing process to obtain the code running result.

[0161] Furthermore, in an embodiment of the present application, when the browser engine runs the view layer code and obtains the running result of the view layer code and the script language engine runs the logic layer code and obtains the running result of the logic layer code, it is also necessary to determine whether there are logic layer codes for other pages for the mini program. If so, the script language engine parses the logic layer code. The script language engine first runs the logic layer code, determines which mini program page the logic layer code execution result points to, parses the view layer code of the mini program page, and sends the parsed view layer code to the browser engine. The browser engine runs the view layer code and obtains the view layer running result.

[0162] When it is determined that there is no logic layer code of other pages, it is determined that the detection task is completed and the detection result is determined.

[0163] In an embodiment of the present application, after obtaining the code execution result, the code execution result can also be recorded through the detection recording method corresponding to the detection task.

[0164] Exemplarily, the recording method corresponding to the first detection task is the first recording method, and the recording method corresponding to the second detection task is the second recording method. The first recording method and the second recording method may be the same or different.

[0165] In an embodiment of the present application, the recording method can be a screenshot method, wherein the screenshot method can take a screenshot of the entire mini program page, or can take a screenshot of a part of the page, for example, taking a screenshot of the part of the page that contains preset page information.

[0166] In another optional embodiment, the recording method may be to write the function call information generated during the execution of the logic layer code into the storage space, or to write the network data generated during the execution of the logic layer code into the storage space.

[0167] For example, in the embodiments of the present application, Figure 7 As shown, the content of the applet setting page is displayed. In the displayed page, the preset page information is included. This page information does not meet the detection requirements, so an optional embodiment records the entire page with the page information, that is, the entire page; another optional embodiment records the area with the page information, such as Figure 8 shown.

[0168] Specifically, the preset page information is "ancestral, suppressed, secret", Figure 7 The page shown includes the "ancestral" information. In an optional embodiment, the entire page information of the page is captured and recorded; in another optional embodiment, the line with the "ancestral" information is captured, and the following is obtained: Figure 8 The records shown.

[0169] In step S503, the content recorded by the recording method can also be used as the detection result, and the detection result can be returned. In the embodiment of the present application, if the target result is that the page does not include certain preset information, and the result of the view layer operation does not include certain preset information, then the detection result is determined to be a passed detection.

[0170] Likewise, if the result of the view layer operation includes certain preset information, the detection result is determined to be a failure.

[0171] When the test result is failure, the content recorded by the recording method can also be used as the test result. For example, if the test result is failure, the test result also includes screenshot information and data storage information.

[0172] After introducing the interaction process between the above-mentioned browser engine and the scripting language engine, a small program detection method is specifically introduced below. In the embodiment of this application, the browser engine is a headless browser, specifically Headless Chromium, and the scripting language engine is V8. The upstream issues the detection task. Specifically, the upstream can be a module that receives the detection task of the developer, so in the embodiment of this application, the upstream is the detection module.

[0173] In the embodiment of the present application, the communication process between Headless Chromium and V8 can be regarded as an inter-process call, and specifically communication can be carried out through Mojo in IPC.

[0174] The specific execution steps are as follows Figure 9 As shown, in Figure 9 In the test, the detection module, Headless Chromium and V8 jointly completed the detection task for the mini program.

[0175] The specific process is as follows:

[0176] Step S901: After the detection module obtains the detection data submitted by the developer, the detection module sends the detection data to the set port;

[0177] In step S902, Headless Chromium monitors the port and obtains detection data. In the embodiment of the present application, the detection data includes at least the path of the applet code package to be detected and the detection task;

[0178] In step S903, Headless Chromium receives the detection task and opens a new tab page to execute the webview layer code of the mini program, that is, the logic layer code;

[0179] Step S904: Headless Chromium creates a V8 process, and the two processes subsequently communicate through Mojo.

[0180] Step S905: Headless Chromium passes the applet code package path and the detection task to be executed to the V8 process;

[0181] Step S906: The V8 process reads the mini-program code based on the mini-program code package path;

[0182] Step S907: The V8 process parses the applet code to obtain the initial configuration information and public library code required for the webview layer code to run;

[0183] Step S908: The V8 process runs the logic layer code to determine the view layer code of the mini program page to be jumped to;

[0184] Step S908: Headless Chromium executes the public library code and webview layer code of the corresponding mini-program page, and jumps to the corresponding designated mini-program page;

[0185] Step S909: The V8 process sends the initial configuration information, view layer code (for specific pages), and public library code required for running the webview layer code to Headless Chromium.

[0186] Step S910: The V8 process performs a detection task to determine whether the network request meets the preset requirements and records the network request at the same time;

[0187] Step S911: Headless Chromium performs a detection task, which is to determine whether the page information contains preset information and intercept the page content;

[0188] Step S912: After the task is completed, Headless Chromium saves the task result;

[0189] Step S913, Headless Chromium notifies the V8 process that the task is completed;

[0190] Step S914: The V8 process saves the task result.

[0191] The above steps are the process of executing the logic layer code and view layer code of the mini program page once. If after step S914, the V8 process executes the logic layer code of other pages, the process returns to step S908.

[0192] If after step S914, the V8 process determines that there is no logic layer code for other pages, that is, the detection task has been performed on each page of the mini program, then step S915 is executed;

[0193] Step S915: The V8 process sends the task result to Headless Chromium.

[0194] In step S916 , Headless Chromium sends the V8 process task result and the Headless Chromium process task result to the detection module.

[0195] In the above embodiment, step S910 and step S911 can be performed simultaneously without any order of precedence. Similarly, step S913 and step S914 can be performed simultaneously without any order of precedence.

[0196] Based on the same concept, the present application also provides a detection device, such as Figure 10 Shown, including:

[0197] An acquisition unit 1001 is configured to acquire mini-program code detection data for a target mini-program, where the mini-program code detection data includes a code package of the target mini-program and a detection task;

[0198] The code execution unit 1002 is used to execute the code package according to the detection task and obtain the code execution result;

[0199] The detection result determination unit 1003 is used to determine that the detection result of the mini-program code detection task is a pass when it is determined that the code running result matches the target result preset in the detection task.

[0200] Optionally, the code includes logic layer code, and the detection task includes determining whether preset data information is included;

[0201] The code execution unit 1002 is specifically used for:

[0202] Calling the scripting language engine to run the logic layer code, determining the logic layer running data generated during the running of the logic layer code, and using the logic layer running data as the code running result;

[0203] The detection result determination unit 1003 is further configured to:

[0204] Determine the matching relationship between the logical layer operation data and the preset data information.

[0205] Optionally, the code also includes view layer code, and the detection task also includes determining whether preset web page information is included;

[0206] The code execution unit 1002 is specifically used for:

[0207] Calling the browser engine, running the view layer code, determining the view web page information generated during the running of the view layer code, and using the view web page information as the code running result;

[0208] The detection result determination unit 1003 is further configured to:

[0209] Determine the matching relationship between the view web page information and the preset web page information.

[0210] Optionally, the detection task specifically includes determining whether each display page of the target applet includes preset web page information corresponding to each display page;

[0211] The code execution unit 1002 is further configured to:

[0212] Call the browser engine, run the view layer code corresponding to each display page of the target applet, determine the display page information of the target applet, and use the display page information as the code running result;

[0213] The detection result determination unit 1003 is specifically configured to:

[0214] Determine the matching relationship between each display page information of the target applet and each corresponding preset web page information to obtain each first matching result;

[0215] A matching relationship between the view web page information and the preset web page information is determined according to each first matching result.

[0216] Optionally, the detection result determining unit 1003 is further configured to:

[0217] Obtain the detection record method corresponding to the detection task;

[0218] Record code execution results based on the detection recording method.

[0219] Optionally, the code execution unit 1002 is specifically configured to:

[0220] The scripting language engine is called to parse the code package according to the detection task to obtain the logic layer code and the logic layer code.

[0221] Optionally, the code execution unit 1002 is specifically configured to:

[0222] After determining that the scripting language engine has parsed the view layer code corresponding to any target applet display page, the browser engine is called to run the view layer code.

[0223] Optionally, the code package also includes configuration information code;

[0224] The code execution unit 1002 is further configured to:

[0225] Calling the scripting language engine to determine the configuration information code in the code package;

[0226] Call the browser engine to create a new browsing interface;

[0227] Based on the configuration information code, the newly created browsing interface is configured and initialized in the browser to obtain a configuration initialization interface;

[0228] Run the view layer code in the configuration initialization interface.

[0229] Optionally, the browser engine is a headless browser engine, the scripting language engine is a JavaScript engine, and the headless browser engine and the JavaScript engine communicate with each other through inter-process communication.

[0230] Based on the same technical concept, the embodiment of the present application provides a computer device, such as Figure 11 As shown, it includes at least one processor 1101 and a memory 1102 connected to the at least one processor. The specific connection medium between the processor 1101 and the memory 1102 is not limited in the embodiment of the present application. Figure 11 For example, the processor 1101 and the memory 1102 are connected via a bus. The bus can be divided into an address bus, a data bus, a control bus, and the like.

[0231] In an embodiment of the present application, the memory 1102 stores instructions that can be executed by at least one processor 1101. The at least one processor 1101 can execute the steps included in the aforementioned virtual machine backup method by executing the instructions stored in the memory 1102.

[0232] The processor 1101 is the control center of the computer device. It can connect the various parts of the computer device using various interfaces and lines, and create a virtual machine by running or executing instructions stored in the memory 1102 and calling data stored in the memory 1102. Optionally, the processor 1101 may include one or more processing units. The processor 1101 may integrate an application processor and a modem processor. The application processor mainly processes the operating system, user interface, and application programs, while the modem processor mainly processes wireless communications. It is understood that the modem processor may not be integrated into the processor 1101. In some embodiments, the processor 1101 and the memory 1102 may be implemented on the same chip. In some embodiments, they may also be implemented on separate chips.

[0233] The processor 1101 can be a general-purpose processor, such as a central processing unit (CPU), a digital signal processor, an application-specific integrated circuit (ASIC), a field programmable gate array or other programmable logic device, a discrete gate or transistor logic device, or a discrete hardware component, and can implement or execute the various methods, steps, and logic block diagrams disclosed in the embodiments of the present application. A general-purpose processor can be a microprocessor or any conventional processor. The steps of the method disclosed in conjunction with the embodiments of the present application can be directly embodied as being executed by a hardware processor, or can be executed by a combination of hardware and software modules in the processor.

[0234] Memory 1102 is a non-volatile computer-readable storage medium that can be used to store non-volatile software programs, non-volatile computer executable programs and modules. Memory 1102 may include at least one type of storage medium, such as a flash memory, a hard disk, a multimedia card, a card-type memory, a random access memory (Random Access Memory, RAM), a static random access memory (Static Random Access Memory, SRAM), a programmable read-only memory (Programmable Read Only Memory, PROM), a read-only memory (Read Only Memory, ROM), an electrically erasable programmable read-only memory (Electrically Erasable Programmable Read-Only Memory, EEPROM), a magnetic memory, a disk, an optical disk, etc. Memory 1102 is any other medium that can be used to carry or store a desired program code in the form of an instruction or data structure and can be accessed by a computer, but is not limited thereto. The memory 1102 in the embodiment of the present application can also be a circuit or any other device that can realize a storage function, for storing program instructions and / or data.

[0235] Based on the same inventive concept, an embodiment of the present application provides a computer-readable storage medium storing a computer program executable by a computer device. When the program runs on the computer device, the computer device executes the steps of the virtual machine backup method.

[0236] Those skilled in the art will appreciate that the embodiments of the present application can be provided as methods, systems, or computer program products. Therefore, the present application can adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application can adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.

[0237] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the present application. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0238] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.

[0239] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing the instructions executed on the computer or other programmable device for implementing the process. Figure 1 a process or multiple processes and / or boxes Figure 1 The steps for the function specified in one or more boxes.

[0240] Obviously, those skilled in the art may make various changes and modifications to this application without departing from the spirit and scope of this application. Thus, if these modifications and variations of this application fall within the scope of the claims of this application and their equivalents, this application is intended to include these modifications and variations.

Claims

1. A method for detecting applet code, characterized in that: The method comprises: Obtaining applet code detection data for a target applet, wherein the applet code detection data includes a code package of the target applet and a detection task; wherein the detection task includes a first detection task for view layer code; According to the detection task, the code package is run to obtain the code running result; When it is determined that the code running result matches the target result preset in the detection task, the detection result of the mini program code detection task is determined to be detection passed; The step of running the code package according to the detection task to obtain a code running result includes: Invoke a browser engine to create a new browsing interface, and send the code package path of the target applet to the scripting language engine; wherein the browser engine is a headless browser engine; According to the detection task, calling the scripting language engine, parsing the code package, and obtaining the configuration information code, logic layer code, and view layer code related to the logic layer code corresponding to the detection task; Based on the configuration information code, the newly created browsing interface is configured and initialized in the browser engine to obtain a configuration initialization interface; Invoking a browser engine in the configuration initialization interface, running the view layer code, determining view web page information generated during the running of the view layer code, and using the view web page information as the code running result; After obtaining the code running result, the following is also included: A matching relationship between the view web page information and preset web page information is determined.

2. The method according to claim 1, characterized in that The detection task also includes a second detection task for the logic layer code, wherein the second detection task specifically includes determining whether preset data information is included; The step of executing the code package according to the detection task to obtain a code execution result further includes: Invoking a scripting language engine to run the logic layer code, determining logic layer running data generated during the running of the logic layer code, and using the logic layer running data as the code running result; After obtaining the code running result, the following is also included: Determine a matching relationship between the logic layer operation data and the preset data information.

3. The method according to claim 1, characterized in that The first detection task specifically includes determining whether each display page of the target applet includes preset web page information corresponding to each display page; The calling of the browser engine, running the view layer code, and determining the view web page information generated during the running of the view layer code include: Invoke a browser engine to run the view layer codes corresponding to the display pages of the target applet, determine the display page information of the target applet, and use the display page information as the code running result; Determining the matching relationship between the view web page information and the preset web page information includes: Determine a matching relationship between each display page information of the target applet and each corresponding preset web page information to obtain each first matching result; A matching relationship between the view web page information and the preset web page information is determined according to the first matching results.

4. The method according to claim 3, characterized in that After obtaining the code running result, the following is also included: Obtaining a detection recording method corresponding to the detection task; The code execution result is recorded based on the detection recording method.

5. The method according to claim 1, wherein The calling of the browser engine and running of the view layer code includes: After determining that the scripting language engine has parsed the view layer code corresponding to any display page of the target applet, the browser engine is called to run the view layer code.

6. The method according to any one of claims 1 to 5, characterized in that The scripting language engine is a JavaScript engine, and the headless browser engine communicates with the JavaScript engine through an inter-process communication mode.

7. A small program code detection device, characterized in that: include: An acquisition unit, configured to acquire applet code detection data for a target applet, wherein the applet code detection data includes a code package of the target applet and a detection task; wherein the detection task includes a first detection task for view layer code; A code execution unit, configured to execute the code package according to the detection task and obtain a code execution result; A detection result determination unit, configured to determine that the detection result of the mini-program code detection task is a pass when it is determined that the code execution result matches the target result preset in the detection task; The code execution unit is specifically used for: Invoke a browser engine to create a new browsing interface, and send the code package path of the target applet to the scripting language engine; wherein the browser engine is a headless browser engine; According to the detection task, calling the scripting language engine, parsing the code package, and obtaining the configuration information code, logic layer code, and view layer code related to the logic layer code corresponding to the detection task; Based on the configuration information code, the newly created browsing interface is configured and initialized in the browser engine to obtain a configuration initialization interface; Invoke the browser engine in the configuration initialization interface, run the view layer code, determine the view web page information generated during the running of the view layer code, and use the view web page information as the code running result; The detection result determination unit is further configured to: A matching relationship between the view web page information and preset web page information is determined.

8. A mini-program code detection system, characterized in that: The system includes: a detection module, a browser engine and a scripting language engine; the browser engine is a headless browser engine; The detection module is used to issue a mini-program code detection task, wherein the mini-program code detection task includes at least mini-program code detection data for a target mini-program; wherein the detection task includes a first detection task for view layer code; The browser engine is used to obtain the applet code detection data for the target applet, wherein the applet code detection data includes the code package of the target applet and the detection task; The browser engine and the scripting language engine are used to run the code package of the target applet to obtain the code running result; The detection module is further configured to determine that the detection result of the mini-program code detection task is a pass when it is determined that the code running result matches the target result preset in the detection task; The browser engine is specifically used for: Create a new browsing interface and send the code package path of the target applet to the scripting language engine; The scripting language engine is specifically used for: Parsing the code package to obtain the configuration information code, logic layer code, and view layer code related to the logic layer code corresponding to the detection task; The browser engine is also used to: Based on the configuration information code, the newly created browsing interface is configured and initialized in the browser engine to obtain a configuration initialization interface; Running the view layer code in the configuration initialization interface, determining view web page information generated during the running of the view layer code, and using the view web page information as the code running result; The detection module is further configured to: A matching relationship between the view web page information and preset web page information is determined.

9. The system according to claim 8, characterized in that The detection task also includes a second detection task for the logic layer code, wherein the second detection task specifically includes determining whether preset data information is included; The scripting language engine is also used to: Running the logic layer code, determining logic layer operation data generated during the running of the logic layer code, and using the logic layer operation data as the code running result; The detection module is further configured to: Determine a matching relationship between the logic layer operation data and the preset data information.

10. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the steps of the method according to any one of claims 1 to 6 are implemented.

11. A computer-readable storage medium, characterized in that It stores a computer program that can be executed by a computer device. When the program is run on the computer device, the computer device executes the steps of the method according to any one of claims 1 to 6.

Citation Information

Patent Citations

  • A small program running method and device and a storage medium

    CN109032691A

  • Application program debugging method and device, terminal and storage medium

    CN110837473A