Remote browser cluster control method, system, device and medium
Patent Information
- Application Number
- CN202611266263.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-20
- Publication Date
- 2026-10-13
AI Technical Summary
[0004]然而,WebDriver协议的设计为“一次会话一个浏览器”,会话结束后浏览器即被销毁,无法在多次任务间保留浏览器的页面状态、cookie和缓存
[0016]本申请实施例提供了远程浏览器集群控制方法、系统、设备及介质。一方面,本申请实施例可以通过业务标识在远程浏览器集群中确定与该业务标识关联的目标浏览器实例,相较于现有技术中每次会话结束后浏览器即被销毁的方案,显著减少了重复初始化操作带来的时间和计算成本。另一方面,本申请实施例通过通信链路上的数据交互活动监控实现空闲超时自动回收,有效防止了客户端异常退出或遗忘释放导致的僵尸浏览器堆积,保障了远程浏览器集群的资源利用率。
Smart Images

Figure CN122909236A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of Internet technology, and in particular to remote browser cluster control methods, systems, devices and media. Background Technology
[0002] With the rapid development of Robotic Process Automation (RPA) and web automation technologies, enterprises need to run dozens or even hundreds of browser instances simultaneously for automated operations in scenarios such as data acquisition, automated testing, and business process automation. These browser instances are typically deployed on remote servers in Kubernetes (K8s) or Docker clusters and are remotely controlled by clients over the network.
[0003] Selenium Grid is currently the most mainstream distributed browser management solution. It adopts a central node (Hub) - worker node (Node) architecture. The Hub receives client requests and distributes them to registered Node nodes. Selenium Grid is based on the WebDriver protocol system. Clients interact with WebDriver through HTTP requests, and WebDriver then drives the browser to perform operations.
[0004] However, the WebDriver protocol is designed for "one browser per session," meaning the browser is destroyed after the session ends, making it impossible to retain the browser's page state, cookies, and cache across multiple tasks. When business processes need to be interrupted and then resumed (such as step-by-step approvals or phased operations), the browser must be recreated, and navigation must be repeated, resulting in a large number of repetitive operations and wasting time and computing costs. Summary of the Invention
[0005] This application provides a remote browser cluster control method, system, device, and medium, which can reduce the operation time and computing cost of remote browsers by reusing browser instances.
[0006] In a first aspect, embodiments of this application provide a remote browser cluster control method, which includes: Receive a browser resource request initiated by a client, wherein the browser resource request carries a business identifier; The target browser instance is determined based on the service identifier and the instance status information of each browser instance in the remote browser cluster. Obtain the target network address of the target browser instance, and establish a target communication link between the client and the target browser instance based on the target network address; Control commands are sent to the browser instance via the target communication link to execute browser operations, and the control commands are triggered by the client. Monitor data interaction activities on the target communication link. When the difference between the most recent activity time and the current time of the data interaction activity exceeds a preset threshold, trigger a recycling operation. The recycling operation includes terminating the target browser instance and releasing the occupied resources.
[0007] In some embodiments, determining the target browser instance based on the service identifier and the instance status information of each browser instance in the remote browser cluster includes: Query whether there is target instance status information corresponding to the business identifier in the browser instance status database. The browser instance status database stores the instance status information of each browser instance in the remote browser cluster. If the target instance status information exists and the target instance status information indicates an idle state, then the browser instance corresponding to the target instance status information is determined as the target browser instance; If the target instance status information does not exist or the instance status information indicates a non-idle state, a new browser instance is created as the target browser instance, and the service identifier is associated with the instance status information of the new browser instance and stored in the browser instance status database.
[0008] In some embodiments, the method further includes: Each browser instance in the remote browser cluster reports its instance status information to the browser instance status database at preset time intervals. Each instance status information in the browser instance status database has a lifecycle. The instance status information of browser instances in normal operation is automatically renewed through continuous reporting, while the instance status information corresponding to terminated browser instances is automatically cleared after the lifecycle ends.
[0009] In some embodiments, establishing a target communication link between the client and the target browser instance based on the target network address includes: Detect the network connectivity between the client and the target network address; If the network is connected, a direct communication link is established between the client and the target browser instance as the target communication link; If the network is not connected, a target communication link is established between the client and the target browser instance through a proxy service.
[0010] In some embodiments, establishing the target communication link between the client and the target browser instance through a proxy service includes: Determine whether the proxy service stores a port mapping relationship between the target network address and the local listening port; If the port mapping relationship is stored, then the target communication link is established based on the port mapping relationship; If the port mapping relationship is not stored, an idle listening port is selected from the proxy service, and the port mapping relationship is constructed based on the idle listening port. The target communication link is then established based on the port mapping relationship.
[0011] In some embodiments, prior to triggering the recycling operation, the method further includes: Obtain the browser migration request sent by the client, save the user data directory of the target browser instance to external storage, and associate the user data directory with the business identifier for storage. The user data directory contains page state data, session credential data, and local cache data. When a new browser instance corresponding to the service identifier is launched, the corresponding user data directory is obtained from the external storage according to the service identifier, and the user data of the new browser instance is restored based on the user data directory.
[0012] In some embodiments, the method further includes: In response to the visualization viewing request initiated by the client, a visualization communication link is established between the client and the remote desktop server on the node where the target browser instance is located through the proxy service; The proxy service performs bidirectional transparent forwarding of remote desktop protocol data at the transport layer, and automatically releases the port resources occupied by the visual communication link when the client side of the visual communication link is detected to be disconnected.
[0013] Secondly, embodiments of this application also provide a remote browser cluster control system, the remote browser cluster control system comprising: The receiving unit is used to receive browser resource requests initiated by the client, wherein the browser resource requests carry a business identifier; An instance determination unit is used to determine a target browser instance based on the service identifier and the instance status information of each browser instance in the remote browser cluster. A link establishment unit is used to obtain the target network address of the target browser instance and establish a target communication link between the client and the target browser instance based on the target network address; An operation unit is configured to send control commands to the browser instance via the target communication link to execute browser operations, wherein the control commands are triggered by the client. The recycling unit is used to monitor data interaction activities on the target communication link. When the difference between the most recent activity time and the current time of the data interaction activity exceeds a preset threshold, a recycling operation is triggered. The recycling operation includes terminating the target browser instance and releasing the occupied resources.
[0014] Thirdly, embodiments of this application also provide a computer device, which includes a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the above-described method.
[0015] Fourthly, embodiments of this application also provide a computer-readable storage medium storing a computer program, the computer program including program instructions that, when executed by a processor, can implement the above-described method.
[0016] This application provides a remote browser cluster control method, system, device, and medium. On one hand, this application can determine the target browser instance associated with a service identifier within the remote browser cluster, significantly reducing the time and computational cost of repeated initialization operations compared to the prior art scheme where browsers are destroyed after each session. On the other hand, this application achieves automatic recycling of idle timeouts through monitoring data interaction activities on the communication link, effectively preventing the accumulation of zombie browsers caused by abnormal client exits or forgotten releases, and ensuring the resource utilization rate of the remote browser cluster. Attached Figure Description
[0017] To more clearly illustrate the technical solutions of the embodiments of this application, the drawings used in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0018] Figure 1 A flowchart illustrating the remote browser cluster control method provided in this application embodiment; Figure 2 A schematic diagram of a sub-process of the remote browser cluster control method provided in the embodiments of this application; Figure 3 This is another schematic diagram of a sub-process of the remote browser cluster control method provided in the embodiments of this application; Figure 4 A schematic block diagram of a remote browser cluster control system provided in an embodiment of this application; Figure 5 A schematic block diagram of a computer device provided in an embodiment of this application. Detailed Implementation
[0019] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this application. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0020] It should be noted that any AI models, software tools, or components not belonging to this company appearing in the embodiments of this application are merely illustrative examples and do not represent actual use. All user personal information involved in the embodiments of this application has been obtained by authorized entities (who have known and consented) or fully authorized by all parties through various legal and compliant means. The collection, storage, use, processing, transmission, provision, and disclosure of the information, data, and signals involved all comply with relevant laws and regulations and do not violate public order and good morals.
[0021] It should be understood that, when used in this specification and the appended claims, the terms "comprising" and "including" indicate the presence of the described features, integrals, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components and / or collections thereof.
[0022] It should also be understood that the terminology used in this application specification is for the purpose of describing particular embodiments only and is not intended to limit the application. As used in this application specification and the appended claims, the singular forms “a,” “an,” and “the” are intended to include the plural forms unless the context clearly indicates otherwise.
[0023] It should also be further understood that the term “and / or” as used in this application specification and the appended claims means any combination of one or more of the associated listed items and all possible combinations, and includes such combinations.
[0024] This application provides a remote browser cluster control method, system, device, and medium.
[0025] The execution entity of the remote browser cluster control method can be the remote browser cluster control system provided in the embodiments of this application, or a computer device that integrates the remote browser cluster control system. The remote browser cluster control system can be implemented in hardware or software, and the computer device can be a terminal or a server.
[0026] Figure 1 This is a flowchart illustrating the remote browser cluster control method provided in an embodiment of this application. Figure 1 As shown, the method includes the following steps S110-S150.
[0027] S110. Receive a browser resource request initiated by the client, wherein the browser resource request carries a business identifier.
[0028] In this embodiment, the client can be an RPA robot program or an automated test script, etc. When the client needs to execute browser automated tasks, it sends a browser resource request to the scheduling subsystem.
[0029] The request carries a business identifier, which is used to uniquely identify a logical business process or user session. This identifier can be, for example, a task sequence number, a user session ID, or a tenant identifier. The business identifier can be generated and maintained by the client (business system) and remains unchanged throughout a complete business process.
[0030] In some embodiments, when initiating the first request, the client generates a globally unique identifier (such as a UUID) as a business identifier and persists this identifier in a local database or configuration file. In subsequent reuse requests, the client reads this identifier and includes it in the browser resource request.
[0031] S120. Determine the target browser instance based on the service identifier and the instance status information of each browser instance in the remote browser cluster.
[0032] In this embodiment, after the remote browser cluster control system receives a browser resource request, it extracts a service identifier from the request and queries the instance status information of each browser instance in the remote browser cluster based on the service identifier to determine the target browser instance. The instance status information includes, but is not limited to: the browser instance's running status (running / stopped), its occupied status (idle / busy), the service identifier binding relationship, and the instance's network address.
[0033] In some embodiments, specifically, please refer to Figure 2 Step S120 includes S1201-S1203: S1201. Query the browser instance status database to see if there is target instance status information corresponding to the service identifier.
[0034] Specifically, the browser instance state database stores the instance state information of each browser instance in the remote browser cluster. In a specific implementation, the browser instance state database can use centralized storage such as Redis. After receiving a client resource request, the scheduling subsystem in the remote browser cluster control system extracts the business identifier from the request and uses this business identifier as an index to query the browser instance state database to determine if there is target instance state information corresponding to that business identifier.
[0035] S1202. If the target instance status information exists and the target instance status information indicates an idle state, then the browser instance corresponding to the target instance status information is determined as the target browser instance.
[0036] If the browser instance state database contains instance state information corresponding to the business identifier, and the occupancy status field in that state information indicates that the instance is currently idle, the scheduling subsystem identifies the browser instance corresponding to that instance state information as the target browser instance and assigns it to the current client. At this time, the current client reuses the browser instance, and the instance's page state, session credentials (cookies), local cached data, etc., are all retained. The client can directly continue its previous operations without re-executing the login and navigation process.
[0037] For example, after completing the first stage of form filling, client A actively disconnects (but does not destroy the browser) and saves the business identifier locally. Five minutes later, client A sends another request with the same identifier. The scheduling subsystem finds that the corresponding browser instance is still idle and directly assigns the instance to client A. After client A re-establishes the WebSocket connection, the browser page remains on the previously filled-out form page, and all the filled-in content is intact. Client A can directly click the submit button to complete subsequent operations.
[0038] S1203. If the target instance status information does not exist or the instance status information indicates a non-idle state, a new browser instance is created as the target browser instance, and the service identifier is associated with the instance status information of the new browser instance and stored in the browser instance status database.
[0039] In one embodiment, if the browser instance state database does not contain instance state information corresponding to the service identifier (i.e., the service identifier is being used for the first time, or the previously bound instance has been destroyed and its state information has expired and been cleared), the scheduling subsystem determines that a new browser instance needs to be created for the client. The system calls the browser creation interface to start a new browser process, generates a new instance identifier and network address, and then associates the service identifier with the instance state information of the new browser instance and stores it in the browser instance state database. Afterward, the service identifier is bound to the new instance.
[0040] In other embodiments, if the browser instance state database contains instance state information corresponding to the service identifier, but the occupancy status field in that state information indicates that the instance is currently in a non-idle state (i.e., being used by other clients), the scheduling subsystem also determines that a new browser instance needs to be created. In some embodiments, the system may also return a conflict warning, allowing the client to decide whether to wait for the original instance to be released or to create a new instance.
[0041] This embodiment achieves precise location and on-demand creation of browser instances. The association storage mechanism between business identifiers and browser instances ensures that the same client can be assigned to the same browser instance in multiple requests, thus achieving state continuity. Simultaneously, the binding relationship achieves natural data isolation, preventing requests from different business identifiers from being assigned to the same instance and avoiding data crosstalk and leakage risks. The introduction of the state database decouples the scheduling logic from the underlying infrastructure, giving the system good scalability.
[0042] Furthermore, after identifying the target browser instance, the scheduling subsystem reserves resources for that instance through atomic operations to prevent resource over-allocation when multiple clients make concurrent requests. In some embodiments, the atomic operation is a Redis DECR (decrement) operation or a SETNX (set if not present) operation. When the scheduling subsystem selects an idle instance for allocation, it decrements the idle count of that instance by one or sets an occupied flag through atomic operations. If the operation succeeds, it means that the resource reservation is successful; if the operation fails, it means that the instance has been taken by other concurrent requests, and the scheduling subsystem selects the next idle instance.
[0043] For example, in a concurrent scenario, if two clients simultaneously request browser resources, the scheduling subsystem selects the same idle instance from the state database to allocate to both. Through Redis atomic operations, only the first request that successfully executes DECR will acquire the allocation right for that instance. If the DECR operation of the second request fails, the scheduling subsystem will then allocate another idle instance or create a new instance for it. This mechanism ensures correct resource allocation in large-scale concurrent scenarios and avoids over-allocation issues.
[0044] Furthermore, the method also includes: each browser instance in the remote browser cluster reporting instance status information to the browser instance status database at a preset time interval (e.g., every 5 seconds); wherein each instance status information in the browser instance status database has a lifecycle, the instance status information of browser instances in normal operation is automatically renewed through continuous reporting, and the instance status information corresponding to terminated browser instances is automatically cleared after the lifecycle ends.
[0045] Through this timed reporting mechanism, the browser instance status database always maintains the latest status information of all active browser instances in the cluster, providing an accurate data foundation for the resource allocation decisions of the scheduling subsystem.
[0046] Specifically, each instance status record in the browser instance status database has a lifecycle (e.g., the expiration time (TTL) of the corresponding key in a Redis implementation). The duration of the lifecycle is typically set to a multiple of the reporting time interval (e.g., 3 times, i.e., 15 seconds) to ensure that normally functioning instances have sufficient time to renew.
[0047] Browser instances in normal operation continuously and periodically report their instance state information in the state database, automatically renewing it (i.e., resetting the lifecycle timer) to maintain the validity of this state information. As long as the instance is running normally and continues to report, its state information will remain in the state database.
[0048] When a browser instance stops reporting due to abnormal exit (such as process crash, node failure, network partition, etc.), its corresponding instance status information is automatically cleared by the status database at the end of its lifecycle, without the need for additional fault detection components to actively detect and clean up. This design greatly reduces the complexity of the system architecture, while ensuring that the scheduling subsystem always reads only the real and usable instance status and will not assign invalid instances to clients.
[0049] For example, if a browser Pod crashes due to an underlying node failure, the browser instances within that Pod can no longer report status information to Redis. Fifteen seconds after the last report (when the lifecycle expires), the status information key corresponding to that instance in Redis automatically expires and is deleted. The scheduling subsystem will no longer be able to query this instance in subsequent resource allocation requests, thus avoiding the assignment of a crashed instance to a client and preventing task failure.
[0050] S130. Obtain the target network address of the target browser instance, and establish a target communication link between the client and the target browser instance based on the target network address.
[0051] In this embodiment, after determining the target browser instance, the target network address (such as IP address and port number) of the instance is obtained, and a communication link between the client and the target browser instance is established based on the network address. The communication link is used for bidirectional data interaction between the client and the browser instance, including the client issuing control commands and the browser instance returning execution results and actively pushing events.
[0052] In one embodiment, the target communication link is a full-duplex communication link based on the WebSocket protocol. When the browser instance starts, it opens the Chrome DevTools Protocol (CDP) debug port and generates a WebSocket connection address. The client establishes a connection with the browser instance through this WebSocket address, enabling bidirectional real-time communication. Because WebSocket supports full-duplex communication, the browser instance can proactively push event notifications to the client (such as page loading completion, network request interception, console log output, etc.), eliminating the need for the client to frequently poll for state changes.
[0053] In some embodiments, specifically, please refer to Figure 3 Specifically, the target communication link is established through steps S1301-S1303: S1301. Detect the network connectivity between the client and the target network address; if the network is connected, proceed to step S1302; if the network is not connected, proceed to step S1303.
[0054] Specifically, after obtaining the target network address of the target browser instance, the scheduling subsystem does not directly establish a communication link. Instead, it first checks the network connectivity between the client and the target network address. This network connectivity check is used to determine whether the client can directly access the computing node where the target browser instance resides.
[0055] In one embodiment, the network connectivity detection is implemented through a Socket connection test: the client attempts to establish a Transmission Control Protocol (TCP) connection with the target network address (IP and port). If the TCP three-way handshake is successfully completed within a preset timeout period (e.g., 3 seconds), the network is determined to be connected; if the connection times out or is rejected, the network is determined to be disconnected.
[0056] S1302. Establish a direct communication link between the client and the target browser instance as the target communication link.
[0057] Specifically, if network connectivity testing indicates that the client and the target browser instance are network reachable (e.g., the client and browser instance are deployed within the same Virtual Private Cloud (VPC) intranet, or connected to the same network via a Virtual Private Network (VPN), then a direct communication link is established between the client and the target browser instance as the target communication link. In direct connection mode, the client directly establishes a WebSocket connection with the browser instance's CDP debug port, and data is not forwarded through any intermediate nodes, resulting in minimal communication latency.
[0058] S1303. Establish a target communication link between the client and the target browser instance through a proxy service.
[0059] Specifically, if network connectivity testing indicates that the network between the client and the target browser instance is unreachable (e.g., the client is deployed on the external network, while the browser instance is deployed on the Kubernetes cluster intranet, the Pod IP is a private IP within the cluster, and the external network cannot directly route to it), then a proxy communication link is established between the client and the target browser instance through a proxy service as the target communication link. In proxy mode, the client sends requests to the proxy service, which acts as a relay node to forward data between the client and the target browser instance.
[0060] The network connectivity detection and direct / proxy switching process is completely transparent to the caller (client). The client only needs to initiate a browser resource request and receive the returned communication link information, without needing to be aware of the underlying network topology or whether it is currently using direct or proxy mode. The scheduling subsystem automatically completes network detection and mode selection, reducing the complexity of client access.
[0061] Furthermore, establishing the target communication link between the client and the target browser instance through the proxy service includes: Determine whether the proxy service stores a port mapping relationship between the target network address and the local listening port; if the port mapping relationship is stored, establish the target communication link based on the port mapping relationship; if the port mapping relationship is not stored, select an idle listening port from the proxy service, construct the port mapping relationship based on the idle listening port, and establish the target communication link based on the port mapping relationship.
[0062] Specifically, the proxy service maintains an active proxy mapping table. This table uses the target browser instance's target network address (target IP and target port) as the key and the locally allocated listening port of the proxy service as the value, recording the port mapping relationship between the target network address and the local listening port. Through this mapping table, the proxy service can quickly determine whether a target browser instance already has a corresponding proxy channel.
[0063] When a client needs to establish a communication link through a proxy service due to network unavailability, the proxy service first determines whether the target network address of the target browser instance already has a corresponding port mapping relationship in the mapping table: If a corresponding port mapping exists, the proxy service does not need to reallocate ports or establish new proxy channels; it directly establishes a target communication link based on the existing port mapping. The client connects to the existing local listening port, and the proxy service forwards the data to the corresponding target browser instance. This port reuse mechanism avoids creating duplicate proxy channels for the same target, effectively saving the proxy server's port resources.
[0064] For example, client A and client B successively request to connect to the same target browser instance (target IP is 10.244.1.5, target port is 9222). Client A first establishes a connection through a proxy service, which allocates port 61001 from the idle port pool and establishes a mapping relationship (10.244.1.5:9222→61001). When client B (whose request may carry the same business identifier as client A) subsequently requests to connect to the same target, the proxy service finds that a mapping relationship already exists and directly reuses port 61001, and client B also connects to the target browser instance through this port.
[0065] If no corresponding port mapping relationship exists in the mapping table, the proxy service selects an idle listening port from the local idle port pool, establishes a port mapping relationship between the target network address and the idle port and stores it in the mapping table, and then establishes the target communication link based on the newly created port mapping relationship.
[0066] In this embodiment, after establishing a TCP connection with the target browser instance, the proxy service performs bidirectional raw byte stream forwarding between the local listening port and the TCP connection. Specifically, the proxy service starts two threads: the first thread performs byte stream forwarding from the client to the target browser instance, and the second thread performs byte stream forwarding from the target browser instance to the client. All data, including the HTTP Upgrade handshake phase, is forwarded directly in raw byte stream form; the proxy service does not parse or modify the application layer protocol content. This forwarding design has the following advantages: First, the proxy service does not depend on a specific WebSocket protocol version; even if the CDP protocol is upgraded in the future, the proxy service can continue to work without modification. Second, it avoids the computational overhead caused by protocol parsing, resulting in high forwarding efficiency. Third, it is naturally compatible with all features of the WebSocket protocol (including full-duplex communication, heartbeat keep-alive, etc.).
[0067] Furthermore, in this embodiment, the proxy service runs an independent idle check thread in the background, periodically (e.g., at regular intervals) scanning all active proxy channels in the mapping table. For proxy channels that exceed the idle timeout threshold and have no data transmission, the proxy service sends a stop signal to close the corresponding local listening port and deletes the corresponding port mapping relationship from the mapping table, automatically releasing port resources and preventing port leakage.
[0068] S140. Send a control command to the browser instance through the target communication link to execute browser operations. The control command is triggered by the client.
[0069] In this embodiment, after the communication link is established, the client sends control commands to the target browser instance through the link to control the browser to perform automated operations. These control commands are triggered by the client and can be generated and issued by the client's business logic code (such as Python scripts, Java programs, etc.) according to task requirements.
[0070] In one embodiment, the control instructions are CDP-based instructions, including but not limited to: page navigation instructions (Page.navigate, used to open a specified URL), script execution instructions (Runtime.evaluate, used to execute JavaScript code in the page context), element interaction instructions (such as DOM.querySelector combined with click operation, used to click page elements), and network request interception instructions (Network.enable and related event handling, used to intercept and analyze network requests), etc.
[0071] For example, in a data acquisition scenario, the client sequentially sends the `Page.navigate` command to open the target website, the `Runtime.evaluate` command to execute JavaScript code to extract page data, and the `Network.enable` command to listen for network requests and capture encrypted data returned by Ajax via the communication link. After executing each command, the browser instance returns the execution results to the client through the same communication link.
[0072] S150. Monitor the data interaction activities on the target communication link. When the difference between the most recent activity time and the current time of the data interaction activities exceeds a preset threshold, trigger a recycling operation. The recycling operation includes terminating the target browser instance and releasing the occupied resources.
[0073] In this embodiment, the system starts an independent idle monitoring thread for each browser instance to continuously monitor data interaction activities on the target communication link. These data interaction activities include control commands sent from the client to the browser instance, execution results returned by the browser instance to the client, and proactively pushed event notifications.
[0074] Specifically, the system maintains an activity timestamp (last_activity_time) for each browser instance. Whenever a message is forwarded through the communication link (whether it's a command from the client to the browser instance or data from the browser instance to the client), this timestamp is updated to the current time. The system periodically (e.g., at regular time intervals) checks the difference between the current time and the activity timestamp; if this difference exceeds a preset threshold (i.e., an idle timeout threshold), the browser instance is determined to have timed out and a recycling operation is triggered. The idle timeout threshold can be specified by the client in the resource request; if not specified, a system default value (e.g., 300 seconds) is used.
[0075] The recycling operation includes terminating the process of the target browser instance (e.g., closing the Chrome browser process) and releasing all resources occupied by the instance (including computing resources, memory resources, storage resources, and network port resources). This idle monitoring and recycling mechanism effectively prevents the accumulation of zombie browsers caused by abnormal client exits or forgotten resource releases, ensuring resource utilization in large-scale clusters.
[0076] In some embodiments, before terminating a browser instance, the system further includes: packaging and uploading the instance's user data directory (containing cookies, login status, LocalStorage, etc.) to external storage (such as cloud object storage OSS / S3) so that data can be loaded from external storage when the instance's state needs to be restored later, thus achieving cross-instance state migration. In this case, the method further includes: obtaining a browser migration request sent by the client, saving the target browser instance's user data directory to external storage, and associating the user data directory with the business identifier for storage; the user data directory contains page state data, session credential data, and local cache data; when a new browser instance corresponding to the business identifier is started, retrieving the corresponding user data directory from the external storage based on the business identifier, and restoring the user data of the new browser instance based on the user data directory.
[0077] Specifically, during the process of the client controlling the browser instance to perform operations through the target communication link, the client can send a browser migration request to the system. The migration request instructs the system to save the user data directory of the current target browser instance to external storage so that the directory can be restored in the new browser instance later.
[0078] The User Data Directory is a directory used by the browser to store user configuration and state data during runtime, including but not limited to the following data: page state data (such as the URL of the currently opened page, page scroll position, form content, etc.), session credential data (such as cookies, session storage, tokens, etc.), and local cache data (such as LocalStorage, IndexedDB, browser cache files, etc.).
[0079] After receiving the migration request, the system packages the user data directory of the target browser instance (e.g., compresses it into a tar.gz file) and uploads it to external storage (e.g., cloud object storage OSS, S3, or distributed file system). At the same time, it records the association between the user data directory and the business identifier in the external storage.
[0080] When a client subsequently initiates a new browser resource request and needs to launch a new browser instance based on the previously saved user data directory (e.g., the original browser instance has been idled, recycled, or destroyed, or a new instance needs to be launched on a different compute node), the system first searches for the corresponding user data directory archive in external storage based on the business identifier. If found, the system downloads the user data directory archive from external storage before the new browser instance starts, decompresses it, and places it in the user data directory location of the new instance. The new browser instance then starts, automatically loading data such as Cookies and LocalStorage from the user data directory upon startup, thus enabling cross-instance browser environment migration.
[0081] In some embodiments, the method further includes: In response to the visualization viewing request initiated by the client, a visualization communication link is established between the client and the remote desktop server on the node where the target browser instance is located through a proxy service; the remote desktop protocol data is bidirectionally and transparently forwarded at the transport layer through the proxy service, and the port resources occupied by the visualization communication link are automatically released when the client side of the visualization communication link is detected to be disconnected.
[0082] Specifically, the client can initiate a visualization viewing request to the system to view the real-time screen of the target browser instance. This request can be triggered by operations and maintenance personnel clicking the "View Screen" button on the client's web management interface, or initiated through an API call.
[0083] After receiving a visualization request, the system establishes a visualization communication link between the client and the remote desktop server on the node where the target browser instance is located through a proxy service.
[0084] In one embodiment, each browser Pod runs a Virtual Network Computing (VNC) server (listening on port 5900) and a noVNC WebSocket bridging service (listening on port 6080). The VNC server is used to capture the frame buffer data of the browser's desktop, and the noVNC service is used to convert the VNC protocol to the WebSocket protocol, enabling the client to view the remote desktop directly through the browser page without installing additional VNC client software.
[0085] When a client initiates a visualization request, the proxy service allocates a local port from the idle port pool, establishes a mapping relationship between this local port and the target VNC server (or noVNC server), and establishes a visualization communication link between the client and the VNC server. The proxy interface returns an HTTP 302 redirect to the corresponding domain's noVNC page, through which the client can view the remote browser's screen in real time.
[0086] The proxy service performs bidirectional transparent forwarding of Remote Framebuffer Protocol (RFB) data at the transport layer. The VNC server continuously pushes screen images (framebuffer data) to the client, and the client's mouse clicks and keyboard input commands are also forwarded to the VNC server through the proxy service. The proxy service does not parse or modify the RFB protocol content; it is only responsible for the bidirectional transfer of the raw byte stream.
[0087] In this embodiment, the visualization communication link supports read-only mode. In read-only mode, the client can view the remote browser screen in real time, but cannot operate it using a mouse or keyboard. This mode is suitable for operation and maintenance monitoring scenarios, allowing maintenance personnel to observe the execution process of automated tasks without accidentally interfering with the running automated scripts due to mouse or keyboard input.
[0088] The proxy service continuously monitors the client-side connection status of the visualization communication link. When a client-side disconnection is detected (e.g., the operations and maintenance personnel close the viewing page, the browser tab is closed, or the network times out), the proxy service automatically closes the visualization communication link, releases the occupied local port resources, and deletes the corresponding mapping relationship from the mapping table.
[0089] In summary, on the one hand, the embodiments of this application can determine the target browser instance associated with the service identifier in the remote browser cluster through the service identifier. Compared with the prior art scheme where the browser is destroyed after each session ends, this significantly reduces the time and computational cost caused by repeated initialization operations. On the other hand, the embodiments of this application achieve automatic recycling of idle timeouts through monitoring data interaction activities on the communication link, effectively preventing the accumulation of zombie browsers caused by abnormal client exits or forgotten releases, and ensuring the resource utilization rate of the remote browser cluster.
[0090] Figure 4 This is a schematic block diagram of a remote browser cluster control system provided in an embodiment of this application. Figure 4As shown, corresponding to the above remote browser cluster control method, this application also provides a remote browser cluster control system 400. The remote browser cluster control system 400 includes a unit for executing the above-described remote browser cluster control method, and can be configured in a terminal or server. Specifically, please refer to... Figure 4 The remote browser cluster control system 400 includes a receiving unit 401, an instance determination unit 402, a link establishment unit 403, an operation unit 404, and a recycling unit 405, wherein: The receiving unit 401 is used to receive a browser resource request initiated by the client, wherein the browser resource request carries a service identifier; The instance determination unit 402 is used to determine the target browser instance based on the service identifier and the instance status information of each browser instance in the remote browser cluster. Link establishment unit 403 is used to obtain the target network address of the target browser instance and establish a target communication link between the client and the target browser instance based on the target network address; Operation unit 404 is used to send control commands to the browser instance through the target communication link to execute browser operations, wherein the control commands are triggered by the client; The recycling unit 405 is used to monitor the data interaction activities on the target communication link. When the difference between the most recent activity time and the current time of the data interaction activity exceeds a preset threshold, a recycling operation is triggered. The recycling operation includes terminating the target browser instance and releasing the occupied resources.
[0091] It should be noted that those skilled in the art can clearly understand that the specific implementation process of the above-mentioned remote browser cluster control system and its various units can be referred to the corresponding descriptions in the foregoing method embodiments. For the sake of convenience and brevity, these details will not be repeated here.
[0092] The aforementioned remote browser cluster control system can be implemented as a computer program, which can, for example... Figure 5 It runs on the computer device shown.
[0093] Please see Figure 5 , Figure 5 This is a schematic block diagram of a computer device 500 provided in an embodiment of this application. The computer device 500 can be a terminal or a server.
[0094] See Figure 5 The computer device 500 includes a processor 502, a memory, and a network interface 505 connected via a system bus 501. The memory may include a non-volatile storage medium 503 and internal memory 504.
[0095] The non-volatile storage medium 503 may store an operating system 5031 and a computer program 5032. The computer program 5032 includes program instructions that, when executed, cause the processor 502 to perform a remote browser cluster control method.
[0096] The processor 502 provides computing and control capabilities to support the operation of the entire computer device 500.
[0097] The internal memory 504 provides an environment for the execution of the computer program 5032 in the non-volatile storage medium 503. When the computer program 5032 is executed by the processor 502, the processor 502 can execute a remote browser cluster control method.
[0098] This network interface 505 is used for network communication with other devices. Those skilled in the art will understand that... Figure 5 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device 500 to which the present application is applied. The specific computer device 500 may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0099] The processor 502 is used to run a computer program 5032 stored in the memory to perform the following steps: Receive a browser resource request initiated by a client, wherein the browser resource request carries a business identifier; The target browser instance is determined based on the service identifier and the instance status information of each browser instance in the remote browser cluster. Obtain the target network address of the target browser instance, and establish a target communication link between the client and the target browser instance based on the target network address; Control commands are sent to the browser instance via the target communication link to execute browser operations, and the control commands are triggered by the client. Monitor data interaction activities on the target communication link. When the difference between the most recent activity time and the current time of the data interaction activity exceeds a preset threshold, trigger a recycling operation. The recycling operation includes terminating the target browser instance and releasing the occupied resources.
[0100] It should be understood that in the embodiments of this application, the processor 502 may be a central processing unit (CPU), or it may be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or any conventional processor.
[0101] It will be understood by those skilled in the art that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program includes program instructions and can be stored in a storage medium, which is a computer-readable storage medium. The program instructions are executed by at least one processor in the computer system to implement the process steps of the embodiments of the above methods.
[0102] Therefore, this application also provides a storage medium. This storage medium can be a computer-readable storage medium. The storage medium stores a computer program, wherein the computer program includes program instructions. When executed by a processor, the program instructions cause the processor to perform the following steps: Receive a browser resource request initiated by a client, wherein the browser resource request carries a business identifier; The target browser instance is determined based on the service identifier and the instance status information of each browser instance in the remote browser cluster. Obtain the target network address of the target browser instance, and establish a target communication link between the client and the target browser instance based on the target network address; Control commands are sent to the browser instance via the target communication link to execute browser operations, and the control commands are triggered by the client. Monitor data interaction activities on the target communication link. When the difference between the most recent activity time and the current time of the data interaction activity exceeds a preset threshold, trigger a recycling operation. The recycling operation includes terminating the target browser instance and releasing the occupied resources.
[0103] The storage medium can be any computer-readable storage medium capable of storing program code, such as a USB flash drive, portable hard drive, read-only memory (ROM), magnetic disk, or optical disk.
[0104] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this application.
[0105] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative. For example, the division of each unit is merely a logical functional division, and there may be other division methods in actual implementation. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed.
[0106] The steps in the methods of this application embodiment can be adjusted, merged, or deleted according to actual needs. The units in the apparatus of this application embodiment can be merged, divided, or deleted according to actual needs. Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.
[0107] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, a terminal, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application.
[0108] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in this application, and these modifications or substitutions should all be covered within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A remote browser cluster control method, characterized in that, include: Receive a browser resource request initiated by a client, wherein the browser resource request carries a business identifier; The target browser instance is determined based on the service identifier and the instance status information of each browser instance in the remote browser cluster. Obtain the target network address of the target browser instance, and establish a target communication link between the client and the target browser instance based on the target network address; Control commands are sent to the browser instance via the target communication link to execute browser operations, and the control commands are triggered by the client. Monitor data interaction activities on the target communication link. When the difference between the most recent activity time and the current time of the data interaction activity exceeds a preset threshold, trigger a recycling operation. The recycling operation includes terminating the target browser instance and releasing the occupied resources.
2. The method according to claim 1, characterized in that, The step of determining the target browser instance based on the service identifier and the instance status information of each browser instance in the remote browser cluster includes: Query whether there is target instance status information corresponding to the business identifier in the browser instance status database. The browser instance status database stores the instance status information of each browser instance in the remote browser cluster. If the target instance status information exists and the target instance status information indicates an idle state, then the browser instance corresponding to the target instance status information is determined as the target browser instance; If the target instance status information does not exist or the instance status information indicates a non-idle state, a new browser instance is created as the target browser instance, and the service identifier is associated with the instance status information of the new browser instance and stored in the browser instance status database.
3. The method according to claim 2, characterized in that, The method further includes: Each browser instance in the remote browser cluster reports its instance status information to the browser instance status database at preset time intervals. Each instance status information in the browser instance status database has a lifecycle. The instance status information of browser instances in normal operation is automatically renewed through continuous reporting, while the instance status information corresponding to terminated browser instances is automatically cleared after the lifecycle ends.
4. The method according to claim 1, characterized in that, The step of establishing a target communication link between the client and the target browser instance based on the target network address includes: Detect the network connectivity between the client and the target network address; If the network is connected, a direct communication link is established between the client and the target browser instance as the target communication link; If the network is not connected, a target communication link is established between the client and the target browser instance through a proxy service.
5. The method according to claim 4, characterized in that, The step of establishing a target communication link between the client and the target browser instance through a proxy service includes: Determine whether the proxy service stores a port mapping relationship between the target network address and the local listening port; If the port mapping relationship is stored, then the target communication link is established based on the port mapping relationship; If the port mapping relationship is not stored, an idle listening port is selected from the proxy service, and the port mapping relationship is constructed based on the idle listening port. The target communication link is then established based on the port mapping relationship.
6. The method according to claim 1, characterized in that, Prior to triggering the recycling operation, the method further includes: Obtain the browser migration request sent by the client, save the user data directory of the target browser instance to external storage, and associate the user data directory with the business identifier for storage. The user data directory contains page state data, session credential data, and local cache data. When a new browser instance corresponding to the service identifier is launched, the corresponding user data directory is obtained from the external storage according to the service identifier, and the user data of the new browser instance is restored based on the user data directory.
7. The method according to claim 1, characterized in that, The method further includes: In response to the visualization viewing request initiated by the client, a visualization communication link is established between the client and the remote desktop server on the node where the target browser instance is located through the proxy service; The proxy service performs bidirectional transparent forwarding of remote desktop protocol data at the transport layer, and automatically releases the port resources occupied by the visual communication link when the client side of the visual communication link is detected to be disconnected.
8. A remote browser cluster control system, characterized in that, The remote browser cluster control system includes: The receiving unit is used to receive browser resource requests initiated by the client, wherein the browser resource requests carry a business identifier; An instance determination unit is used to determine a target browser instance based on the service identifier and the instance status information of each browser instance in the remote browser cluster. A link establishment unit is used to obtain the target network address of the target browser instance and establish a target communication link between the client and the target browser instance based on the target network address; An operation unit is configured to send control commands to the browser instance via the target communication link to execute browser operations, wherein the control commands are triggered by the client. The recycling unit is used to monitor data interaction activities on the target communication link. When the difference between the most recent activity time and the current time of the data interaction activity exceeds a preset threshold, a recycling operation is triggered. The recycling operation includes terminating the target browser instance and releasing the occupied resources.
9. A computer 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 computer program, it implements the remote browser cluster control method as described in any one of claims 1-7.
10. A storage medium, characterized in that, The storage medium stores a computer program, which includes program instructions that, when executed by a processor, cause the processor to perform the remote browser cluster control method as described in any one of claims 1-7.