A method of optimizing loading traversal of browser capabilities
Patent Information
- Application Number
- CN202411108462.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-13
- Publication Date
- 2026-09-29
- Estimated Expiration
- 2044-08-13
AI Technical Summary
[0007]本发明的目的在于提供一种优化浏览器能力的加载遍历方法,以解决背景技术中提出的现有技术中存在补丁文件内容过多、需要在多个页面使用相同的替换规则时,需要重复编写多条规则,增加了工作量和维护成本的问题
[0028]本发明的目的是通过增加URL的模糊匹配功能来解决现有技术的这些缺点。通过引入正则匹配功能,可以更精确地匹配需要替换的页面,减少不必要的遍历和处理,从而降低内存占用和提高系统效率。同时,支持正则匹配也简化了替换规则的编写,减少了重复劳动,提高了系统的灵活性和可维护性。这项技术改进旨在优化系统性能,提升用户体验,以应对现有技术的不足之处。
Smart Images

Figure CN119106214B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of browser performance technology, specifically a loading traversal method for optimizing browser capabilities. Background Technology
[0002] Because the pages provided by clients may be incompatible with the current browser version or have inherent coding issues, they may fail to display or function correctly. To address this problem, the browser has developed a solution for dynamically replacing page content. This technology achieves compatibility and adaptation, ensuring that the client's pages display perfectly in various browsers, thus improving the user experience.
[0003] Existing technology: The content to be replaced is written into a dedicated patch file and encrypted. Then, the encrypted patch file is packaged into the client's APK. After the browser begins downloading the page document but before parsing it, a specific mechanism extracts and applies this encrypted patch file, enabling dynamic replacement of the page content. This process ensures that the page is fixed and optimized before rendering, thus providing a better user experience and page display effect.
[0004] The main drawbacks of existing technologies include:
[0005] 1. Regarding the issue of excessive patch file content, when the number of replacement rules stored in the process cache is large, it may lead to an increase in memory usage and a rise in the time complexity of traversal operations, thereby impacting system performance.
[0006] 2. Currently, the system can only perform exact matching and cannot perform fuzzy matching on URLs. This means that when the same replacement rule needs to be used on multiple pages, multiple rules need to be written repeatedly, increasing workload and maintenance costs. Summary of the Invention
[0007] The purpose of this invention is to provide a loading traversal method that optimizes browser capabilities, thereby solving the problems in the prior art mentioned in the background, such as excessive patch file content and the need to repeatedly write multiple rules when using the same replacement rules on multiple pages, which increases workload and maintenance costs.
[0008] To solve the above-mentioned technical problems, the technical solution adopted by the present invention is as follows:
[0009] A loading traversal method that optimizes browser capabilities includes the following steps:
[0010] Step S1: Create a browser (WebView), where the user calls the browser's provided interface to send configurations; and initialize the browser kernel.
[0011] Step S2: The plaintext patch file is encrypted using the private key, and the encrypted file is packaged into the APK. During browser operation, the encrypted patch file is read from the application's assets directory and decrypted. The file is restored to plaintext using the same private key. The browser kernel uses Chromium Vector as a cache table to store replacement rules and stores them in three different cache tables according to their type.
[0012] Step S3: Call `logUrl` to trigger a network request. The browser uses the network module to establish a connection with the server to which the URL belongs and sends a request message to the server. The request message includes the request method, URL address, and request header information. The server processes the request according to the request message and returns the corresponding response message. The response message includes the resource files required by the web page.
[0013] In step S4, the search engine will traverse the corresponding cache table according to the type to match, and then the search engine will parse the resource files respectively.
[0014] Step S5: When the user switches pages or performs interactive operations, repeat steps S3 and S4 to reload and render the new page content; and when the user exits the application, proceed to step S6.
[0015] Step S6: When exiting the application, the system triggers the release of WebView's resources and the destruction of kernel components, ending the process.
[0016] According to the above technical solution, in step S2, the original content includes several replacement rules, and the replacement rules include type, URL, source string and target string.
[0017] According to the above technical solution, in step S3, the resource files include HTML, CSS, and JavaScript files.
[0018] According to the above technical solution, in step S4, the search engine includes one or more of HTML Parser, CSS Parser, and V8 engine.
[0019] According to the above technical solution, in step S4, matching by traversing the corresponding cache table according to the type is specifically as follows:
[0020] Step S401: Determine if the file is being processed. If it is being processed, determine if the file's URL matches the URL in the Modify Item. If the match is successful, proceed to step S402; otherwise, proceed to step S403.
[0021] Step S402: Determine whether the content of the file being processed includes the source string in Modify Item. If so, replace the source string with the target string and proceed to step S404. If not, proceed to step S403.
[0022] Step S403, matching failed, indicating that the file does not need to be replaced.
[0023] Step S404: Repeat steps S401 and S402 to complete the traversal of the cache table.
[0024] According to the above technical solution, in step S401, the condition for a successful match is whether the URL of the file is exactly the same as the URL in ModifyItem, or whether the URL of the file satisfies the matching rules defined in ModifyItem.
[0025] According to the above technical solution, in step S6, the system calls the corresponding lifecycle methods to trigger the release of WebView resources and the destruction of kernel components, including using one or more of the onPause, onStop and onDestroy methods.
[0026] According to the above technical solution, triggering WebView's resource release and kernel component destruction includes stopping network requests, releasing memory, closing network connections, and terminating related processes.
[0027] Compared with the prior art, the present invention has the following beneficial effects:
[0028] The purpose of this invention is to address these shortcomings of existing technologies by adding fuzzy URL matching functionality. By introducing regular expression matching, the pages to be replaced can be matched more accurately, reducing unnecessary traversal and processing, thereby reducing memory consumption and improving system efficiency. Simultaneously, supporting regular expression matching simplifies the writing of replacement rules, reduces repetitive work, and improves system flexibility and maintainability. This technical improvement aims to optimize system performance and enhance user experience to address the deficiencies of existing technologies. Attached Figure Description
[0029] Figure 1 This is a schematic diagram illustrating the implementation process of the present invention. Detailed Implementation
[0030] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0031] Example 1
[0032] like Figure 1 As shown, a loading traversal method to optimize browser capabilities includes the following steps:
[0033] Step S1: Create a browser (WebView), where the user calls the browser's provided interface to send configurations; and initialize the browser kernel.
[0034] Step S2: The plaintext patch file is encrypted using the private key, and the encrypted file is packaged into the APK. During browser operation, the encrypted patch file is read from the application's assets directory and decrypted. The file is restored to plaintext using the same private key. The browser kernel uses Chromium Vector as a cache table to store replacement rules and stores them in three different cache tables according to their type.
[0035] Step S3: The `loadUrl` method is an interface provided by the browser used to load a specified URL address, i.e., open a webpage. Calling `loadUrl` triggers a network request. The browser uses its network module to establish a connection with the server containing the URL and sends a request message to the server. The request message includes the request method, URL address, and request header information. The server processes the request based on the request message and returns a corresponding response message, which includes the resource files required by the web page.
[0036] In step S4, the search engine will traverse the corresponding cache table according to the type to match, and then the search engine will parse the resource files respectively.
[0037] Step S5: When the user switches pages or performs interactive operations, repeat steps S3 and S4 to reload and render the new page content; and when the user exits the application, proceed to step S6.
[0038] Step S6: When exiting the application, the system triggers the release of WebView's resources and the destruction of kernel components, ending the process.
[0039] The method in this invention, by introducing a regular expression matching function that supports URLs, can more accurately match the pages that need to be replaced, avoid unnecessary traversal and processing, and improve the accuracy of the replacement rules.
[0040] By optimizing patch file content, memory usage was reduced, system performance was improved, and resource consumption was lowered. Optimized traversal efficiency and simplified rule writing made the system run more efficiently, improving overall browser page loading speed by 5%. Support for regular expression matching simplified the process of writing replacement rules, reduced repetitive work, improved work efficiency, and lowered maintenance costs.
[0041] Through the above optimization measures, the present invention can significantly improve system performance, speed up page loading, enhance user experience, and enable users to use the system more smoothly.
[0042] Example 2
[0043] This embodiment is a further refinement of Embodiment 1.
[0044] In step S2, the original content includes several replacement rules, which include type, URL, source string and target string.
[0045] In step S3, the resource files include HTML, CSS, and JavaScript files.
[0046] In step S4, the search engine includes one or more of the following: HTML Parser, CSS Parser, and V8 engine.
[0047] In step S4, the matching process involves traversing the corresponding cache table based on the type.
[0048] Step S401: Determine whether the file is being processed. If it is being processed, determine whether the URL of the file matches the URL in ModifyItem. If the match is successful, proceed to step S402; otherwise, proceed to step S403.
[0049] Step S402: Determine whether the content of the file being processed includes the source string in Mod i fy I tem. If so, replace the source string with the target string and proceed to step S404. If not, proceed to step S403.
[0050] Step S403, matching failed, indicating that the file does not need to be replaced.
[0051] Step S404: Repeat steps S401 and S402 to complete the traversal of the cache table.
[0052] In step S401, a successful match is determined by whether the file's URL is exactly the same as the URL in the Modify Item, or whether the file's URL conforms to the matching rules defined in the Modify Item. These matching rules are templates composed of a series of characters (numbers, letters, and underscores) and special characters (., +, *, \, etc.), used to verify whether the text to be matched conforms to the template. For example, if the defined URL rule is / path / to / \d+ / index.html, where \d+ can represent any number, then a URL conforming to this rule could be / path / to / 01 / index.html, while / path / to / at / index.html would not.
[0053] In step S6, the system calls the corresponding lifecycle methods to trigger the release of WebView resources and the destruction of kernel components, including the use of one or more of the onPause, onStop, and onDestroy methods.
[0054] Triggering resource release and kernel component destruction in WebView includes stopping network requests, releasing memory, closing network connections, and terminating related processes.
[0055] Example 3
[0056] This embodiment provides a specific implementation method.
[0057] Step 1: Create a browser. Users can call the browser's provided interfaces to send configurations as needed, such as setting the window size and enabling caching.
[0058] During the initialization of the browser kernel, the system loads the WebView kernel module, initializes the runtime environment, provides communication interfaces for WebView, ensures that the WebView kernel can successfully load and render network resources, and performs security management to ensure that WebView runs stably in the application.
[0059] Step 2: The browser kernel reads the encrypted patch file from the Android application's assets directory and decrypts it to obtain the original content. This original content contains multiple replacement rules (ModifyItem), each rule consisting of a type (HTML, JavaScript, or CSS), URL, source string, and target string.
[0060] The kernel uses Chromium Vector as a cache table to store these rules, storing them in three different cache tables based on their type. This allows the kernel to directly traverse the corresponding cache table based on the type in subsequent operations, reducing unnecessary traversal time and enabling efficient page replacement operations without repeatedly reading and decrypting files, thus significantly improving the efficiency and performance of replacement operations.
[0061] Step 3: The browser actively loads the page via the `loadUrl` method, triggering the `net` module to send a request to the server to establish a connection and download the various resource files required for the web page (mainly HTML, CSS, and JavaScript files). This network and resource loading process is the first and essential step in web page loading and rendering. Once loading is complete, users can interact with the page, including clicking hyperlinks, filling out forms, etc., thereby browsing and manipulating the web page content.
[0062] Step 4: To adapt to and be compatible with the web pages provided by the client, after downloading the resources in Step 3, before the HTMLParser, CSSParser, and V8 engine parse these resource files, they will first traverse the corresponding cache table according to the type for matching:
[0063] 1. If the URL of the file being processed matches the URL in ModifyItem, proceed to step 2; otherwise, proceed to step 3.
[0064] 2. If the content of the file being processed contains the source string in ModifyItem, then replace the source string with the target string. This step is to ensure compatibility with the client-provided page so that it can be displayed perfectly; then proceed to step 4.
[0065] 3. If the match fails, it means that the file does not need to be replaced; proceed to step 4.
[0066] 4. If the cache table has not been completely traversed, repeat steps 1 and 2; otherwise, proceed to step 5.
[0067] Step 5: When the user switches pages or interacts with the application, repeat steps 3 and 4 to load and render the new page content; when the user exits the application, proceed to step 6.
[0068] Step Six: Exit the application. The system calls the corresponding lifecycle methods (including onPause, onStop, and onDestroy) to trigger the release of WebView's resources and the destruction of kernel components. This includes stopping network requests, releasing memory, closing network connections, and terminating related processes to ensure that resources are released and the corresponding processes are terminated, thereby avoiding memory leaks and performance issues.
[0069] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus.
[0070] Finally, it should be noted that the above descriptions are merely preferred embodiments of the present invention and are not intended to limit the present invention. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art can still modify the technical solutions described in the foregoing embodiments or make equivalent substitutions for some of the technical features. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A loading traversal method for optimizing browser capabilities, characterized in that: Includes the following steps: Step S1: Create a browser WebView; the user calls the browser's provided interface to send configurations; and initialize the browser kernel. Step S2: The plaintext patch file is encrypted using the private key, and the encrypted file is packaged into the APK. During browser operation, the encrypted patch file is read from the application's assets directory and decrypted. The file is then restored to plaintext using the same private key. The browser kernel uses Chromium Vector as a cache table to store replacement rules, and stores them in three different cache tables according to their type. The original content includes several replacement rules, which include type, URL, source string, and target string. Step S3: Call loadUrl to trigger a network request. The browser uses the network module to establish a connection with the server to which the URL belongs and sends a request message to the server. The request message includes the request method, URL address, and request header information. The server processes the request based on the request message and returns the corresponding response message, which includes the resource files required by the web page. In step S4, the search engine will traverse the corresponding cache table according to the type for matching, and then the search engine will parse the resource files respectively; the specific steps of traversing the corresponding cache table according to the type are as follows: Step S401: Determine if the file is being processed. If it is being processed, determine if the URL of the file matches the URL in ModifyItem. If the match is successful, proceed to step S402; otherwise, proceed to step S403. Step S402: Determine whether the content of the file being processed includes the source string in ModifyItem. If so, replace the source string with the target string and proceed to step S404. If not, proceed to step S403. Step S403, matching failed, indicating that the file does not need to be replaced. Step S404: Repeat steps S401 and S402 to complete the traversal of the cache table. Step S5: When the user switches pages or performs interactive operations, repeat steps S3 and S4 to reload and render the new page content; and when the user exits the application, proceed to step S6. Step S6: When exiting the application, the system triggers the release of WebView's resources and the destruction of kernel components, ending the process.
2. The loading traversal method for optimizing browser capabilities according to claim 1, characterized in that: In step S3, the resource files include HTML, CSS, and JavaScript files.
3. The loading traversal method for optimizing browser capabilities according to claim 1, characterized in that: In step S4, the search engine includes one or more of the following: HTML Parser, CSS Parser, and V8 engine.
4. The loading traversal method for optimizing browser capabilities according to claim 1, characterized in that: In step S401, a successful match is determined by whether the URL of the file is exactly the same as the URL in ModifyItem, or whether the URL of the file satisfies the matching rules defined in the URL in ModifyItem.
5. A loading traversal method for optimizing browser capabilities according to claim 1, characterized in that: In step S6, the system calls the corresponding lifecycle methods to trigger the release of WebView resources and the destruction of kernel components, including using one or more of the onPause, onStop, and onDestroy methods.
6. A loading traversal method for optimizing browser capabilities according to claim 5, characterized in that: Triggering WebView's resource release and kernel component destruction includes stopping network requests, releasing memory, closing network connections, and terminating related processes.
Citation Information
Patent Citations
File deleting method and file deleting device
CN102880713A
URL data mining method and system
CN110287428A