A method, apparatus, device, and storage medium for connecting to a browser page.

By storing the browser page's identity in local storage, different pages can share a single long-lived connection, solving the problem of connection exhaustion when multiple browser pages are open and improving loading speed.

CN116016477BActive Publication Date: 2026-03-10HILLSTONE NETWORKS CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

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

AI Technical Summary

Technical Problem

When opening multiple browser pages, each new page will occupy one Hypertext Transfer Protocol (HTTP) connection, which can lead to connection exhaustion and abnormal loading status of some pages.

Method used

By storing the browser page's identity in local storage, different pages can share a single long connection, and stored data can be monitored and pushed.

Benefits of technology

This avoids multiple long connections occupying all the connection slots, thus improving the loading speed of multiple browser pages.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116016477B_ABST
    Figure CN116016477B_ABST
Patent Text Reader

Abstract

This application provides a method, apparatus, device, and storage medium for connecting to browser pages. The method includes: when a browser page is opened, determining whether a long-lived connection flag for sending events to a server exists in local storage space; if the presence of the flag is confirmed, storing the browser page's identifier in local storage space, wherein the browser page and the opened browser page share the long-lived connection; monitoring stored data in local storage space, and pushing the stored data to the browser page and the opened browser page. This method can avoid multiple long-lived connections from consuming the connection limit, thus improving the loading speed of multiple browser pages.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of browser page connection, and more specifically, to a method, apparatus, device, and storage medium for connecting browser pages. Background Technology

[0002] Currently, in multi-page scenarios, when a new browser application page is opened, the application will establish a new long connection. In this way, the two application pages will always occupy two Hypertext Transfer Protocol (HTP) connections. Therefore, it can be deduced that each time a new application page is opened, one more HTP connection will be added.

[0003] In addition, when multiple pages are opened, some pages may remain in a loading state, causing the pages to fail to display correctly.

[0004] Therefore, how to avoid multiple long connections from consuming the connection limit and improve the loading speed of multiple browser pages is a technical problem that needs to be solved. Summary of the Invention

[0005] The purpose of this application is to provide a method for connecting to browser pages. The technical solution of this application can increase the number of browser page connections.

[0006] In a first aspect, embodiments of this application provide a method for connecting a browser page, comprising: when a browser page is opened, determining whether a long connection flag for sending events to a server exists in the local storage space; when it is determined that a long connection flag for sending events to a server exists in the local storage space, storing the browser page's identity in the local storage space, wherein the browser page and the opened browser page share the long connection; monitoring the stored data in the local storage space, and pushing the stored data to the browser page and the opened browser page.

[0007] In the above embodiments, this application stores the identity identifiers of different browser pages in the same local storage space, and different browser pages can share a long connection, thereby enabling multiple browser pages to receive push data simultaneously. This method can avoid multiple long connections from consuming the connection limit and improve the loading speed of multiple browser pages.

[0008] In some embodiments, after determining whether a long-connection flag for the server to send events exists in the local storage space, the method further includes:

[0009] If it is determined that there is no long-lived connection flag for sending events to the server in the local storage space, an event long-lived connection is established to connect to the browser page.

[0010] Store the identity identifier corresponding to the browser page in the local storage space, and push the stored data to the browser page and the opened browser pages.

[0011] In the above embodiments of this application, when there are no long connection flags in the local storage space, a long connection can be established when a new browser page is opened, and the newly opened browser page can be connected through the established long connection.

[0012] In some embodiments, determining whether a long-lived connection flag for sending events by the server exists in the local storage space includes:

[0013] Determine if a preset field for storing long-lived connections exists in the local storage space;

[0014] When it is determined that a preset field for storing long connections exists in the local storage space, it is determined whether the preset field is the identity identifier of the browser page;

[0015] Determine if a long-lived connection flag for the server to send events exists in the local storage space, including:

[0016] It was determined that the preset field is not the identity identifier of the browser page.

[0017] In the above embodiments, this application can determine whether a long connection flag exists in the local storage space by checking whether a preset field in the local storage space is a browser page. This allows for the establishment of a new long connection or the sharing of a long connection with an existing browser page when a new browser page is opened subsequently.

[0018] In some embodiments, storing the browser page's identity in local storage includes:

[0019] The browser page's identity identifier is stored in a preset identifier in the local storage space, and the preset identifier in the local storage space is monitored. The identity identifier in the local storage space is used to select an identity identifier from the local storage space and re-establish a long connection through the browser page corresponding to the selected identity identifier when the established long connection is broken.

[0020] In the above embodiments, by storing the identity identifier of the browser page in a preset identifier in the local storage space, a new long connection can be established through the browser page corresponding to the identity identifier, thereby realizing the transfer of the long connection.

[0021] In some embodiments, before determining that a long-connection flag for the server to send an event exists in the local storage space, the method further includes:

[0022] Generate an identity identifier corresponding to the browser page. The identity identifier is obtained by traversing all identity identifiers stored in the local storage space. Each identity identifier is different from every other identity identifier in the total number of identity identifiers.

[0023] In the above embodiments, the generated unique identifier can accurately determine whether a long connection flag exists in the local storage space.

[0024] In some embodiments, monitoring stored data in local storage space includes:

[0025] Monitor the long-connection flags stored in the local storage space, and determine whether the long-connection has been disconnected based on the current status of the long-connection;

[0026] When a long connection is determined to be broken, a preset function is used to reconnect the long connection until the long connection is successfully reconnected.

[0027] In the above embodiments, this application can reconnect disconnected long connections to ensure that messages can be successfully pushed to the browser page.

[0028] In some embodiments, after monitoring stored data in local storage and pushing the stored data to browser pages and opened browser pages, the method further includes:

[0029] When the browser page is closed, the identity identifier is removed from the local storage space, and it is determined whether the browser page is a persistent connection page.

[0030] When determining that a browser page is a persistent connection page, check if there are any other browser pages that are already open besides the browser page.

[0031] When it is determined that there is an open browser page other than the browser page, the identity of one of the open browser pages is updated to a preset field in the local storage space.

[0032] In the above embodiments, this application can save resources by deleting unused browser long connections, and can promptly establish a new long connection when the only long connection is closed, thus ensuring the smoothness of the browser receiving messages.

[0033] Secondly, embodiments of this application provide an apparatus for connecting to a browser page, comprising:

[0034] The determination module is used to determine whether a long connection flag for sending events to the server exists in the local storage space when a browser page is opened;

[0035] The connection module is used to store the browser page's identity in the local storage space when it is determined that a long connection flag for sending events to the server exists in the local storage space. The browser page and the opened browser page share the long connection.

[0036] The push module is used to monitor the stored data in the local storage space and push the stored data to the browser page and the browser page that is open.

[0037] Optionally, the device further includes:

[0038] The module is configured to establish an event long connection for connecting to the browser page when the determining module determines whether a long connection flag for sending events to the server exists in the local storage space, and when it determines that a long connection flag for sending events to the server does not exist in the local storage space.

[0039] Store the identity identifier corresponding to the browser page in the local storage space, and push the stored data to the browser page and the opened browser pages.

[0040] Optionally, determine the specific use of the module for:

[0041] Determine if a preset field for storing long-lived connections exists in the local storage space;

[0042] When it is determined that a preset field for storing long connections exists in the local storage space, it is determined whether the preset field is the identity identifier of the browser page;

[0043] The module is specifically used for:

[0044] It was determined that the preset field is not the identity identifier of the browser page.

[0045] Optionally, the connection module is specifically used for:

[0046] The browser page's identity identifier is stored in a preset identifier in the local storage space, and the preset identifier in the local storage space is monitored. The identity identifier in the local storage space is used to select an identity identifier from the local storage space and re-establish a long connection through the browser page corresponding to the selected identity identifier when the established long connection is broken.

[0047] Optionally, the device further includes:

[0048] The generation module is used to generate an identity identifier corresponding to the browser page before the determining module determines that a long connection flag for sending events to the server exists in the local storage space. The identity identifier is obtained by traversing all identity identifiers stored in the local storage space, and each identity identifier is different from every identity identifier in the total number of identity identifiers.

[0049] Optionally, the push module is specifically used for:

[0050] Monitor the long-connection flags stored in the local storage space, and determine whether the long-connection has been disconnected based on the current status of the long-connection;

[0051] When a long connection is determined to be broken, a preset function is used to reconnect the long connection until the long connection is successfully reconnected.

[0052] Optionally, the device further includes:

[0053] The update module is used to, after the push module monitors the stored data in the local storage space and pushes the stored data to the browser page and the opened browser page, delete the identity identifier from the local storage space when the browser page is closed, and determine whether the browser page is a long-connection page.

[0054] When determining that a browser page is a persistent connection page, check if there are any other browser pages that are already open besides the browser page.

[0055] When it is determined that there is an open browser page other than the browser page, the identity of one of the open browser pages is updated to a preset field in the local storage space.

[0056] Thirdly, embodiments of this application provide an electronic device, including a processor and a memory, wherein the memory stores computer-readable instructions, and when the computer-readable instructions are executed by the processor, the steps of the method provided in the first aspect above are performed.

[0057] Fourthly, embodiments of this application provide a readable storage medium having a computer program stored thereon, which, when executed by a processor, performs the steps of the method provided in the first aspect above.

[0058] Other features and advantages of this application will be set forth in the following description and will be apparent in part from the description or may be learned by practicing embodiments of this application. The objectives and other advantages of this application may be realized and obtained by means of the structures particularly pointed out in the written description, claims, and drawings. Attached Figure Description

[0059] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments of this application will be briefly introduced below. It should be understood that the following drawings only show some embodiments of this application and should not be regarded as a limitation of the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.

[0060] Figure 1 A flowchart illustrating a method for connecting to a browser page, as provided in an embodiment of this application;

[0061] Figure 2 A flowchart illustrating an implementation method for connecting to a browser page, as provided in this application embodiment;

[0062] Figure 3 A schematic block diagram of a device for connecting to a browser page, provided as an embodiment of this application;

[0063] Figure 4 This is a schematic diagram of a device for connecting to a browser page, provided in an embodiment of this application. Detailed Implementation

[0064] 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 embodiments of this application, and not all embodiments. The components of the embodiments of this application described and shown in the accompanying drawings can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of this application provided in the accompanying drawings is not intended to limit the scope of the claimed application, but merely represents selected embodiments of this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application without inventive effort are within the scope of protection of this application.

[0065] It should be noted that similar reference numerals and letters in the following figures indicate similar items; therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures. Furthermore, in the description of this application, terms such as "first," "second," etc., are used only to distinguish descriptions and should not be construed as indicating or implying relative importance.

[0066] First, some of the terms used in the embodiments of this application will be explained to facilitate understanding by those skilled in the art.

[0067] HTTP: Hypertext Transfer Protocol (HTTP) is a simple request-response protocol that typically runs on top of TCP. It specifies what messages a client might send to a server and what responses it might receive.

[0068] An SSE server-sent event allows a webpage to receive updates from the server.

[0069] LocalStorage: Used for local storage, it solves the problem of insufficient cookie storage space (each cookie has a storage space of 4k). Browsers generally support a size of 5M in localStorage, but this may vary in different browsers.

[0070] This application applies to scenarios involving browser page connections, specifically increasing the number of browser page connections by having multiple browser pages share a single long connection.

[0071] However, currently, in multi-page scenarios, when a new browser application page is opened, that application establishes another persistent connection. This means that the two application pages will continuously occupy two Hypertext Transfer Protocol (HTP) connections. Therefore, it can be deduced that each time an application page is opened, one more HTP connection is added. Furthermore, when multiple pages are open, some pages may remain in a loading state, causing them to fail to display correctly.

[0072] Therefore, this application, when a browser page is opened, determines whether a long-lived connection flag for sending events to the server exists in the local storage space; if the long-lived connection flag for sending events to the server exists in the local storage space, the browser page's identity is stored in the local storage space, wherein the browser page and the opened browser page share the long-lived connection; the stored data in the local storage space is monitored, and the stored data is pushed to the browser page and the opened browser page. By storing the identity flags of different browser pages in the same local storage space, and allowing different browser pages to share a single long-lived connection, different browsers can receive pushed data simultaneously. This method avoids multiple long-lived connections from consuming the connection limit, thus improving the loading speed of multiple browser pages.

[0073] In this embodiment of the application, the executing entity can be a browser page connecting device in the browser page connecting system. In practical applications, the browser page connecting device can be electronic devices such as terminal devices and servers, and there are no restrictions here.

[0074] The following is combined with Figure 1 The method for connecting to a browser page according to embodiments of this application will be described in detail.

[0075] Please refer to Figure 1 , Figure 1 A flowchart illustrating a method for connecting to a browser page, as provided in this application embodiment, is shown below. Figure 1 The methods shown for connecting to browser pages include:

[0076] Step 110: When a browser page is opened, determine whether a long connection flag for sending events to the server exists in the local storage space.

[0077] Local Storage includes a flag for a persistent connection used to connect to a browser page. The persistent connection flag can be a preset field for a persistent connection. The persistent connection is used by the server to send events to the browser page. These events can be data messages requested by the user or messages automatically pushed by the server.

[0078] In some embodiments of this application, before determining that a long connection flag for the server to send events exists in the local storage space, Figure 1 The method also includes generating an identity identifier corresponding to the browser page, wherein the identity identifier is obtained by traversing all identity identifiers stored in the local storage space, and each identity identifier is different from every single identity identifier in the total number of identity identifiers.

[0079] In the above process, this application can accurately determine whether a long connection flag exists in the local storage space by generating a unique identifier.

[0080] The identity identifier (ID) can be a name, number, or code representing a browser page. When the browser application page begins loading, an ID is generated for the current page and stored in LocalStorage. This ID serves as a unique identifier for the current webpage. Specifically, starting with the first browser page, when confirming the page ID, the system first iterates through LocalStorage to see if an opened page ID already exists. If it does, the ID is changed until no corresponding ID exists in LocalStorage, thus obtaining a unique ID value.

[0081] In some embodiments of this application, determining whether a long connection flag for sending events by the server exists in the local storage space includes: determining whether a preset field for storing long connections exists in the local storage space; when it is determined that a preset field for storing long connections exists in the local storage space, determining whether the preset field is an identity identifier of the browser page; determining that a long connection flag for sending events by the server exists in the local storage space includes: determining that the preset field is not an identity identifier of the browser page.

[0082] In the above process, this application can determine whether a long connection flag exists in the local storage space by checking whether a preset field in the local storage space is a browser page. This allows for the establishment of a new long connection or the sharing of a long connection with an existing browser page when opening a new browser page.

[0083] Among them, the preset fields can be used to store the fields of the corresponding long connection, including the identity identifier of the browser page.

[0084] In some embodiments of this application, after determining whether a long-connection flag for the server to send events exists in the local storage space, Figure 1 The method also includes: when it is determined that there is no long connection flag for sending events to the server in the local storage space, establishing a long event connection for connecting to the browser page; storing the identity identifier corresponding to the browser page in the local storage space, and pushing the stored data to the browser page and the opened browser page.

[0085] In the above process, when there are no long connection flags in the local storage space, a long connection can be established when a new browser page is opened. For this purpose, message data can be pushed to the browser page through the long connection.

[0086] The stored data can be push messages sent by the server to the browser page, and the push messages can be message notifications requested by the user from the server.

[0087] Step 120: When it is determined that a long connection flag for sending events to the server exists in the local storage space, the identity of the browser page is stored in the local storage space.

[0088] In this case, the browser page and the opened browser page share the same persistent connection.

[0089] In some embodiments of this application, storing the identity identifier of the browser page in the local storage space includes: storing the identity identifier of the browser page in a preset identifier in the local storage space, and monitoring the preset identifier in the local storage space. The identity identifier in the local storage space is used to select an identity identifier from the local storage space by traversal and re-establish a long connection through the browser page corresponding to the selected identity identifier when the established long connection is broken.

[0090] In the above process, this application stores the browser page's identity identifier in a preset identifier in the local storage space, and can re-establish a long connection through the browser page corresponding to the identity identifier, thereby realizing the transfer of the long connection.

[0091] Monitoring data in local storage includes detecting persistent connection flags and monitoring push data. After a browser page loads, before establishing an SSE persistent connection, a check is performed by querying a specific field in LocalStorage (e.g., sse_active). This field records the ID of the browser page that has already established an SSE persistent connection. If the query finds a value 'x' (where 'x' is not the current page's ID), it means the page with ID 'x' has already established an SSE persistent connection, and the current application page does not need to establish one again. The current page skips the SSE persistent connection establishment process and only needs to add listeners to the push message and SSE persistent connection fields in LocalStorage. If the value of this field is empty or does not exist, it means no page has already established an SSE persistent connection. The current page needs to establish an SSE persistent connection and store its ID in this field (sse_active). After establishing the SSE persistent connection, the received push message needs to be stored in a specific field in LocalStorage (e.g., sse_message). Message sharing is achieved by monitoring changes in the value of a specific field (sse_message) in LocalStorage, without the need to establish an additional connection channel.

[0092] Step 130: Monitor the stored data in the local storage space and push the stored data to the browser page and the opened browser page.

[0093] The stored data includes some push messages.

[0094] In some embodiments of this application, monitoring stored data in local storage space includes:

[0095] Monitor the long-connection flag stored in the local storage space and determine whether the long-connection is broken based on its current status. When the long-connection is determined to be broken, reconnect the long-connection using a preset function until the long-connection is successfully reconnected.

[0096] In the above process, this application can reconnect disconnected long connections, ensuring that messages can be successfully pushed to the browser page.

[0097] In some embodiments of this application, after monitoring the stored data in the local storage space and pushing the stored data to the browser page and the opened browser page, Figure 1The method also includes: when the browser page is closed, deleting the identity identifier from the local storage space and determining whether the browser page is a persistent connection page; when the browser page is determined to be a persistent connection page, determining whether there are any other open browser pages besides the browser page; when it is determined that there are other open browser pages besides the browser page, updating the identity identifier of one of the open browser pages to a preset field in the local storage space.

[0098] In the above process, this application can save resources by deleting unused browser persistent connections, and can promptly establish a new persistent connection when the only persistent connection is closed, thus ensuring the smoothness of the browser receiving messages.

[0099] For example, when the current page is closed, the current page's ID is first deleted from LocalStorage. If the current page is the one establishing the SSE persistent connection, the IDs of other pages need to be found by traversing LocalStorage. If any of the other pages' IDs with a value of 'y' are found (by traversing to find the first matching ID), then 'y' is updated in the sse_active field. At this point, other pages, upon detecting the change in sse_active to 'y', compare their own IDs with 'y'. The page with ID 'y' finds that the value in sse_active matches its own ID, and page 'y' then establishes the SSE connection. Other pages do not perform any operations. If no matching IDs are found, it means that the application only opened the current page and did not open multiple pages. Therefore, there is no need to specify the next page to establish the SSE persistent connection; simply clear the value of the sse_active field in LocalStorage.

[0100] Figure 1Example application scenario: When the first browser page is opened, there are no other page IDs in LocalStorage, so the unique ID value generated for this page is 1. The data with the field name "sse_id_1" and a value of 1 is stored in LocalStorage. At this point, the value of the "sse_active" field read from LocalStorage is empty, indicating that no page has established an SSE persistent connection. Therefore, the current page with ID 1 updates its own ID "1" to the "sse_active" field, establishes an SSE persistent connection, and sets an exception listener function. When the second page is opened, page ID 1 already exists in LocalStorage, so the generated ID is 2. The data with the field name "sse_id_2" and a value of 2 is stored in LocalStorage. The value of the "sse_active" field read from LocalStorage is 1, indicating that the page with ID 1 has already established an SSE persistent connection. The current page does not need to establish one again; only listeners for the "sse_active" and "sse_message" fields in LocalStorage need to be added. Open the third page. Page IDs 1 and 2 already exist in LocalStorage, so the generated ID is 3. Subsequent operations are the same as for page ID 2. At this point, a push notification "x" is sent from the background. Page 1, having established an SSE persistent connection, can directly receive the push notification "x". After receiving the message, Page 1 places the message "x" under the "sse_message" field in LocalStorage. Pages 2 and 3 then detect the change in the "sse_message" field value to "x" and retrieve the push notification "x" from this field. Suddenly, a network jitter anomaly occurs, causing poor network conditions and an unexpected break in the SSE persistent connection. The exception listener function set by Page 1 when establishing the SSE persistent connection is triggered. It reads the value of the "sse_active" field from LocalStorage as 1, which is the current page ID. Therefore, it will continuously attempt to re-establish the SSE persistent connection until it is successfully established, thus maintaining the push function's normal operation after encountering an anomaly. When page 1 is closed, it deletes its own `sse_id_1` field from LocalStorage. The value of the `sse_active` field in LocalStorage is now 1, representing the current page's ID. Therefore, it's necessary to specify the next page to establish an SSE persistent connection after the current page is closed. Page 1 then iterates through the fields in LocalStorage to find the first field that starts with `sse_id_` (fields starting with `sse_id` represent other page IDs). Assuming the first field found is `sse_id_3`, page 1 updates the value of the `sse_active` field to 3 and then closes the page.After page 1 is closed, both pages 2 and 3 detect changes in the `sse_active` field in `LocalStorage`. Both pages retrieve the value of `sse_active` for comparison. Page 2 determines that the value of `sse_active` is 3, which is not equal to its own ID, and performs no action. Page 3 finds that the value of `sse_active` is 3 and equal to its own ID, therefore page 3 needs to establish a new SSE long connection. If a new application page is then opened, the current page, when generating a unique ID, finds that the `sse_id_1` field is not present in `LocalStorage`, meaning ID 1 can be used. Therefore, the ID of the new page is 1 (the new page 1), and subsequent operations are the same as for page 2. Pages 1 and 2 are closed, leaving only page 3 with the established SSE long connection. Page 3 is closed, and it removes its own ID from `LocalStorage`. Since the value of the `sse_active` field is now 3, page 3 needs to specify the next page to establish an SSE long connection. However, page 3, while iterating through the fields in `LocalStorage`, no longer finds any fields starting with `sse_id`. Therefore, page 3 clears the value of the `sse_active` field and closes directly.

[0101] In the above Figure 1 In the process shown, when a browser page is opened, it is determined whether a long-lived connection flag for sending events to the server exists in the local storage space. If the flag exists, the browser page's identity is stored in the local storage space, where the browser page and the opened browser pages share the long-lived connection. The stored data in the local storage space is monitored, and the stored data is pushed to the browser page and the opened browser pages. By storing the identity flags of different browser pages in the same local storage space, and allowing different browser pages to share a single long-lived connection, different browsers can receive pushed data simultaneously. This method avoids multiple long-lived connections consuming the connection limit, thus improving the loading speed of multiple browser pages.

[0102] The following is combined with Figure 2 The implementation method of connecting to a browser page according to the embodiments of this application will be described in detail.

[0103] Please refer to Figure 2 , Figure 2 A flowchart illustrating an implementation method for connecting to a browser page, as provided in this application embodiment, is shown below. Figure 2 The implementation method for connecting to a browser page, as shown, includes:

[0104] Step 210: Generate the identity identifier corresponding to the browser page.

[0105] Specifically: Generate the identity identifier for the current browser page.

[0106] Step 220: Determine if a long-lived connection exists.

[0107] Specifically: When a browser page is opened, determine whether a long-lived connection flag for sending events to the server exists in the local storage space. If it exists, proceed to step 230; otherwise, proceed to step 240.

[0108] Step 230: Store the browser page's identity in local storage.

[0109] Specifically: Store the identity identifier of the current browser page in local storage space.

[0110] Step 240: Establish a long connection.

[0111] Specifically: If it is determined that there is no long-lived connection flag for sending events from the server in the local storage space, establish a long-lived connection for connecting to the browser page.

[0112] Step 250: Push a message to the browser page.

[0113] Specifically: Monitor the stored data in the local storage space and push the stored data to browser pages and opened browser pages.

[0114] The previous text passed Figures 1-2 The method for connecting to a browser page has been described. The following section will combine... Figures 3-4 Describes the device used to connect to a browser page.

[0115] Please refer to Figure 3 This is a schematic block diagram of a device 300 for connecting to a browser page provided in an embodiment of this application. The device 300 can be a module, program segment, or code on an electronic device. This device 300 is related to the above... Figure 1 The method implementation corresponds to this and can be executed. Figure 1 The various steps involved in the method embodiments and the specific functions of the device 300 can be found in the following description. To avoid repetition, detailed descriptions are appropriately omitted here.

[0116] Optionally, the device 300 includes:

[0117] The determination module 310 is used to determine whether a long connection flag for sending events to the server exists in the local storage space when a browser page is opened;

[0118] The connection module 320 is used to store the identity of the browser page in the local storage space when it is determined that there is a long connection flag for the server to send events in the local storage space, wherein the browser page and the opened browser page share the long connection.

[0119] The push module 330 is used to monitor the stored data in the local storage space and push the stored data to the browser page and the opened browser page.

[0120] Optionally, the device further includes:

[0121] The module establishes an event long connection for connecting to the browser page. This is done after the determining module determines whether a long connection flag for sending events to the server exists in the local storage space. If the determining module determines that a long connection flag for sending events to the server does not exist in the local storage space, the module establishes the event long connection for connecting to the browser page. The module stores the identity identifier corresponding to the browser page in the local storage space and pushes the stored data to the browser page and the opened browser pages.

[0122] Optionally, determine the specific use of the module for:

[0123] Determine if a preset field for storing long-lived connections exists in the local storage space; if so, determine if the preset field is the browser page's identity identifier; determine the specific uses of this module:

[0124] It was determined that the preset field is not the identity identifier of the browser page.

[0125] Optionally, the connection module is specifically used for:

[0126] The browser page's identity identifier is stored in a preset identifier in the local storage space, and the preset identifier in the local storage space is monitored. The identity identifier in the local storage space is used to select an identity identifier from the local storage space and re-establish a long connection through the browser page corresponding to the selected identity identifier when the established long connection is broken.

[0127] Optionally, the device further includes:

[0128] The generation module is used to generate an identity identifier corresponding to the browser page before the determining module determines that a long connection flag for sending events to the server exists in the local storage space. The identity identifier is obtained by traversing all identity identifiers stored in the local storage space, and each identity identifier is different from every identity identifier in the total number of identity identifiers.

[0129] Optionally, the push module is specifically used for:

[0130] Monitor the long-connection flag stored in the local storage space and determine whether the long-connection is broken based on its current status. When the long-connection is determined to be broken, reconnect the long-connection using a preset function until the long-connection is successfully reconnected.

[0131] Optionally, the device further includes:

[0132] The update module is used by the push module to monitor the stored data in the local storage space and push the stored data to the browser page and the opened browser pages. When the browser page is closed, the module deletes the identity identifier from the local storage space and determines whether the browser page is a long-connection page. If the browser page is determined to be a long-connection page, the module determines whether there are other opened browser pages besides the browser page. If it is determined that there are other opened browser pages besides the browser page, the module updates the identity identifier of one of the opened browser pages to a preset field in the local storage space.

[0133] Please refer to Figure 4 This is a schematic block diagram of a device for connecting to a browser page, provided in an embodiment of this application. The device may include a memory 410 and a processor 420. Optionally, the device may further include a communication interface 430 and a communication bus 440. This device is similar to the one described above. Figure 1 The method implementation corresponds to this and can be executed. Figure 1 The specific functions of the device involved in the method embodiments can be found in the following description.

[0134] Specifically, memory 410 is used to store computer-readable instructions.

[0135] Processor 420 is used to process readable instructions stored in memory and is capable of executing... Figure 1 Each step in the method.

[0136] The communication interface 430 is used for signaling or data communication with other node devices. For example, it is used for communication with a server or terminal, or for communication with other device nodes, but the embodiments of this application are not limited thereto.

[0137] Communication bus 440 is used to enable direct communication between the above components.

[0138] In this embodiment, the communication interface 430 of the device is used for signaling or data communication with other node devices. The memory 410 can be high-speed RAM or non-volatile memory, such as at least one disk storage device. Optionally, the memory 410 can also be at least one storage device located remotely from the aforementioned processor. The memory 410 stores computer-readable instructions, which, when executed by the processor 420, enable the electronic device to perform the aforementioned... Figure 1The method process is shown. Processor 420 can be used on device 300 and is used to perform the functions in this application. Exemplarily, the processor 420 described above can be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components, and the embodiments of this application are not limited thereto.

[0139] This application embodiment also provides a readable storage medium, wherein when the computer program is executed by a processor, it performs the following... Figure 1 The method process executed by the electronic device in the illustrated method embodiment.

[0140] Those skilled in the art will understand that, for the sake of convenience and brevity, the specific working process of the device described above can be referred to the corresponding process in the aforementioned method, and will not be elaborated further here.

[0141] In summary, this application provides a method, apparatus, electronic device, and storage medium for connecting browser pages. The method includes: when a browser page is opened, determining whether a long-connection flag for sending events to a server exists in local storage; if the long-connection flag exists in local storage, storing the browser page's identity in local storage, wherein the browser page and the opened browser page share the long-connection; monitoring the stored data in local storage, and pushing the stored data to the browser page and the opened browser page. This method can avoid multiple long-connections consuming the connection limit, thus improving the loading speed of multiple browser pages.

[0142] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can also be implemented in other ways. The apparatus embodiments described above are merely illustrative. For example, the flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than those marked in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram and / or flowchart, and combinations of blocks in block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.

[0143] In addition, the functional modules in the various embodiments of this application can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.

[0144] If the aforementioned functions are implemented as software functional modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a portion 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, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0145] The above description is merely an embodiment of this application and is not intended to limit the scope of protection of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of protection of this application. It should be noted that similar reference numerals and letters in the following figures indicate similar items; therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures.

[0146] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included 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.

[0147] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

Claims

1. A method of linking browser pages, characterized by, The method comprises the following steps: When a browser page is opened, it is determined whether a long connection mark for server-sent events exists in a local storage space; When it is determined that the long connection mark for server-sent events exists in the local storage space, an identity of the browser page is stored in the local storage space, wherein the browser page and an opened browser page share the long connection; The stored data in the local storage space is monitored, and the stored data is pushed to the browser page and the opened browser page; The step of storing the identity of the browser page in the local storage space comprises the following steps:

2. The method of claim 1, wherein, The identity of the browser page is stored in a preset identity in the local storage space, and the preset identity in the local storage space is monitored, wherein the identity in the local storage space is used to select an identity from the local storage space by traversal when the established long connection is disconnected, and a long connection is re-established through the corresponding browser page of the selected identity. After the step of determining whether the long connection mark for server-sent events exists in the local storage space, the method further comprises the following steps: When it is determined that the long connection mark for server-sent events does not exist in the local storage space, an event long connection for connecting the browser page is established; 3. The method according to claim 1 or 2, characterized in that, The identity corresponding to the browser page is stored in the local storage space, and the stored data is pushed to the browser page and the opened browser page. The step of determining whether the long connection mark for server-sent events exists in the local storage space comprises the following steps: It is determined whether a preset field for storing the long connection exists in the local storage space; When it is determined that the preset field for storing the long connection exists in the local storage space, it is determined whether the preset field is the identity of the browser page; The step of determining that the long connection mark for server-sent events exists in the local storage space comprises the following steps:

4. The method according to claim 1 or 2, characterized in that, It is determined that the preset field is not the identity of the browser page. Before the step of determining that the long connection mark for server-sent events exists in the local storage space, the method further comprises the following steps:

5. The method according to claim 1 or 2, characterized in that, The identity corresponding to the browser page is generated, wherein the identity is obtained by traversing all identities stored in the local storage space, and the identity is different from each identity in the all identities. The step of monitoring the stored data in the local storage space comprises the following steps: The long connection mark stored in the local storage space is monitored, and it is determined whether the long connection is disconnected through the current state of the long connection; 6. The method of claim 1 or 2, wherein, When it is determined that the long connection is disconnected, the long connection is reconnected through a preset function until the long connection is reconnected. After the step of monitoring the stored data in the local storage space and pushing the stored data to the browser page and the opened browser page, the method further comprises the following steps: When the browser page is closed, the identity is deleted from the local storage space, and it is determined whether the browser page is a long connection page; When it is determined that the browser page is the long connection page, it is determined whether there is an opened browser page other than the browser page; When it is determined that there is an opened browser page other than the browser page, the identity of one of the opened browser pages is updated to a preset field in the local storage space.

7. An apparatus for linking browser pages, characterized by Comprising: A determination module is configured to determine whether there is a long connection flag for server-sent events in a local storage space when a browser page is opened; A connection module is configured to store the identity of the browser page in the local storage space when it is determined that the long connection flag for the server-sent events exists in the local storage space, wherein the browser page and an opened browser page share the long connection; A push module is configured to monitor the storage data in the local storage space and push the storage data to the browser page and the opened browser page; The connection module is specifically configured to store the identity of the browser page in a preset identity in the local storage space, and monitor the preset identity in the local storage space, wherein the identity in the local storage space is used to select one identity from the local storage space by traversal when the established long connection is disconnected, and reestablish a long connection through the corresponding browser page of the selected identity.

8. An electronic device, comprising: Comprising: A memory and a processor, the memory stores computer readable instructions, when the computer readable instructions are executed by the processor, the steps in the method of any one of claims 1-6 are run.

9. A computer-readable storage medium, characterized in that, Comprising: A computer program, when the computer program is run on a computer, the computer is caused to execute the method of any one of claims 1-6.

Citation Information

Patent Citations

  • Method for realizing multi-page sharing based on WebSocket, electronic equipment and storage medium

    CN115396414A