A method, device, equipment and medium for accurately and directionally collecting HTTP response
By embedding a proxy layer in the browser kernel network layer, accurate, seamless, and zero-latency collection of HTTP responses is achieved, solving the problems of low signal-to-noise ratio and easy platform detection in existing technologies, and improving data analysis efficiency and the authenticity of collection.
Patent Information
- Application Number
- CN202611109558.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-24
- Publication Date
- 2026-11-24
AI Technical Summary
Existing technical solutions suffer from problems such as low signal-to-noise ratio, high resource consumption, easy platform detection, and complex configuration in browser HTTP response data collection, making it difficult to achieve accurate and seamless cross-domain interface data collection.
By embedding a proxy layer in the browser kernel network layer, the target interface response is intercepted through URL regular expression matching and Content-Type prefix comparison. A Tee data replication pipeline design is adopted to achieve zero-latency and seamless data collection, and support fallback collection of abnormal status codes.
It achieves accurate collection of target interface responses, reduces log volume, ensures data authenticity, avoids platform detection, supports cross-domain requests, reduces operation and maintenance costs, and does not affect page loading sequence.
Smart Images

Figure CN123157964A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of browser technology, and in particular to a method, apparatus, device, and medium for accurately targeting and collecting HTTP responses. Background Technology
[0002] The fingerprint browser, based on the Chromium kernel, customizes browser environment features (such as Canvas, WebGL, and Navigator) to present an independent device environment for each instance on the target platform. It is primarily used for scenarios such as multi-account operation in cross-border e-commerce and ad verification. In actual operation, the target platform will send risk control signals or trigger CAPTCHAs through specific HTTP interfaces. The development team needs to obtain the response content of these interfaces in real time to analyze the platform's environment detection strategy and optimize fingerprint configuration parameters.
[0003] Currently, there are several main ways to obtain browser HTTP response data: Method 1: Full web log crawling Using the `--log-net-log` startup parameter provided by the browser writes detailed information about all network requests to a log file. The problem with this method is the excessive log volume—a single normal browsing operation can generate hundreds of megabytes of logs, with the target interface's response buried among irrelevant requests for images, fonts, scripts, etc., resulting in extremely low retrieval efficiency. When running multiple browser instances in batches, both disk I / O and storage space face significant pressure.
[0004] Method 2: Chrome DevTools Protocol (CDP) CDP is a debugging protocol officially provided by Chromium, which allows network request data to be obtained by opening a debug port. However, mainstream platforms such as Facebook and TikTok have the ability to detect debugging features such as window.cdc_*. Once a debug port is detected, the platform will change its behavior logic, and the obtained response will no longer be the result of the real environment, greatly reducing the value of data analysis. In addition, CDP uses an asynchronous callback mechanism to obtain the response body, which is prone to data loss in high-frequency interface scenarios.
[0005] Method 3: Browser extension or Service Worker Browser extensions can intercept network requests via the webRequest or declarativeNetRequest API, but they have the following drawbacks: First, extensions leave traces on objects such as navigator.plugins and chrome.runtime, which may be detected by the platform's fingerprinting strategy; second, Manifest V3 has limited the ability of extensions to read the response body. Service Workers, on the other hand, need to be actively registered by the page and cannot intercept cross-origin requests.
[0006] Method 4: External Proxy Server (MITM) This method involves deploying a man-in-the-middle proxy between the browser and the server to decrypt HTTPS traffic and obtain the response content. However, this approach requires a self-signed CA certificate, making deployment complex. Furthermore, platforms can detect the proxy's presence through certificate verification and proxy characteristics, which can compromise the accuracy of the collected results.
[0007] In summary, the existing technical solutions have the following technical defects: (1) The full log method has a low signal-to-noise ratio and high resource consumption; (2) The CDP solution introduces debugging features, which are easily detected by the platform, resulting in data distortion; (3) The extension and ServiceWorker solutions have obvious exposure traces and limited functionality; (4) The external proxy solution requires the installation of certificates, which is complex to deploy and also faces the risk of being detected by the platform. The core contradiction is that the existing solutions either have coarse collection granularity, interfering with the real environment, or cannot achieve accurate collection of cross-domain interfaces.
[0008] Therefore, there is an urgent need for a technical solution that is embedded in the browser kernel, completely unaware of the target platform, and accurately collects data only for specified interfaces, in order to solve the problem of the authenticity and accuracy of HTTP response collection in fingerprint browser scenarios. Summary of the Invention
[0009] The technical problem to be solved by this invention is to provide a method, apparatus, device and medium for accurate targeted collection of HTTP responses. By embedding a proxy layer in the browser kernel network layer, it is possible to achieve accurate, zero-latency and imperceptible targeted collection of HTTP responses of target interfaces without opening debugging ports or installing proxy certificates. It also automatically triggers fallback collection for abnormal status codes, effectively solving the technical problems of low signal-to-noise ratio, easy platform detection and complex configuration of existing solutions in fingerprint browser scenarios.
[0010] In a first aspect, the present invention provides a method for precisely targeting and collecting HTTP responses for use in Chromium-based browsers, comprising the following steps: Step S1: Read the external configuration file in the same directory as the browser executable file to obtain at least one collection rule; each collection rule contains at least a URL regular expression for matching the target HTTP response and a collection count threshold; Step S2: Insert a proxy factory into the network factory chain of the Browser process in the Chromium browser. The proxy factory is used to intercept all network responses sent to the rendering process. Step S3: When the proxy factory intercepts any network response, it first checks whether the HTTP status code of the network response belongs to the preset abnormal status code set. If it does, it jumps directly to step S5; otherwise, it matches and filters the network response according to the collection rules in the configuration file. If the network response does not match any collection rules, it is directly passed through to the rendering process and the step ends. If it matches a collection rule, it proceeds to step S4. Step S4: Increment the current collection count corresponding to the collection rule by one, and determine whether the collection count threshold has been reached. If it has been reached, mark the rule as invalid. Step S5: Create a data replication pipeline for the hit network response, and simultaneously send the response body data of the network response to the rendering process via the original pipeline, and write it to the memory buffer via the replication pipeline; when the network response transmission is completed, asynchronously write the acquisition record containing at least the response body data to persistent storage.
[0011] Secondly, the present invention provides an apparatus for precisely targeting and collecting HTTP responses for use in Chromium-based browsers, comprising: A configuration loading module is used to read external configuration files in the same directory as the browser executable file and obtain at least one collection rule; each collection rule contains at least a URL regular expression for matching the target HTTP response and a collection count threshold; The proxy injection module is used to insert a proxy factory into the network factory chain of the browser process in the Chromium browser. The proxy factory is used to intercept all network responses sent to the rendering process. The rule matching module is used to check whether the HTTP status code of any network response belongs to the preset abnormal status code set when the proxy factory intercepts any network response. If it does, the data collection module is directly triggered; otherwise, the network response is matched and filtered according to the collection rules in the configuration file. If the network response does not match any collection rules, it is directly passed to the rendering process and the module ends; if it matches a collection rule, the collection count update module is triggered. The data collection count update module is used to increment the current data collection count corresponding to the data collection rule by one, and determine whether the data collection count threshold has been reached. If it has been reached, the rule is marked as invalid. The data acquisition module is used to create a data replication pipeline for the hit network response, simultaneously sending the response body data of the network response to the rendering process via the original pipeline and writing it to the memory buffer via the replication pipeline; when the network response transmission is completed, the acquisition record containing at least the response body data is asynchronously written to persistent storage.
[0012] Thirdly, the present invention provides an electronic device including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the method described in the first aspect.
[0013] Fourthly, the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method described in the first aspect.
[0014] One or more technical solutions provided by this invention have at least the following technical effects or advantages: 1. This invention uses a configuration-driven URL regular expression matching and Content-Type prefix comparison mechanism to collect only the response data of the target interface, avoiding the massive amount of redundant logs generated by full packet capture of --log-net-log. The log volume is reduced from hundreds of MB to KB, greatly improving the efficiency of data analysis.
[0015] 2. This invention embeds a proxy layer into the browser process network factory chain within the Chromium kernel. It does not open any debugging ports, inject any debugging features (such as window.cdc_*), install third-party certificates, or modify objects like navigator.plugins or chrome.runtime. The data collection process is completed in a closed loop within the browser, and the target platform is unaware of the collection activity, thus ensuring that the obtained response data is completely consistent with the results in a real user environment. This is the core advantage of this solution compared to CDP and MITM proxies.
[0016] 3. This invention employs a Tee data replication pipeline design. While the response data is being sent normally to the rendering process via the original pipeline, it is also asynchronously written to the memory buffer via the replication pipeline. The rendering process can receive and process data normally without waiting for the acquisition side to complete any I / O operations, and the acquisition behavior has zero impact on the page loading sequence.
[0017] 4. This invention implements interception at the URLLoader layer, which is located at the bottom of the browser's network stack. All HTTP requests and responses sent via the network pass through this layer. Therefore, this solution can collect response data from any domain, including cross-domain requests, without being limited by the page's own registration scope, overcoming the shortcomings of Service Worker and extension solutions in intercepting cross-domain interfaces.
[0018] 5. This invention automatically skips rule matching and directly enters the data collection process for HTTP 400, 500, 503 and other abnormal status codes. Even if the user has not configured rules for the interface in advance, the abnormal situation can be preserved. Developers can later locate the root cause of the problem by reviewing the logs, solving the pain point of existing solutions that cause the loss of key information due to missing rule configuration.
[0019] 6. The collection rules of this invention are stored in a JSON configuration file in the same directory as the browser executable file. After modifying the configuration, the changes will take effect after restarting the browser. There is no need to modify the source code or recompile the browser, which reduces the operation and maintenance costs and the debugging threshold.
[0020] 7. This invention performs log writing operations asynchronously through a thread pool, without blocking I / O threads; the memory buffer limit for a single response body is 4MB to prevent memory overflow; the rule matching time is recorded with microsecond precision, which facilitates the assessment of the impact on concurrency performance when the rule set size increases, and provides observability assurance for large-scale deployment.
[0021] 8. The data collection service of this invention is managed through ProfileKeyedServiceFactory. Each Profile has an independent data collection service instance, while Guest Profiles do not create instances. In multi-account operation scenarios, the data collection configurations and data of each Profile are isolated from each other and do not interfere with each other. The proxy factory is automatically destroyed after all in-transit requests are completed, eliminating the risk of resource leakage.
[0022] The above description is merely an overview of the technical solution of the present invention. In order to better understand the technical means of the present invention and to implement it in accordance with the contents of the specification, and in order to make the above and other objects, features and advantages of the present invention more apparent and understandable, specific embodiments of the present invention are described below. Attached Figure Description
[0023] The present invention will be further described below with reference to the accompanying drawings and embodiments.
[0024] Figure 1 This is a flowchart of the method in Embodiment 1 of the present invention; Figure 2 This is a schematic diagram of the device in Embodiment 2 of the present invention. Detailed Implementation
[0025] The overall concept of the technical solution in this application embodiment is as follows: Insert a proxy layer into the network factory chain of Chromium's Browser process. Requests that match the rules go through the collection process, while other requests are completely transparent, with zero awareness of the platform.
[0026] 2.1 Configuring the Driver The rules are written in the url.json file located in the same directory as chrome.exe, in the following format: [ { "content-type": "application / json", "url": "^https: / / login\.example\.com / api / risk / verify", "count": 10 } ] The three fields are: content-type (prefix matching, empty indicates no type restriction), url (RE2 regular expression), and count (maximum number of times data is collected, 0 indicates unlimited, the rule will automatically stop after reaching the limit). Changes to the configuration will take effect after a restart; no browser recompilation is required.
[0027] 2.2 Proxy Layer Injection In `ChromeContentBrowserClient::WillCreateURLLoaderFactory`, `URLLoaderFactoryBuilder::Append()` is called to append the proxy factory to the end of the factory chain. Note that it is appended, not replaced; the original CORS, HSTS, and cookie handling are all preserved, and from a network behavior perspective, it is exactly the same as without a proxy layer.
[0028] 2.3 Data Acquisition Process When each network request arrives, the process is as follows: ① Two-stage filtering: Content-Type prefix comparison (O(k) complexity) → RE2 regular expression matching of URL.
[0029] Miss: Pass directly through, end.
[0030] HTTP 400 / 500 / 503: No rules are checked, and data is collected directly (as a fallback).
[0031] ② Create a Tee pipe: Create a pair of Mojo DataPipes (write end tee_sink_ / read end renderer_consumer). Immediately hand over the reading end to the rendering process—the rendering side does not wait, receives data normally, and the loading sequence remains unchanged.
[0032] ③ Asynchronous consumption: SimpleWatcher listens to the raw network pipe and reads data as soon as it becomes available. Simultaneously write to tee_sink_ (received during rendering) and append to the memory buffer captured_body_. Maximum size 4 MB, data will be discarded if it exceeds this limit.
[0033] ④ After completing the network pipeline EOF collection, record the URL, status code, Content-Type, response body, request headers, and timestamp. It is sealed as a record and written to disk asynchronously via ThreadPool without blocking the I / O thread.
[0034] ⑤ Performance tracking: The time (in microseconds) for each rule match is asynchronously appended to p_time.log. Used to evaluate the impact of increasing rule set size on concurrent performance.
[0035] 2.4 Lifecycle Management The data collection service (UrlMonitorService) is managed through ProfileKeyedServiceFactory. It is initialized when a Profile is created and destroyed when the Profile is closed. Multiple Profiles do not interfere with each other, and Guest Profiles do not create instances. The proxy factory (UrlMonitorProxyFactory) is self-owned and is automatically destroyed when all Mojo Receivers are disconnected and all in-transit requests are completed.
[0036] Example 1 like Figure 1 As shown, this embodiment provides a method for precise targeted collection of HTTP responses for Chromium-based browsers, including the following steps: Step S1: Read the external configuration file in the same directory as the browser executable file to obtain at least one collection rule; each collection rule contains at least a URL regular expression for matching the target HTTP response and a collection count threshold; Step S2: Insert a proxy factory into the network factory chain of the Browser process in the Chromium browser. The proxy factory is used to intercept all network responses sent to the rendering process. Step S3: When the proxy factory intercepts any network response, it first checks whether the HTTP status code of the network response belongs to the preset abnormal status code set. If it does, it jumps directly to step S5; otherwise, it matches and filters the network response according to the collection rules in the configuration file. If the network response does not match any collection rules, it is directly passed through to the rendering process and the step ends. If it matches a collection rule, it proceeds to step S4. Step S4: Increment the current collection count corresponding to the collection rule by one, and determine whether the collection count threshold has been reached. If it has been reached, mark the rule as invalid. Step S5: Create a data replication pipeline for the hit network response, and simultaneously send the response body data of the network response to the rendering process via the original pipeline, and write it to the memory buffer via the replication pipeline; when the network response transmission is completed, asynchronously write the acquisition record containing at least the response body data to persistent storage.
[0037] In this embodiment, preferably, the configuration file in step S1 is a JSON format file; Each collection rule also includes a Content-Type prefix matching field; the matching filtering in step S3 is specifically as follows: first, the Content-Type prefix is compared with linear time complexity, and then the URL regular expression is matched after the comparison is successful; when the collection count threshold is an integer greater than 0, it indicates the maximum number of collections allowed for the rule. When the number of collections for the rule is greater than or equal to the threshold, the rule becomes invalid; when the collection count threshold is 0, it indicates that there is no limit to the number of collections.
[0038] In this embodiment, preferably, in step S2, the URLLoaderFactoryBuilder::Append() method is called in the ChromeContentBrowserClient::WillCreateURLLoaderFactory callback to append the proxy factory to the end of the network factory chain, so as to retain the original CORS, HSTS and cookie processing logic.
[0039] In this embodiment, preferably, the data copying pipeline in step S5 is a pair of Mojo DataPipes, wherein the write end is held by the proxy factory for writing response body data, and the read end is consumed by the rendering process; the upper limit of the memory buffer is 4MB, and when the response body data exceeds this upper limit, the excess part is discarded; In step S5, SimpleWatcher asynchronously listens for data arrival events in the original network pipeline and synchronously executes the following when data arrives: reads data from the original pipeline and simultaneously writes the data to the write end of the data replication pipeline and the memory buffer. The collection record in step S5 includes at least: Uniform Resource Locator, HTTP status code, Content-Type, response body data, request header information, and collection timestamp; the asynchronous writing is performed in a non-I / O thread through a thread pool.
[0040] In this embodiment, preferably, the preset abnormal status code set includes at least HTTP 400, HTTP 500 and HTTP 503.
[0041] In this embodiment, preferably, it also includes step S6: each time the rule matching in step S3 is executed, the matching time is recorded with microsecond precision and asynchronously appended to the performance log file.
[0042] In this embodiment, preferably, the collection process is executed through a collection service managed by ProfileKeyedServiceFactory. The collection service is initialized when the browser profile is created and destroyed when the profile is closed. Multiple profiles are isolated from each other, and the Guest Profile does not create an instance of the collection service. The proxy factory has its own lifecycle and is automatically destroyed after all Mojo Receivers are disconnected and all in-transit requests are completed.
[0043] Based on the same inventive concept, this application also provides an apparatus corresponding to the method in Embodiment 1, as detailed in Embodiment 2.
[0044] Example 2 like Figure 2 As shown, this embodiment provides a device for precisely targeted collection of HTTP responses for Chromium-based browsers, including: A configuration loading module is used to read external configuration files in the same directory as the browser executable file and obtain at least one collection rule; each collection rule contains at least a URL regular expression for matching the target HTTP response and a collection count threshold; The proxy injection module is used to insert a proxy factory into the network factory chain of the browser process in the Chromium browser. The proxy factory is used to intercept all network responses sent to the rendering process. The rule matching module is used to check whether the HTTP status code of any network response belongs to the preset abnormal status code set when the proxy factory intercepts any network response. If it does, the data collection module is directly triggered; otherwise, the network response is matched and filtered according to the collection rules in the configuration file. If the network response does not match any collection rules, it is directly passed to the rendering process and the module ends; if it matches a collection rule, the collection count update module is triggered. The data collection count update module is used to increment the current data collection count corresponding to the data collection rule by one, and determine whether the data collection count threshold has been reached. If it has been reached, the rule is marked as invalid. The data acquisition module is used to create a data replication pipeline for the hit network response, simultaneously sending the response body data of the network response to the rendering process via the original pipeline and writing it to the memory buffer via the replication pipeline; when the network response transmission is completed, the acquisition record containing at least the response body data is asynchronously written to persistent storage.
[0045] In this embodiment, preferably, the configuration file in the configuration loading module is a JSON format file; each collection rule also includes a Content-Type prefix matching field; the matching filtering in the rule matching module specifically involves: first performing Content-Type prefix comparison with linear time complexity, and then performing URL regular expression matching after the comparison passes; when the collection count threshold is an integer greater than 0, it indicates the maximum allowed number of collections for the rule, and the rule becomes invalid when the number of collections for the rule is greater than or equal to the threshold; when the collection count threshold is 0, it indicates that there is no limit to the number of collections.
[0046] In this embodiment, preferably, in the proxy injection module, the URLLoaderFactoryBuilder::Append() method is called in the ChromeContentBrowserClient::WillCreateURLLoaderFactory callback to append the proxy factory to the end of the network factory chain, so as to retain the original CORS, HSTS and cookie processing logic.
[0047] In this embodiment, preferably, the data replication pipeline in the data acquisition module is a pair of MojoDataPipes, wherein the write end is held by the proxy factory for writing response body data, and the read end is consumed by the rendering process; the upper limit of the memory buffer is 4MB, and when the response body data exceeds this upper limit, the excess part is discarded; The data acquisition module asynchronously listens for data arrival events in the original network pipeline using SimpleWatcher, and synchronously executes the following when data arrives: reads data from the original pipeline, and simultaneously writes the data to the write end of the data replication pipeline and the memory buffer. The data acquisition module contains at least the following data in its acquisition records: Uniform Resource Locator (URI), HTTP status code, Content-Type, response body data, request header information, and acquisition timestamp; the asynchronous writing is performed in a non-I / O thread using a thread pool.
[0048] In this embodiment, preferably, the preset abnormal status code set includes at least HTTP 400, HTTP 500 and HTTP 503.
[0049] In this embodiment, preferably, it also includes a performance tracking module, which records the matching time with microsecond precision and asynchronously appends it to the performance log file each time the rule matching in the rule matching module is executed.
[0050] In this embodiment, preferably, the collection process is executed through a collection service managed by ProfileKeyedServiceFactory. The collection service is initialized when the browser profile is created and destroyed when the profile is closed. Multiple profiles are isolated from each other, and the Guest Profile does not create an instance of the collection service. The proxy factory has its own lifecycle and is automatically destroyed after all Mojo Receivers are disconnected and all in-transit requests are completed.
[0051] Since the apparatus described in Embodiment 2 of the present invention is an apparatus used to implement the method of Embodiment 1 of the present invention, those skilled in the art can understand the specific structure and variations of the apparatus based on the method described in Embodiment 1 of the present invention, and therefore will not be described again here. All apparatuses used in the method of Embodiment 1 of the present invention fall within the scope of protection of the present invention.
[0052] Based on the same inventive concept, this application provides an electronic device embodiment corresponding to Embodiment 1, as detailed in Embodiment 3.
[0053] Example 3 This embodiment provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it can implement any of the implementation methods in Embodiment 1.
[0054] Since the electronic device described in this embodiment is the device used to implement the method in Embodiment 1 of this application, those skilled in the art can understand the specific implementation method and various variations of the electronic device in this embodiment based on the method described in Embodiment 1 of this application. Therefore, how the electronic device implements the method in the embodiment of this application will not be described in detail here. Any device used by those skilled in the art to implement the method in the embodiment of this application falls within the scope of protection of this application.
[0055] Based on the same inventive concept, this application provides a storage medium corresponding to Embodiment 1, as detailed in Embodiment 4.
[0056] Example 4 This embodiment provides a computer-readable storage medium storing a computer program thereon. When the computer program is executed by a processor, it can implement any of the implementation methods in Embodiment 1.
[0057] Example 5 Login risk control interface abnormal response tracking This embodiment uses the login risk control interface data collection of a target platform (a cross-border e-commerce platform) under a fingerprint browser environment as an example to illustrate the specific implementation process of the present invention. When the platform detects abnormal login behavior, it returns a JSON response body containing the reason for rejection through the https: / / login.example.com / api / risk / verify interface. However, the page UI only displays "Login failed, please try again later" without showing the specific reason. The R&D team needs to collect the response body of this interface to analyze the risk control strategy and optimize the fingerprint configuration.
[0058] I. Configuration Phase The operations and maintenance personnel should create a url.json configuration file in the same directory as the browser's executable file (chrome.exe), with the following content: json [ { "content-type": "application / json", "url": "^https: / / login\\.example\\.com / api / risk / verify", "count": 20 } ] The content-type field specifies that only responses with the Content-Type header starting with application / json will be collected, using prefix matching; the url field is a RE2 regular expression used to precisely match the target interface; the count field is set to 20, indicating that this rule will collect a maximum of 20 times and will automatically expire after reaching the limit, avoiding the collection of too much redundant data.
[0059] After configuration, restart the browser for the configuration file to take effect. UrlMonitorService creates an instance through ProfileKeyedServiceFactory during browser profile initialization, loads and parses the rule set from the url.json file, and stores it in an in-memory data structure.
[0060] II. Request Initiation and Proxy Interception When a user logs in using the fingerprint browser instance, the browser sends a POST request to https: / / login.example.com / api / risk / verify.
[0061] The request is processed via the Chromium network stack. In the ChromeContentBrowserClient::WillCreateURLLoaderFactory callback, this invention appends the UrlMonitorProxyFactory (proxy factory) to the end of the network factory chain using the URLLoaderFactoryBuilder::Append() method. Because it is an append rather than a replacement, the original CORS, HSTS, cookie, and other processing logics are all retained. From a network behavior perspective, the browser is completely consistent with a regular browser without any data scraping tools installed.
[0062] When the server returns an HTTP response, the response data flows through the network factory chain and is intercepted by the proxy layer created by UrlMonitorProxyFactory.
[0063] III. Rule Matching and Decision Making The proxy layer receives an HTTP status code of 200, which does not belong to the abnormal status code set (400 / 500 / 503), so it enters the rule matching process.
[0064] The matching process consists of two stages: In the first stage, the proxy layer extracts the Content-Type value (e.g., application / json;charset=utf-8) from the response header and performs a prefix comparison with the content-type field (application / json) in the configuration file. This operation has linear time complexity, and the match is successful.
[0065] In the second phase, the proxy layer performs a RE2 regular expression match between the complete URL of this request (https: / / login.example.com / api / risk / verify?session_id=abc123) and the URL regular expression in the configuration (^https: / / login\\.example\\.com / api / risk / verify). If the match is successful, the rule has been hit.
[0066] Subsequently, the agent layer updates the number of times the rule has been collected from 0 to 1. The current value (1) is less than the threshold (20), and the rule continues to be effective.
[0067] IV. Data Acquisition and Dual-Path Distribution After the rule is matched, the proxy layer enters the data acquisition process. The core of this process is to create a Tee data replication pipeline, specifically by creating a pair of Mojo DataPipes: The writer (tee_sink_): held by the proxy layer, used to receive response body data read from the network pipeline.
[0068] The reader (renderer_consumer) is immediately handed over to the rendering process. The rendering process can consume data normally without waiting for subsequent operations from the acquisition side, and the page loading sequence is not affected.
[0069] The proxy layer asynchronously listens for readable events in the raw network pipeline (i.e., the data pipeline between the browser's underlying network stack and the rendering process) using SimpleWatcher. When the server response body arrives in batches, SimpleWatcher triggers a callback, and the proxy layer performs the following operations: (1) Read a piece of data (e.g., 4KB) from the original network pipe; (2) Synchronously write the data to tee_sink_ (Mojo DataPipe write end), and the data flows normally to the rendering process through this path; (3) The same data is appended to the memory buffer captured_body_ for subsequent persistent storage.
[0070] During the above process, the rendering process is always able to receive response data at the original rate, and the memory buffer writes on the acquisition side are performed entirely in a bypass, without causing any blockage to the main data stream. If the response volume exceeds the preset limit (4MB in this embodiment), the excess portion is directly discarded to avoid memory overflow.
[0071] V. Asynchronous disk writing and performance recording When the original network pipeline transmission is complete and an EOF (End-Of-File) signal is received, the proxy layer encapsulates the following information into a data acquisition record: Request URL: https: / / login.example.com / api / risk / verify?session_id=abc123; HTTP status code: 200; Content-Type: application / json; charset=utf-8; Complete response body: for example, {"code":1001,"msg":"IP location mismatch","data":null}; Request header information (key fields such as User-Agent, Accept-Language, etc.); Collect timestamps (accurate to milliseconds).
[0072] The captured data is asynchronously written to a disk file (e.g., capture.log) via a ThreadPool. The disk write operation is performed in a non-I / O thread, which does not block the browser's main thread or the network I / O thread.
[0073] Meanwhile, the total time taken from extracting Content-Type to completing regular expression matching in this rule matching process (e.g., 12 microseconds) is asynchronously appended to the performance log file p_time.log. The development team can periodically review this log to assess whether the matching step will become a performance bottleneck for concurrent requests when the rule set grows to hundreds of rules.
[0074] VI. Rule Lifecycle and Subsequent Data Collection After this data collection is completed, UrlMonitorService records the number of times this rule has been collected as 1. When the rule is hit for the 20th time, the proxy layer updates the number of collections from 19 to 20, determines that the threshold has been reached, and marks the rule as invalid. Thereafter, the matching engine will skip this invalid rule when traversing the rule set and will no longer match it, thus saving CPU overhead.
[0075] VII. Profile Switching and Resource Cleanup If a user closes the current profile or switches to another profile, UrlMonitorService detects the profile closure event through the ProfileKeyedServiceFactory management mechanism and automatically destroys the collection service instance corresponding to the current profile. All Mojo Receivers under this profile are disconnected. UrlMonitorProxyFactory automatically destroys its own instance after ensuring that all pending requests have been completed, releasing all held Mojo pipelines and memory buffer resources, eliminating the risk of memory leaks. The Guest Profile never creates a collection service instance.
[0076] 8. Verification of Abnormalities Suppose that one day, the platform's login risk control interface returns an HTTP 503 error due to an internal server-side error, and the development team has not yet configured rules for this interface in url.json. In this case, the proxy layer, in the first step of the rule matching process, checks that the status code belongs to the abnormal status code set (400 / 500 / 503), skips the rule matching process, and proceeds directly to the data collection step. The response body (e.g., an HTML page containing server-side exception stack trace information) is completely collected and written to disk. Developers can then retrieve the exception details when reviewing the logs later, without losing crucial debugging information due to missing rule configurations.
[0077] As can be seen from the above embodiments, the present invention achieves accurate, seamless, and zero-latency collection of HTTP responses from target interfaces by embedding a lightweight proxy in the Chromium kernel network layer. At the same time, it ensures the ability to preserve the scene in unexpected scenarios through an exception fallback mechanism, effectively solving the problem of the authenticity and reliability of HTTP response collection in fingerprint browser scenarios.
[0078] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0079] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0080] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0081] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0082] While specific embodiments of the present invention have been described above, those skilled in the art should understand that the specific embodiments described are merely illustrative and not intended to limit the scope of the present invention. Equivalent modifications and variations made by those skilled in the art in accordance with the spirit of the present invention should be covered within the scope of protection of the claims of the present invention.
Claims
1. A method for precise targeted collection of HTTP responses, characterized in that, For browsers using the Chromium engine, the following steps are included: Step S1: Read the external configuration file in the same directory as the browser executable file to obtain at least one collection rule; each collection rule contains at least a URL regular expression for matching the target HTTP response and a collection count threshold; Step S2: Insert a proxy factory into the network factory chain of the Browser process in the Chromium browser. The proxy factory is used to intercept all network responses sent to the rendering process. Step S3: When the proxy factory intercepts any network response, it first checks whether the HTTP status code of the network response belongs to the preset abnormal status code set. If it does, it jumps directly to step S5; otherwise, it matches and filters the network response according to the collection rules in the configuration file. If the network response does not match any collection rules, it is directly passed through to the rendering process and the step ends. If it matches a collection rule, it proceeds to step S4. Step S4: Increment the current collection count corresponding to the collection rule by one, and determine whether the collection count threshold has been reached. If it has been reached, mark the rule as invalid. Step S5: Create a data replication pipeline for the hit network response, and simultaneously send the response body data of the network response to the rendering process via the original pipeline, and write it to the memory buffer via the replication pipeline; when the network response transmission is completed, asynchronously write the acquisition record containing at least the response body data to persistent storage.
2. The method according to claim 1, characterized in that, The configuration file in step S1 is a JSON format file; each collection rule also includes a Content-Type prefix matching field; the matching filtering in step S3 is specifically as follows: first, Content-Type prefix comparison is performed with linear time complexity, and URL regular expression matching is performed after the comparison is successful; when the collection count threshold is an integer greater than 0, it indicates the maximum number of collections allowed for the rule, and the rule becomes invalid when the number of collections for the rule is greater than or equal to the threshold; when the collection count threshold is 0, it indicates that there is no limit to the number of collections.
3. The method according to claim 1, characterized in that, In step S2, the URLLoaderFactoryBuilder::Append() method is called in the ChromeContentBrowserClient::WillCreateURLLoaderFactory callback to append the proxy factory to the end of the network factory chain, so as to retain the original CORS, HSTS and cookie processing logic.
4. The method according to claim 1, characterized in that, The data copying pipeline in step S5 is a pair of MojoDataPipes, where the write end is held by the proxy factory for writing response body data, and the read end is consumed by the rendering process; the upper limit of the memory buffer is 4MB, and when the response body data exceeds this upper limit, the excess part is discarded; In step S5, SimpleWatcher asynchronously listens for data arrival events in the original network pipeline and synchronously executes the following when data arrives: reads data from the original pipeline and simultaneously writes the data to the write end of the data replication pipeline and the memory buffer. The collection record in step S5 includes at least: Uniform Resource Locator, HTTP status code, Content-Type, response body data, request header information, and collection timestamp; the asynchronous writing is performed in a non-I / O thread through a thread pool.
5. The method according to claim 1, characterized in that, The preset set of exception status codes includes at least HTTP 400, HTTP 500, and HTTP 503.
6. The method according to claim 1, characterized in that, It also includes step S6, where each time the rule matching in step S3 is executed, the matching time is recorded with microsecond precision and asynchronously appended to the performance log file.
7. The method according to claim 1, characterized in that, The data collection process is executed through the data collection service managed by ProfileKeyedServiceFactory. The data collection service is initialized when the browser profile is created and destroyed when the profile is closed. Multiple profiles are isolated from each other, and the Guest Profile does not create an instance of the data collection service. The proxy factory has its own lifecycle and is automatically destroyed after all Mojo Receivers are disconnected and all in-transit requests are completed.
8. A device for precisely targeted collection of HTTP responses, characterized in that, Browsers used with the Chromium engine include: A configuration loading module is used to read external configuration files in the same directory as the browser executable file and obtain at least one collection rule; each collection rule contains at least a URL regular expression for matching the target HTTP response and a collection count threshold; The proxy injection module is used to insert a proxy factory into the network factory chain of the browser process in the Chromium browser. The proxy factory is used to intercept all network responses sent to the rendering process. The rule matching module is used to check whether the HTTP status code of any network response belongs to the preset abnormal status code set when the proxy factory intercepts any network response. If it does, the data collection module is directly triggered; otherwise, the network response is matched and filtered according to the collection rules in the configuration file. If the network response does not match any collection rules, it is directly passed to the rendering process and the module ends; if it matches a collection rule, the collection count update module is triggered. The data collection count update module is used to increment the current data collection count corresponding to the data collection rule by one, and determine whether the data collection count threshold has been reached. If it has been reached, the rule is marked as invalid. The data acquisition module is used to create a data replication pipeline for the hit network response, simultaneously sending the response body data of the network response to the rendering process via the original pipeline and writing it to the memory buffer via the replication pipeline; when the network response transmission is completed, the acquisition record containing at least the response body data is asynchronously written to persistent storage.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the method as described in any one of claims 1 to 7.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the method as described in any one of claims 1 to 7.
