Method and apparatus for implementing a headless browser cluster

By forming a headless browser cluster across multiple servers, the problems of resource consumption and cumbersome deployment of headless browsers on application servers are solved, achieving efficient resource utilization and rapid response, and improving application performance and stability.

CN114443301BActive Publication Date: 2026-03-27WIRELESS LIFE (HANGZHOU) INFORMATION TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-01-26
Publication Date
2026-03-27

AI Technical Summary

Technical Problem

In existing technologies, headless browsers consume a large amount of CPU and memory resources when deployed on application servers, affecting application stability. The deployment process is cumbersome, resource utilization is low, and different applications need to be deployed repeatedly, wasting time and manpower.

Method used

The headless browser is deployed on multiple servers to form a cluster, managed by IP address. Each server pre-starts a pool of headless browser instances, and the client obtains available instances from the cluster to develop functions. Resources are reclaimed when the client releases the instances.

Benefits of technology

It avoids consuming application server resources, improves application performance and stability, reduces the time spent on repeated deployment and installation configuration, and achieves balanced resource utilization and rapid response.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114443301B_ABST
    Figure CN114443301B_ABST
Patent Text Reader

Abstract

The present disclosure relates to a method and device for implementing a headless browser cluster. The method comprises: assigning a corresponding accessible IP address to each server in a plurality of servers; wherein the plurality of servers form a cluster; installing a headless browser in each server; after receiving a headless browser starting instruction, starting a preset number of headless browser instances, the started headless browser instances forming a headless browser instance pool; after detecting that a headless browser instance acquisition instruction is received, acquiring a target headless browser instance available from the headless browser instance pool; acquiring a network socket endpoint address of the target headless browser instance; and sending the network socket endpoint address of the target headless browser instance to a client.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present disclosure relates to the technical field of computer, and particularly relates to a method and device for implementing a headless browser cluster. BACKGROUND

[0002] A headless browser is a browser without a UI layer, which cannot operate the interface through a keyboard or a mouse. Compared with a common browser, the headless browser has higher performance and less resource consumption, and is suitable for running in a server. The headless browser is usually used for project UI testing, page screenshot, function integrity testing, etc. The headless browser is operated through a control protocol at a bottom layer, such as a Webdriver or a DevTool protocol. The headless browser provides a bottom layer method, such as opening a page, taking a screenshot, clicking, etc., which is called through the protocol.

[0003] A current scheme is that when a project uses a headless browser, the headless browser needs to be deployed in a project application server, and then the headless browser is started in the application server to provide a call for an application. Since the headless browser occupies a large amount of CPU and memory resources, the performance of the application itself is affected, and the stability of the application is reduced. Meanwhile, the process of deploying the headless browser is very cumbersome, and there are installation package timeout and complex configuration. In addition, different applications need to be repeatedly deployed, which wastes time and manpower. Since the load of each application is different, the resource utilization rate of the headless browser is not high for some applications, and the resources are not enough for some applications, which causes the resource utilization rate to be unable to be maximized. SUMMARY

[0004] To overcome the problems in the related art, the embodiments of the present disclosure provide a method and device for implementing a headless browser cluster. The technical scheme is as follows.

[0005] According to a first aspect of the embodiments of the present disclosure, a method for implementing a headless browser cluster is provided, and the method comprises the following steps.

[0006] allocating a corresponding accessible IP address to each of a plurality of servers; wherein the plurality of servers form a cluster;

[0007] installing a headless browser in each of the servers;

[0008] starting a preset number of headless browser instances after receiving a headless browser starting instruction, wherein the started headless browser instances form a headless browser instance pool;

[0009] obtaining a target headless browser instance from the headless browser instance pool after detecting that a headless browser instance obtaining instruction is received;

[0010] obtaining a network socket endpoint address of the target headless browser instance;

[0011] sending the network socket endpoint address of the target headless browser instance to the client.

[0012] The technical scheme provided by the embodiments of the present disclosure can have the following beneficial effects: the present disclosure provides a method for implementing a headless browser cluster, comprising: assigning a corresponding accessible IP address to each server in a plurality of servers; wherein the plurality of servers form a cluster; installing a headless browser in each server; after receiving a headless browser starting instruction, starting a preset number of headless browser instances, and the started headless browser instances form a headless browser instance pool; after detecting that a headless browser instance acquisition instruction is received, acquiring a target headless browser instance available from the headless browser instance pool; acquiring a network socket endpoint address of the target headless browser instance; and sending the network socket endpoint address of the target headless browser instance to the client. By deploying the headless browser on a plurality of servers to form a cluster service, the application server CPU and memory resources are not occupied, the application performance and stability are not affected, the need for repeated deployment of different applications is avoided, time and manpower are saved, load balancing is achieved, and resource utilization is maximized. In addition, the application server does not need to separately install the headless browser, thereby saving the problems of complicated installation and configuration, slow speed, etc. Each server starts a certain number of headless browser instances in advance to form a headless browser instance pool. When an application needs to acquire an instance, a usable headless browser instance is taken out from the headless browser instance pool and immediately returned, the response time is fast, and the smoothness of user experience is improved.

[0013] In one embodiment, after the available headless browser instance is acquired from the headless browser instance pool, the method further comprises:

[0014] decrementing the number of headless browser instances included in the headless browser instance pool by one;

[0015] changing the use state of the target headless browser instance to used.

[0016] In one embodiment, the acquiring of the available target headless browser instance from the headless browser instance pool comprises:

[0017] acquiring state information of each server in the cluster;

[0018] determining a target server according to the state information of each server in the cluster;

[0019] judging whether the target headless browser instance pool corresponding to the target server is empty;

[0020] if the target headless browser instance pool is empty, determining whether a maximum load quantity of the target server has been exceeded;

[0021] if the maximum load quantity of the target server has not been exceeded, starting a new headless browser instance and adding the new headless browser instance to the target headless browser instance pool;

[0022] selecting the target headless browser instance from the newly started headless browser instance;

[0023] if the target headless browser instance pool is not empty, obtaining the target headless browser instance from the headless browser instances already in the target headless browser instance pool.

[0024] In one embodiment, after the network socket endpoint address of the target headless browser instance is obtained, the method further includes:

[0025] mapping the network socket endpoint address of the target headless browser instance with the target headless browser instance;

[0026] The method further includes:

[0027] receiving a headless browser instance release instruction, the headless browser instance release instruction including a network socket endpoint address of a target headless browser instance to be released;

[0028] finding the target headless browser instance according to the network socket endpoint address of the target headless browser instance and the mapping relationship;

[0029] changing a use state of the target headless browser instance to an unused state according to the release instruction;

[0030] releasing the target headless browser instance to the headless browser instance pool.

[0031] In one embodiment, the method further includes:

[0032] detecting a state of each headless browser instance in the headless browser instance pool;

[0033] when a use quantity of a first headless browser instance exceeds a preset quantity, and / or the first headless browser instance has not been used for a preset time length, deleting the first headless browser instance.

[0034] According to a second aspect of the embodiments of the present disclosure, a method for implementing a headless browser cluster is provided, and the method includes:

[0035] sending a headless browser instance obtaining instruction;

[0036] receiving a network socket endpoint address of a target headless browser instance sent by the cluster;

[0037] connecting the target headless browser instance according to the network socket endpoint address of the target headless browser instance;

[0038] performing function development in the connected target headless browser instance.

[0039] The present disclosure provides a method for implementing a headless browser cluster, the method comprising: sending a headless browser instance acquisition instruction; receiving a network socket endpoint address of a target headless browser instance sent by the cluster; connecting the target headless browser instance according to the network socket endpoint address of the target headless browser instance; and performing function development in the connected target headless browser instance. In this way, the headless browser in the cluster can be called to complete the function development, without the need to create a headless browser in the application server, so as to not occupy the CPU and memory resources of the application server, not affect the application performance and stability, avoid the need for repeated deployment of different applications, waste of time and manpower, and at the same time, balance the load and maximize the resource utilization. Moreover, the application does not need to separately install a headless browser, thereby saving the problems of complicated installation and configuration, slow speed, etc.

[0040] In one embodiment, after the function development in the connected target headless browser instance, the method further comprises:

[0041] After the function development is completed, sending a headless browser instance release instruction to the cluster.

[0042] According to a third aspect of the embodiments of the present disclosure, an apparatus for implementing a headless browser cluster is provided, comprising:

[0043] an allocation module configured to allocate a corresponding accessible IP address to each of a plurality of servers, wherein the plurality of servers form a cluster;

[0044] an installation module configured to install a headless browser in each of the servers;

[0045] a starting module configured to start a preset number of headless browser instances after receiving a headless browser starting instruction, wherein the started headless browser instances form a headless browser instance pool;

[0046] a first acquisition module configured to acquire a target headless browser instance from the headless browser instance pool after detecting that a headless browser instance acquisition instruction is received;

[0047] a second acquisition module configured to acquire a network socket endpoint address of the target headless browser instance;

[0048] The first sending module is configured to send the network socket endpoint address of the target headless browser instance to the client.

[0049] In one embodiment, the apparatus further comprises:

[0050] The processing module is configured to, after the first obtaining module obtains the available headless browser instance from the pool of headless browser instances, decrease the number of headless browser instances included in the pool of headless browser instances by one.

[0051] The first changing module is configured to change the use state of the target headless browser instance to used.

[0052] In one embodiment, the first obtaining module comprises:

[0053] The first obtaining submodule is configured to obtain the state information of each of the servers in the cluster.

[0054] The first determining submodule is configured to determine a target server according to the state information of each of the servers in the cluster.

[0055] The first judging submodule is configured to judge whether the target headless browser instance pool corresponding to the target server is empty.

[0056] The second judging submodule is configured to, if the target headless browser instance pool is empty, judge whether the maximum load number of the target server has been exceeded.

[0057] The starting submodule is configured to, if the maximum load number of the target server has not been exceeded, start a new headless browser instance and add it to the target headless browser instance pool.

[0058] The first selecting submodule is configured to select the target headless browser instance from the newly started headless browser instance.

[0059] The second selecting submodule is configured to, if the target headless browser instance pool is not empty, obtain the target headless browser instance from the existing headless browser instances in the target headless browser instance pool.

[0060] In one embodiment, the apparatus further comprises:

[0061] The relationship establishing module is configured to, after the second obtaining module obtains the network socket endpoint address of the target headless browser instance, establish a mapping relationship between the network socket endpoint address of the target headless browser instance and the target headless browser instance.

[0062] The apparatus further comprises:

[0063] The first receiving module is configured to receive a headless browser instance release instruction, wherein the headless browser instance release instruction comprises a network socket endpoint address of a target headless browser instance to be released.

[0064] The searching module is configured to search for the target headless browser instance according to the network socket endpoint address of the target headless browser instance and the mapping relationship.

[0065] The second changing module is configured to change a use state of the target headless browser instance to an unused state according to the release instruction.

[0066] The releasing module is configured to release the target headless browser instance into the headless browser instance pool.

[0067] In an embodiment, the apparatus further comprises:

[0068] The detecting module is configured to detect a state of each headless browser instance in the headless browser instance pool.

[0069] The deleting module is configured to delete a first headless browser instance when a use frequency of the first headless browser instance exceeds a preset frequency and / or the first headless browser instance is not used within a preset time length.

[0070] According to a fourth aspect of an embodiment of the present disclosure, an apparatus for implementing a headless browser cluster apparatus is provided, comprising:

[0071] The second sending module is configured to send a headless browser instance acquisition instruction.

[0072] The second receiving module is configured to receive a network socket endpoint address of a target headless browser instance sent by the cluster.

[0073] The connecting module is configured to connect the target headless browser instance according to the network socket endpoint address of the target headless browser instance.

[0074] The developing module is configured to develop a function in the connected target headless browser instance.

[0075] In an embodiment, the apparatus further comprises a third sending module configured to send a headless browser instance release instruction to the cluster after the function development is completed.

[0076] According to a fifth aspect of an embodiment of the present disclosure, an apparatus for implementing a headless browser cluster apparatus is provided, comprising:

[0077] A processor;

[0078] A memory for storing processor-executable instructions;

[0079] wherein the processor is configured to:

[0080] assigning a corresponding accessible IP address to each of a plurality of servers, wherein the plurality of servers form a cluster;

[0081] installing a headless browser in each of the servers;

[0082] starting a preset number of headless browser instances upon receiving a headless browser starting instruction, wherein the started headless browser instances form a headless browser instance pool;

[0083] obtaining a target headless browser instance from the headless browser instance pool upon detecting that a headless browser instance obtaining instruction is received;

[0084] obtaining a network socket endpoint address of the target headless browser instance;

[0085] sending the network socket endpoint address of the target headless browser instance to a client.

[0086] According to a sixth aspect of the embodiments of the present disclosure, an apparatus for implementing a headless browser cluster apparatus is provided, comprising:

[0087] a processor;

[0088] a memory for storing processor-executable instructions;

[0089] wherein the processor is configured to:

[0090] sending a headless browser instance obtaining instruction;

[0091] receiving a network socket endpoint address of a target headless browser instance sent by the cluster;

[0092] connecting to the target headless browser instance according to the network socket endpoint address of the target headless browser instance;

[0093] developing a function in the connected target headless browser instance.

[0094] According to a seventh aspect of the embodiments of the present disclosure, a computer readable storage medium is provided, which stores computer instructions, and the instructions are executed by a processor to implement the steps of the method of any one of the first aspect.

[0095] According to an eighth aspect of the embodiments of the present disclosure, a computer readable storage medium is provided, which stores computer instructions, and the instructions are executed by a processor to implement the steps of the method of any one of the first aspect.

[0096] It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the disclosure. BRIEF DESCRIPTION OF DRAWINGS

[0097] The accompanying drawings, which are incorporated in and form a part of the specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the disclosure.

[0098] Figure 1 is a flowchart of a method for implementing a headless browser cluster according to an example embodiment Figure 1 .

[0099] Figure 2 is a flowchart of a method for implementing a headless browser cluster according to an example embodiment Figure 2 .

[0100] Figure 3 is a flowchart of a method for implementing a headless browser cluster according to an example embodiment Figure 3 .

[0101] Figure 4 is a flowchart of a method for implementing a headless browser cluster according to an example embodiment .

[0102] Figure 5 is a flowchart of a method for implementing a headless browser cluster according to an example embodiment Figure 4 .

[0103] Figure 6 is a flowchart of a method for implementing a headless browser cluster according to an example embodiment Figure 5 .

[0104] Figure 7 is a flowchart of a method for implementing a headless browser cluster according to an example embodiment Figure 6 .

[0105] Figure 8 is a flowchart of a method for implementing a headless browser cluster according to an example embodiment Figure 7 .

[0106] Figure 9 is a block diagram of an apparatus for implementing a headless browser cluster according to an example embodiment.

[0107] Figure 10 is a block diagram of an apparatus for implementing a headless browser cluster according to an example embodiment.

[0108] Figure 11 is a block diagram of an apparatus 90 for implementing a headless browser cluster according to an example embodiment.

[0109] Figure 12 is a block diagram of an apparatus 80 for implementing a headless browser cluster according to an example embodiment. DETAILED DESCRIPTION

[0110] The example embodiments will be described in detail herein with reference to the attached drawings. In the following description, same numbers refer to same or similar elements throughout the drawings. The embodiments described in the following example embodiments are not meant to represent all embodiments consistent with the present disclosure. Rather, they are merely examples of apparatuses and methods consistent with some aspects of the present disclosure as detailed in the appended claims.

[0111] Figure 1 is a flowchart of a method for implementing a headless browser cluster according to an example embodiment, as shown in Figure 1 the method is for a server side, the method comprises the following steps S101-S103:

[0112] In step S101, each server in a plurality of servers is assigned a corresponding accessible IP address; wherein the plurality of servers form a cluster.

[0113] Wherein, the server can be a virtual machine, or a physical machine, the present disclosure does not limit the implementation of the server.

[0114] First, a plurality of servers will be built, and each server is assigned a corresponding accessible IP address.

[0115] In step S102, a headless browser is installed in each server.

[0116] The headless browser is installed on each server.

[0117] In the present disclosure, the headless browser is deployed on a plurality of servers, each server creates a certain number of headless browser instances by calling the headless browser through playwright, forming a headless browser instance pool, and the plurality of servers form a cluster to provide services externally.

[0118] Since the headless browser is installed in advance on each server, the application does not need to install the headless browser separately in the application server, saving the problems of complicated installation and configuration, slow speed, etc.

[0119] Moreover, by deploying the headless browser on a plurality of servers to form a cluster service, the application server CPU and memory resources are not occupied, the application performance and stability are not affected, the need for repeated deployment of different applications is avoided, time and manpower are saved, at the same time, the load is balanced, and the resource utilization rate is maximized.

[0120] In step S103, after receiving the headless browser starting instruction, a preset number of headless browser instances are started, and the started headless browser instances form a headless browser instance pool.

[0121] For example, a service can be deployed on a server to manage and maintain the headless browser instance pool through playwright. When the service starts, a preset number of headless browser instances can be started in advance to form a headless browser instance pool.

[0122] The starting of the preset number of headless browser instances can include starting a headless browser instance in each server.

[0123] Each server starts a certain number of headless browser instances in advance to form a headless browser instance pool. When the client's application needs to obtain a headless browser instance, an available headless browser instance is immediately returned from the headless browser pool, the response time is fast, and the smoothness of user experience is improved.

[0124] In step S104, after detecting that the headless browser instance obtaining instruction is received, an available target headless browser instance is obtained from the headless browser instance pool.

[0125] When the client's application needs to use a headless browser, the client sends a headless browser instance obtaining instruction to the cluster formed by multiple servers. After the cluster receives the headless browser instance obtaining instruction, an available target headless browser instance is obtained from the headless browser instance pool.

[0126] Specifically, an obtaining interface can be provided to obtain the network socket endpoint (English: websocket endpoint) address of the headless browser instance.

[0127] In one embodiment, as shown in Figure 2 obtaining an available target headless browser instance from the headless browser instance pool includes the following sub-steps:

[0128] In step S1041, the state information of each server in the cluster is obtained.

[0129] In step S1042, the target server is determined according to the state information of each server in the cluster.

[0130] In step S1043, it is judged whether the target headless browser instance pool corresponding to the target server is empty;

[0131] In step S1044, if the target headless browser instance pool is empty, it is judged whether the maximum load number of the target server has been exceeded;

[0132] In step S1045, if the maximum load quantity of the target server is not exceeded, a new headless browser instance is started and added to the target headless browser instance pool;

[0133] In step S1046, a target headless browser instance is selected from the newly started headless browser instance;

[0134] In step S1047, if the maximum load quantity is exceeded, exit directly;

[0135] After exiting, the step of selecting a target server can be re-executed.

[0136] In step S1048, if the target headless browser instance pool is not empty, a target headless browser instance is obtained from the existing headless browser instance in the target headless browser instance pool.

[0137] Continuing with the above example, since there are multiple servers in the cluster, each server has a corresponding headless browser instance pool, so if the client wants to use a headless browser instance, it needs to first use a load balancing algorithm based on the state information of each server in the multiple servers to determine the target server that can provide a headless browser instance for the user, after determining the target server, the IP of the target server is obtained, and then based on the IP of the target server, the target server can be called after the client calls the acquisition interface, when calling, it is judged whether the target headless browser instance pool corresponding to the target server is empty, if the target headless browser instance pool is empty, it is judged whether the maximum load quantity of the target server has been exceeded, if not, a new headless browser instance is started and added to the target headless browser instance pool, and a target headless browser instance is selected from the newly started headless browser instance; if the maximum load quantity of the target server is exceeded, exit directly; if the target headless browser instance pool is not empty, a target headless browser instance is obtained from the existing headless browser instance in the target headless browser instance pool.

[0138] Among them, a headless browser instance can be newly started at a time, or multiple headless browser instances can be newly started, which depends on the system settings and the load quantity of the server, when a new headless browser instance is started at a time, the newly started headless browser is the target headless browser instance; if multiple new headless browser instances are started at a time, then one of them needs to be selected as the target headless browser instance.

[0139] In an embodiment, after obtaining the available target headless browser instance from the headless browser instance pool, the method further includes the following sub-steps A1-A2:

[0140] A1, reducing the number of headless browser instances included in the headless browser instance pool by one;

[0141] A2, changing the use state of the target headless browser instance to used.

[0142] After obtaining the available target headless browser instance, the target headless browser can be taken out, the number of headless browser instance pool is reduced by one, and the use state of the target headless browser instance is changed to used.

[0143] In step S105, the network socket endpoint address of the target headless browser instance is obtained.

[0144] In one embodiment, after obtaining the network socket endpoint address of the target headless browser instance, further comprising:

[0145] Mapping the network socket endpoint address of the target headless browser instance with the target headless browser instance;

[0146] The purpose of performing this step is to achieve the purpose of releasing the target headless browser instance.

[0147] Specifically, the above method further comprises the following sub-steps B1-B4:

[0148] B1, receiving a headless browser instance release instruction, the headless browser instance release instruction including the network socket endpoint address of the target headless browser instance to be released;

[0149] B2, finding the target headless browser instance according to the network socket endpoint address of the target headless browser instance and the mapping relationship;

[0150] B3, changing the use state of the target headless browser instance to unused according to the release instruction;

[0151] B4, releasing the target headless browser instance into the headless browser instance pool.

[0152] In one implementation, a release interface can be provided, when the client calls the target headless browser underlying interface to complete the function development, the release interface of the cluster service can be called to release the target headless browser. The interface is used to release the headless browser instance used by the client, when the interface is called, the headless browser instance is marked as unused, and reenters the headless browser instance pool.

[0153] Specifically, the client can call the release interface, which is equivalent to sending a release instruction to the cluster. The headless browser instance release instruction includes the network socket endpoint address of the target headless browser instance to be released. When the cluster receives the headless browser instance release instruction, it finds the target headless browser based on the network socket endpoint address, and then changes the use state of the target headless browser instance to unused according to the release instruction. The target headless browser instance is released into the headless browser instance pool.

[0154] In step S106, the network socket endpoint address of the target headless browser instance is sent to the client.

[0155] After sending the network socket endpoint address of the target headless browser instance to the client, the client connects to the network socket endpoint address through the playwright module to obtain a remote headless browser instance, so that the client can remotely call the headless browser underlying interface to complete the function development.

[0156] The present disclosure provides a method for implementing a headless browser cluster, comprising: assigning a corresponding accessible IP address to each server in a plurality of servers; wherein the plurality of servers form a cluster; installing a headless browser in each server; after receiving a headless browser start instruction, starting a predetermined number of headless browser instances, and the started headless browser instances form a headless browser instance pool; after detecting that a headless browser instance acquisition instruction is received, acquiring a target headless browser instance from the headless browser instance pool; acquiring the network socket endpoint address of the target headless browser instance; and sending the network socket endpoint address of the target headless browser instance to the client. By deploying the headless browser to multiple servers to form a cluster service, the application server CPU and memory resources are not occupied, the application performance and stability are not affected, the need for repeated deployment of different applications is avoided, time and manpower are saved, load balancing is achieved, and resource utilization is maximized. The application server does not need to separately install the headless browser, which saves the problems of complicated installation and configuration, slow speed, etc. Each server starts a certain number of headless browser instances in advance to form a headless browser instance pool. When the application needs to acquire a headless browser instance, a usable headless browser instance is immediately returned by taking it from the headless browser instance pool, the response time is fast, and the smoothness of user experience is improved.

[0157] Since a headless browser instance is used too many times or not used for a long time, it may cause the headless browser instance memory not to be released and occupy CPU resources. Therefore, it is necessary to regularly check the state of the headless browser instance pool and remove unhealthy headless browser instances. At this time, the above method further comprises the following sub-steps C1-C2:

[0158] In step C1, the state of each headless browser instance in the headless browser instance pool is detected.

[0159] In step C2, when the number of uses of the first headless browser instance exceeds the preset number of times, and / or the first headless browser instance is not used within the preset time length, the first headless browser instance is deleted.

[0160] Figure 3 A flowchart for implementing a headless browser cluster method according to an exemplary embodiment is shown in FIG. 1. As shown in FIG. 1, the method is used on the client side, and the method includes the following steps S201-S204: Figure 3

[0161] In step S201, a headless browser instance acquisition instruction is sent.

[0162] In step S202, the network socket endpoint address of the target headless browser instance sent by the cluster is received.

[0163] After the cluster receives the headless browser instance acquisition instruction, the target browser is selected for the client from the headless browser instance pool composed of the already started headless browser instances.

[0164] In step S203, the target headless browser instance is connected according to the network socket endpoint address of the target headless browser instance.

[0165] The network socket endpoint address of the target headless browser instance can be connected through the playwright module to obtain the remote target headless browser instance.

[0166] In step S204, function development is performed in the connected target headless browser instance.

[0167] The function development is completed by calling the underlying interface of the remote target headless browser instance.

[0168] After the function development is performed in the connected target headless browser instance, a headless browser instance release instruction is sent to the cluster.

[0169] ​The method for implementing a headless browser cluster provided by the present disclosure comprises the following steps: sending a headless browser instance acquisition instruction; receiving a network socket endpoint address of a target headless browser instance sent by a cluster; connecting the target headless browser instance according to the network socket endpoint address of the target headless browser instance; and developing a function in the connected target headless browser instance. In this way, the headless browser in the cluster can be called to complete the function development, and there is no need to create a headless browser in an application server, so that the CPU and memory resources of the application server are not occupied, the application performance and stability are not affected, the need for repeated deployment of different applications is avoided, time and manpower are saved, load balancing is achieved, and the resource utilization rate is maximized. In addition, the application does not need to separately install a headless browser, and the problems of complicated installation and configuration, slow speed, etc. are avoided.

[0170] The method for implementing a headless browser cluster provided by the present disclosure comprises the following steps: sending a headless browser instance acquisition instruction; receiving a network socket endpoint address of a target headless browser instance sent by a cluster; connecting the target headless browser instance according to the network socket endpoint address of the target headless browser instance; and developing a function in the connected target headless browser instance. In this way, the headless browser in the cluster can be called to complete the function development, and there is no need to create a headless browser in an application server, so that the CPU and memory resources of the application server are not occupied, the application performance and stability are not affected, the need for repeated deployment of different applications is avoided, time and manpower are saved, load balancing is achieved, and the resource utilization rate is maximized. In addition, the application does not need to separately install a headless browser, and the problems of complicated installation and configuration, slow speed, etc. are avoided. Figure 4 The method for implementing a headless browser cluster provided by the present disclosure comprises the following steps: sending a headless browser instance acquisition instruction; receiving a network socket endpoint address of a target headless browser instance sent by a cluster; connecting the target headless browser instance according to the network socket endpoint address of the target headless browser instance; and developing a function in the connected target headless browser instance. In this way, the headless browser in the cluster can be called to complete the function development, and there is no need to create a headless browser in an application server, so that the CPU and memory resources of the application server are not occupied, the application performance and stability are not affected, the need for repeated deployment of different applications is avoided, time and manpower are saved, load balancing is achieved, and the resource utilization rate is maximized. In addition, the application does not need to separately install a headless browser, and the problems of complicated installation and configuration, slow speed, etc. are avoided.

[0171] The cluster module

[0172] The cluster module is responsible for deploying the headless browser on multiple servers. Each server creates a certain number of headless browser instances through playwright to form a headless browser instance pool. Multiple servers form a cluster to provide services externally. The specific implementation steps include the following steps S301-S303, and the flowchart is as shown in Figure 5

[0173] In step S301, multiple servers are built, and each server is allocated a corresponding accessible IP address.

[0174] In step S302, the headless browser is installed on each server.

[0175] In step S303, a service is deployed to the server to manage and maintain the headless browser instance pool through playwright.

[0176] When the service starts, a certain number of headless browser instances are started in advance to form a headless browser instance pool.

[0177] The present disclosure also provides an acquisition interface for acquiring the network socket endpoint address of the headless browser instance. The specific implementation steps include the following steps S401-S4010, and the flowchart is as shown in Figure 6 ​​

[0178] A load balancing module can also be set before calling the acquisition interface of the cluster service, which determines which target server in the cluster to call according to the state of each server in the cluster, acquires the IP of the target server, and then calls the acquisition interface of the target server, and then executes the following steps:

[0179] In step S401, the acquisition interface is called.

[0180] In step S402, after calling the interface, it is judged whether the target headless browser instance pool of the target server is empty. If it is empty, step S403 is executed, and if it is not empty, step S406 is executed.

[0181] In step S403, if it is empty, it is judged whether the maximum load quantity of the target server has been exceeded. If it has not been exceeded, step S404 is executed; if it has been exceeded, step S405 is executed.

[0182] In step S404, a new headless browser instance is started and added to the target headless browser instance pool, and step S406 is executed.

[0183] In step S405, if it is exceeded, it is directly exited.

[0184] In step S406, a target headless browser instance is taken out, and the number of target headless browser instance pools is reduced by one.

[0185] In step S407, the target headless browser instance is set as used.

[0186] In step S408, the network socket endpoint address of the target headless browser instance is acquired.

[0187] In step S409, the network socket endpoint address is mapped with the target headless browser instance.

[0188] In step S4010, the network socket endpoint address of the target headless browser instance is returned.

[0189] The disclosure also provides a release interface, which transmits the network socket endpoint address of the target headless browser instance, and is used to release the target headless browser instance used by the client. When the release interface is called, the target headless browser instance is marked as unused and reenters the target headless browser instance pool. The specific implementation steps include steps S501-S504, and the flow chart is shown in Figure 7 .

[0190] In step S501, the release interface is called, and the network socket endpoint address of the target headless browser instance is transmitted.

[0191] In step S502, find the target headless browser instance according to the mapping relationship;

[0192] In step S503, set the target headless browser instance as unused;

[0193] In step S504, put the target headless browser instance into the headless browser instance pool.

[0194] Client module

[0195] The client module is responsible for calling the external service of the cluster, obtaining a usable network socket endpoint address, and then connecting the address through the playwright module. Remote invocation of the headless browser underlying interface can be used to complete the function development. The specific implementation steps include steps S601-S604, and the flowchart is shown in Figure 8 .

[0196] In step S601, call the acquisition interface of the cluster service to obtain a usable network socket endpoint address;

[0197] In step S602, connect the network socket endpoint address in the previous step to obtain a remote headless browser instance;

[0198] In step S603, call the remote headless browser underlying interface to complete the function development;

[0199] In step S604, after completing the function development, call the release interface of the cluster service to release the instance.

[0200] In the present disclosure, by deploying headless browsers on multiple servers to form a cluster service, the application stability is avoided from being affected, the problem of repeated deployment and complicated installation of different applications is solved, and the resource utilization is maximized. A certain number of headless browser instances are started on each server to form a headless browser instance pool. When an application needs to obtain a headless browser instance, a usable headless browser instance is immediately returned by taking it from the headless browser instance pool, the response time is faster, and the user experience is improved.

[0201] The following is an apparatus embodiment of the present disclosure, which can be used to execute the method embodiment of the present disclosure.

[0202] Figure 9 is a block diagram of an apparatus for implementing a headless browser cluster according to an exemplary embodiment. The apparatus can be implemented by software, hardware, or a combination of both as part of a server. As shown in Figure 9 , the apparatus for implementing a headless browser cluster includes:

[0203] The distribution module 11 is configured to assign a corresponding accessible IP address to each of a plurality of servers, wherein the plurality of servers form a cluster.

[0204] The installation module 12 is configured to install a headless browser in each of the servers.

[0205] The starting module 13 is configured to start a preset number of headless browser instances after receiving a headless browser starting instruction, and the started headless browser instances form a headless browser instance pool.

[0206] The first obtaining module 14 is configured to obtain a target headless browser instance available from the headless browser instance pool after detecting that a headless browser instance obtaining instruction is received.

[0207] The second obtaining module 15 is configured to obtain a network socket endpoint address of the target headless browser instance.

[0208] The first sending module 16 is configured to send the network socket endpoint address of the target headless browser instance to a client.

[0209] In an embodiment, the apparatus further comprises:

[0210] The processing module is configured to reduce the number of headless browser instances included in the headless browser instance pool by one after the first obtaining module obtains a headless browser instance available from the headless browser instance pool.

[0211] The first changing module is configured to change the use state of the target headless browser instance to used.

[0212] In an embodiment, the first obtaining module comprises:

[0213] The first obtaining submodule is configured to obtain state information of each of the servers in the cluster.

[0214] The first determining submodule is configured to determine a target server according to the state information of each of the servers in the cluster.

[0215] The first judging submodule is configured to judge whether a target headless browser instance pool corresponding to the target server is empty.

[0216] The second judging submodule is configured to judge whether a maximum load number of the target server has been exceeded if the target headless browser instance pool is empty.

[0217] The starting submodule is configured to start a new headless browser instance and add it to the target headless browser instance pool if the maximum load number of the target server has not been exceeded.

[0218] a first selection sub-module, configured to select the target headless browser instance from the newly started headless browser instances;

[0219] a second selection sub-module, configured to obtain the target headless browser instance from the headless browser instances already existing in the target headless browser instance pool if the target headless browser instance pool is not empty.

[0220] In an embodiment, the apparatus further comprises:

[0221] a relationship establishment module, configured to, after the second obtaining module obtains the network socket endpoint address of the target headless browser instance, establish a mapping relationship between the network socket endpoint address of the target headless browser instance and the target headless browser instance;

[0222] The apparatus further comprises:

[0223] a first receiving module, configured to receive a headless browser instance release instruction, wherein the headless browser instance release instruction comprises a network socket endpoint address of a target headless browser instance to be released;

[0224] a searching module, configured to search for the target headless browser instance according to the network socket endpoint address of the target headless browser instance and the mapping relationship;

[0225] a second changing module, configured to change a use state of the target headless browser instance to unused according to the release instruction;

[0226] a releasing module, configured to release the target headless browser instance into the headless browser instance pool.

[0227] In an embodiment, the apparatus further comprises:

[0228] a detecting module, configured to detect states of the headless browser instances in the headless browser instance pool;

[0229] a deleting module, configured to delete a first headless browser instance when a use frequency of the first headless browser instance exceeds a preset frequency and / or the first headless browser instance is not used within a preset time length.

[0230] Figure 10 is a block diagram of an apparatus for implementing a headless browser cluster according to an exemplary embodiment. The apparatus for implementing a headless browser cluster can be implemented as part or all of a client by software, hardware or a combination of both. As shown in Figure 10 the apparatus for implementing a headless browser cluster comprises:

[0231] The second sending module 21 is configured to send a headless browser instance acquisition instruction.

[0232] The second receiving module 22 is configured to receive a network socket endpoint address of a target headless browser instance sent by the cluster.

[0233] The connecting module 23 is configured to connect the target headless browser instance according to the network socket endpoint address of the target headless browser instance.

[0234] The developing module 24 is configured to develop a function in the connected target headless browser instance.

[0235] In an embodiment, the apparatus further comprises a third sending module configured to send a headless browser instance release instruction to the cluster after the function development is completed.

[0236] The embodiments of the present disclosure further provide an apparatus for implementing a headless browser cluster, which is used in a server and comprises:

[0237] a processor;

[0238] a memory for storing processor-executable instructions;

[0239] The processor is configured to:

[0240] allocate a corresponding accessible IP address to each of a plurality of servers, wherein the plurality of servers form a cluster;

[0241] install a headless browser in each of the servers;

[0242] start a preset number of headless browser instances upon receiving a headless browser start instruction, wherein the started headless browser instances form a headless browser instance pool;

[0243] detect that a headless browser instance acquisition instruction is received, and acquire a target headless browser instance from the headless browser instance pool;

[0244] acquire a network socket endpoint address of the target headless browser instance;

[0245] send the network socket endpoint address of the target headless browser instance to a client.

[0246] The processor can be further configured to:

[0247] In an embodiment, after the target headless browser instance is acquired from the headless browser instance pool, the processor is further configured to:

[0248] decrementing the number of headless browser instances included in the headless browser instance pool by one;

[0249] changing a usage state of the target headless browser instance to used.

[0250] In one embodiment, the obtaining the target headless browser instance available from the headless browser instance pool comprises:

[0251] obtaining state information of each of the servers in the cluster;

[0252] determining a target server according to the state information of each of the servers in the cluster;

[0253] judging whether a target headless browser instance pool corresponding to the target server is empty;

[0254] if the target headless browser instance pool is empty, judging whether a maximum load number of the target server has been exceeded;

[0255] if the maximum load number of the target server has not been exceeded, starting a new headless browser instance and adding it to the target headless browser instance pool;

[0256] selecting the target headless browser instance from the newly started headless browser instance;

[0257] if the target headless browser instance pool is not empty, obtaining the target headless browser instance from the headless browser instances already in the target headless browser instance pool.

[0258] In one embodiment, after the obtaining the network socket endpoint address of the target headless browser instance, the method further comprises:

[0259] establishing a mapping relationship between the network socket endpoint address of the target headless browser instance and the target headless browser instance;

[0260] The processor is further configured to:

[0261] receiving a headless browser instance release instruction, the headless browser instance release instruction including a network socket endpoint address of a target headless browser instance to be released;

[0262] looking up the target headless browser instance according to the network socket endpoint address of the target headless browser instance and the mapping relationship;

[0263] changing a usage state of the target headless browser instance to unused according to the release instruction;

[0264] release the target headless browser instance into the headless browser instance pool.

[0265] In one embodiment, the processor is further configured to:

[0266] detect a state of each headless browser instance in the headless browser instance pool;

[0267] delete the first headless browser instance when a number of times of using the first headless browser instance exceeds a preset number of times, and / or the first headless browser instance is not used within a preset time length.

[0268] The embodiments of the present disclosure further provide a device for implementing a headless browser cluster, the device being used in a client, the device comprising:

[0269] a processor;

[0270] a memory for storing processor-executable instructions;

[0271] wherein the processor is configured to:

[0272] send a headless browser instance acquisition instruction;

[0273] receive a network socket endpoint address of a target headless browser instance sent by the cluster;

[0274] connect the target headless browser instance according to the network socket endpoint address of the target headless browser instance;

[0275] perform a function development in the connected target headless browser instance.

[0276] The processor can be further configured to:

[0277] In one embodiment, after the function development in the connected target headless browser instance, the processor is further configured to:

[0278] after the function development is completed, send a headless browser instance release instruction to the cluster.

[0279] As to the device in the above-mentioned embodiments, the specific manners in which each module performs operations have been described in detail in the embodiments of the method, and will not be described in detail here.

[0280] Figure 11is a block diagram of an apparatus 90 for implementing a headless browser cluster according to an exemplary embodiment. For example, the apparatus 90 can be provided as a server. The apparatus 90 includes a processing component 902, which further comprises one or more processors, and a memory resource represented by a memory 903 for storing instructions, such as an application, executable by the processing component 902. The application stored in the memory 903 can include one or more than one module each corresponding to a set of instructions. In addition, the processing component 902 is configured to execute the instructions to perform the method described above.

[0281] The apparatus 90 can further include a power component 906 configured to perform power management of the apparatus 90, a wired or wireless network interface 905 configured to connect the apparatus 90 to a network, and an input output (I / O) interface 908. The apparatus 90 can operate based on an operating system stored in the memory 903, such as Windows ServerTM, Mac OS XTM, UnixTM, LinuxTM, FreeBSDTM, or the like.

[0282] A non-transitory computer readable storage medium, when instructions in the storage medium are executed by a processor of an apparatus 90, enables the apparatus 90 to perform the method described above for implementing a headless browser cluster, the method comprising:

[0283] sending a headless browser instance obtaining instruction;

[0284] receiving a network socket endpoint address of a target headless browser instance sent by the cluster;

[0285] connecting the target headless browser instance according to the network socket endpoint address of the target headless browser instance;

[0286] developing a function in the connected target headless browser instance.

[0287] In one embodiment, after the developing a function in the connected target headless browser instance, the method further comprises:

[0288] after completing the function development, sending a headless browser instance releasing instruction to the cluster.

[0289] After the obtaining an available headless browser instance from the headless browser instance pool, the method further comprises:

[0290] decrementing the number of headless browser instances included in the headless browser instance pool by one;

[0291] changing the use state of the target headless browser instance to used.

[0292] In one embodiment, the obtaining the target headless browser instance from the available headless browser instance pool comprises:

[0293] obtaining state information of each of the servers in the cluster;

[0294] determining a target server according to the state information of each of the servers in the cluster;

[0295] judging whether a target headless browser instance pool corresponding to the target server is empty;

[0296] if the target headless browser instance pool is empty, judging whether a maximum load quantity of the target server has been exceeded;

[0297] if the maximum load quantity of the target server has not been exceeded, starting a new headless browser instance and adding it to the target headless browser instance pool;

[0298] selecting the target headless browser instance from the newly started headless browser instance;

[0299] if the target headless browser instance pool is not empty, obtaining the target headless browser instance from the existing headless browser instances in the target headless browser instance pool.

[0300] In one embodiment, after the obtaining the network socket endpoint address of the target headless browser instance, the method further comprises:

[0301] mapping the network socket endpoint address of the target headless browser instance with the target headless browser instance;

[0302] The method further comprises:

[0303] receiving a headless browser instance release instruction, the headless browser instance release instruction comprising a network socket endpoint address of a target headless browser instance to be released;

[0304] finding the target headless browser instance according to the network socket endpoint address of the target headless browser instance and the mapping relationship;

[0305] changing a use state of the target headless browser instance to unused according to the release instruction;

[0306] releasing the target headless browser instance to the headless browser instance pool.

[0307] In one embodiment, the method further comprises:

[0308] detecting a state of each headless browser instance in the pool of headless browser instances;

[0309] when the number of times of using the first headless browser instance exceeds a preset number of times, and / or the first headless browser instance is not used within a preset time length, deleting the first headless browser instance.

[0310] Figure 12 Fig. 1 is a block diagram illustrating an apparatus 80 for implementing a headless browser cluster according to an example embodiment. The apparatus 80 is suitable for a terminal device. For example, the apparatus 80 can be a computer, a digital broadcast terminal, a messaging device, a game console, a tablet device, a medical device, a fitness device, a personal digital assistant, and the like.

[0311] The apparatus 80 can include one or more of the following components: a processing component 802, a memory component 804, a power supply component 806, a multimedia component 808, an audio component 810, an input / output (I / O) interface 812, a sensor component 814, and a communication component 816.

[0312] The processing component 802 usually controls overall operations of the apparatus 80, such as operations associated with displaying, making phone calls, data communications, camera operations, and recording operations. The processing component 802 can include one or more processors 820 to execute instructions to complete all or part of steps of the methods described above. In addition, the processing component 802 can include one or more modules to facilitate interaction between the processing component 802 and other components. For example, the processing component 802 can include a multimedia module to facilitate the interaction between the multimedia component 808 and the processing component 802.

[0313] The memory component 804 is configured to store various types of data to support operations of the apparatus 80. Examples of these data include instructions for any application or methods operating on the apparatus 80, contact data, phonebook data, messages, pictures, videos, and the like. The memory component 804 can be implemented by any type of volatile or non-volatile storage devices or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic or optical disk.

[0314] The power supply component 806 supplies electrical power for various components of the apparatus 80. The power supply component 806 can include a power supply management system, one or more power supplies, and other components associated with generating, managing, and distributing power for the apparatus 80.

[0315] The multimedia component 808 includes a screen providing an output interface between the device 80 and a user. In some embodiments, the screen can include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen can be implemented as a touch screen to receive input signals from a user. The touch panel includes one or more touch sensors to sense touch, swiping, and gestures on the touch panel. The touch sensors can not only sense a boundary of a touching or swiping action, but also detect duration and pressure related to the touching or swiping action. In some embodiments, the multimedia component 808 includes a front camera and / or a rear camera. When the device 80 is in an operation mode, such as a shooting mode or a video mode, the front camera and / or the rear camera can receive external multimedia data. Each of the front and rear camera can be a fixed optical lens system or have a focal length and optical zooming capability.

[0316] The audio component 810 is configured to output and / or input audio signals. For example, the audio component 810 includes a microphone (MIC) configured to receive external audio signals when the device 80 is in an operation mode, such as a call mode, a recording mode, and a voice recognition mode. The received audio signals can be further stored in the memory 804 or transmitted via the communication component 816. In some embodiments, the audio component 810 also includes a speaker for outputting audio signals.

[0317] The I / O interface 812 provides an interface between the processing component 802 and peripheral interface modules, which can be a keypad, a click wheel, buttons, and the like. The buttons can include, but are not limited to, a home button, a volume button, a start button, and a lock button.

[0318] The sensor component 814 includes one or more sensors to provide various state assessments for the device 80. For example, the sensor component 814 can detect an open / closed state of the device 80, relative positioning of components, such as a display and a keypad of the device 80, a change in position of the device 80 or a component of the device 80, presence or absence of user contact with the device 80, a change in orientation of the device 80 or acceleration / deceleration of the device 80, and a temperature change of the device 80. The sensor component 814 can include a proximity sensor configured to detect presence of a nearby object without any physical touch. The sensor component 814 can further include a light sensor, such as a CMOS or CCD image sensor, for use in an imaging application. In some embodiments, the sensor component 814 can further include an acceleration sensor, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.

[0319] The communication component 816 is configured to facilitate wired or wireless communication between the device 80 and other devices. The device 80 can access a wireless network based on a communication standard, such as WiFi, 2G, or 3G, or a combination thereof. In an exemplary embodiment, the communication component 816 receives a broadcast signal or broadcast related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 816 also includes a Near Field Communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on Radio Frequency Identification (RFID) technology, Infrared Data Association (IrDA) technology, Ultra-WideBand (UWB) technology, Bluetooth (BT) technology and other technologies.

[0320] In an exemplary embodiment, the device 80 can be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, micro-controllers, microprocessors or other electronic components, for performing the above-described methods.

[0321] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions, such as the memory 804 including instructions, is also provided, which can be executed by the processor 820 of the device 80 to complete the above-described methods. For example, the non-transitory computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disc, and an optical data storage device, etc.

[0322] A non-transitory computer-readable storage medium, when instructions in the storage medium are executed by a processor of a device 80, enables the device 80 to perform the above-described method of implementing a headless browser cluster, the method comprising:

[0323] allocating a corresponding accessible IP address to each of a plurality of servers; wherein the plurality of servers form a cluster;

[0324] installing a headless browser in each of the servers;

[0325] after receiving a headless browser starting instruction, starting a preset number of headless browser instances, the started headless browser instances forming a headless browser instance pool;

[0326] after detecting that a headless browser instance acquisition instruction is received, acquiring a target headless browser instance from the headless browser instance pool;

[0327] acquiring a network socket endpoint address of the target headless browser instance;

[0328] sending a network socket endpoint address of the target headless browser instance to the client.

[0329] Other embodiments of the disclosure will be apparent to those skilled in the art from consideration of the specification and practice of the concepts disclosed herein. It is intended that the specification and examples be considered as exemplary only, with a true scope and spirit of the disclosure being indicated by the following claims.

[0330] It is to be understood that the disclosure is not limited to the precise structures hereinabove described and shown in the drawings, and that various modifications and changes can be made without departing from the scope thereof. The scope of the disclosure is indicated by the appended claims, rather than the description of the specification.

Claims

1. A method for implementing a headless browser cluster, characterized in that, The method is used on the server side, and the method includes: Assign a corresponding accessible IP address to each of the multiple servers; wherein the multiple servers form a centrally managed headless browser resource cluster; Install a headless browser on each of the aforementioned servers; Upon receiving the headless browser launch command, a preset number of headless browser instances are launched. The launched headless browser instances form a headless browser instance pool, which is managed and maintained by Playwright. Upon receiving a headless browser instance retrieval instruction, an available target headless browser instance is retrieved from the headless browser instance pool. Decrease the number of the target headless browser instances included in the headless browser instance pool by one; Change the usage status of the target headless browser instance to "used"; Obtain the network socket endpoint address of the target headless browser instance, and establish a mapping relationship between the network socket endpoint address of the target headless browser instance and the target headless browser instance; Send the network socket endpoint address of the target headless browser instance to the client; The method further includes: Receive a headless browser instance release instruction, wherein the headless browser instance release instruction includes the network socket endpoint address of the target headless browser instance to be released; The target headless browser instance is located based on its network socket endpoint address and the mapping relationship. According to the release command, the usage status of the target headless browser instance is changed to unused; Release the target headless browser instance into the headless browser instance pool; Obtaining an available target headless browser instance from the headless browser instance pool includes: Obtain the status information of each server in the cluster; The target server is determined based on the status information of each server in the cluster; Determine whether the target headless browser instance pool corresponding to the target server is empty; If the target headless browser instance pool is empty, determine whether the maximum load of the target server has been exceeded. If the maximum load of the target server is not exceeded, start a new headless browser instance and add it to the target headless browser instance pool; Select the target headless browser instance from the newly launched headless browser instance; If the target headless browser instance pool is not empty, obtain the target headless browser instance from the existing headless browser instances in the target headless browser instance pool.

2. The method according to claim 1, characterized in that, The method further includes: Detect the status of each headless browser instance in the headless browser instance pool; The first headless browser instance is deleted when the number of times it is used exceeds a preset number, and / or the first headless browser instance has not been used within a preset time period.

3. A method for implementing a headless browser cluster, characterized in that, The method is used on the client side, and the method includes: Send a headless browser instance retrieval instruction to the server in the method described in claim 1; Receive the network socket endpoint address of the target headless browser instance sent by the cluster; Connect to the target headless browser instance based on the network socket endpoint address of the target headless browser instance; Feature development is performed on the connected target headless browser instance.

4. The method according to claim 3, characterized in that, After developing features in the connected target headless browser instance, the method further includes: After the aforementioned functionality is developed, a command to release the headless browser instance is sent to the cluster.

5. An apparatus for implementing a headless browser cluster, characterized in that, The device is used on the server side to implement the method for implementing a headless browser cluster as described in claim 1, the device comprising: An allocation module is used to allocate a corresponding accessible IP address to each of the multiple servers; wherein the multiple servers form a cluster; An installation module is provided for installing a headless browser on each of the servers. The startup module is used to start a preset number of headless browser instances after receiving a headless browser startup command. The started headless browser instances form a headless browser instance pool, which is managed and maintained by Playwright. The first acquisition module is used to acquire an available target headless browser instance from the headless browser instance pool after detecting that a headless browser instance acquisition instruction has been received. The second acquisition module is used to acquire the network socket endpoint address of the target headless browser instance; The first sending module is used to send the network socket endpoint address of the target headless browser instance to the client. The first acquisition module includes: The first acquisition submodule is used to acquire the status information of each server in the cluster; The first determining submodule is used to determine the target server based on the status information of each server in the cluster; The first judgment submodule is used to determine whether the target headless browser instance pool corresponding to the target server is empty; The second judgment submodule is used to determine whether the maximum load of the target server has been exceeded if the target headless browser instance pool is empty. The startup submodule is used to start a new headless browser instance and add it to the target headless browser instance pool if the maximum load of the target server is not exceeded. The first selection submodule is used to select the target headless browser instance from the newly launched headless browser instances; The second selection submodule is used to obtain the target headless browser instance from the existing headless browser instances in the target headless browser instance pool if the target headless browser instance pool is not empty.

6. An apparatus for implementing a headless browser cluster, characterized in that, The device is used on the client side, and the device includes: The second sending module is used to send a headless browser instance acquisition instruction to the server in the method described in claim 1; The second receiving module is used to receive the network socket endpoint address of the target headless browser instance sent by the cluster. The connection module is used to connect to the target headless browser instance based on the network socket endpoint address of the target headless browser instance; A development module for developing features within the connected target headless browser instance.

Citation Information

Patent Citations

  • Page sharing picture generation method and device, and page sharing method and device

    CN112052420A

  • Remote access method, device and equipment of Chromium browser and computer readable medium

    CN112243039A