Page inactivation detection method, system and equipment and storage medium
By listening to network resource requests and calculating the waiting time, determining the page is inactivated and closing the main thread, the risk of data being stolen during unmanned periods is solved, and the effect of reducing security risks and improving resource utilization efficiency is achieved.
Patent Information
- Application Number
- CN202510071265.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-16
- Publication Date
- 2025-05-16
AI Technical Summary
During unattended hours, businesses and users’ data faces huge risks of being stolen, resulting in economic losses and reputational damage.
By listening to network resource requests, recording the request and time nodes, and calculating the waiting time based on the system time. If the waiting time exceeds the set time threshold, it is determined that the page is inactivated and the corresponding main thread is closed.
It effectively reduces security risks, prevents information leakage caused by long-term no operation on the page, releases invalid resources, improves resource utilization efficiency, and sets time thresholds by analyzing user behavior data, improving detection accuracy.
Smart Images

Figure CN120017326A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of computer technology, and in particular relates to a page inactivation detection method, system, device and storage medium. Background Art
[0002] In today's digital age, data security has become a top priority for enterprises and users. With the rapid development of information technology, the value of data has become increasingly prominent, covering a lot of important information such as business secrets of enterprises and personal privacy of users. However, in actual scenarios, especially during some unattended periods, data faces a great risk of being stolen.
[0003] For enterprises, if there are no effective security measures in their server rooms, office areas and other places during unattended periods after get off work or during holidays, hackers may take the opportunity to invade the network system and steal the company's core data, such as financial data, customer information, research and development results, etc. This will cause huge economic losses and reputation damage to the company, and may even affect the company's survival and development.
[0004] For users, personal computers, mobile devices, etc. may also become targets of data thieves when no one is using them. Once personal information such as ID numbers, bank card information, social accounts, etc. are stolen, it will not only lead to property losses, but also may cause a series of serious problems such as identity theft and privacy leakage, which will bring great troubles and security risks to users' lives. Therefore, both enterprises and users must attach great importance to data security issues during unattended periods and take practical and effective preventive measures to ensure the security and integrity of data. Summary of the invention
[0005] In view of the above-mentioned deficiencies in the prior art, the present invention provides a page inactivation detection method, system, device and storage medium to solve the above-mentioned technical problems.
[0006] In a first aspect, the present invention provides a page inactivation detection method, comprising: Monitor network resource requests and record network resource requests and time nodes; Calculate the waiting time based on the system time and the latest time node of the network resource request; If it is confirmed that the waiting time exceeds the set time threshold, the page is determined to be inactivated and the corresponding main thread is closed.
[0007] In an optional implementation, monitoring the network resource request and recording the network resource request and the time node include: Configure the monitored network resource address; Using a script running in the background to intercept the network resource request, and extracting the target address from the network resource request, if the target address matches the network resource address, then recording the network resource request and the time node; The network resource request is forwarded.
[0008] In an optional implementation, monitoring the network resource request and recording the network resource request and the time node include: Creating an asynchronous task queue, saving the network resource request intercepted by the main thread to the asynchronous task queue, and the main thread forwarding the saved completed network resource request; A background thread is used to extract a network resource address and a sending time from the network resource request saved in the asynchronous task queue, and the sending time is updated to a structure pre-constructed for the network resource address.
[0009] In an optional implementation, a background thread is used to extract a network resource address and a sending time from a network resource request saved in an asynchronous task queue, and the sending time is updated to a structure pre-constructed for the network resource address, including: Obtaining a monitoring object, wherein the monitoring object includes one or more network resource addresses; Build a unique corresponding structure for the network resource address and name the corresponding structure after the network resource address; A background thread is used to extract a network resource address and a sending time from a network resource request saved in an asynchronous task queue. When the background thread confirms that the extracted network resource address belongs to a monitoring object, the extracted sending time is saved in a corresponding structure.
[0010] In an optional implementation, the waiting time is calculated based on the system time and the time node of the latest network resource request, including: The structure is traversed, the time difference between the time in the structure and the current system time is calculated, and the time difference is output as the waiting time of the corresponding monitoring object.
[0011] In an optional embodiment, the method further comprises: Obtaining user behavior data, the user behavior data including access addresses and access times within a specified period; Divide user behavior data into multiple data groups according to access addresses; Clustering is performed on multiple data groups respectively to obtain multiple categories corresponding to each access address; Calculate the maximum difference in access time in each category; An average value of maximum differences belonging to the same access address is calculated, and the average value is set as a time threshold corresponding to the access address.
[0012] In an optional implementation, after determining that the page is inactivated, the method further includes: Add the network resource addresses of network resource requests that are determined to be page inactivation to the interception list; Using the script running in the background to intercept network resource requests, and matching the target address of the intercepted network resource request with the network resource address in the interception list; If the target address matches the network resource address in the interception list, the intercepted network resource request is cached in the interception task queue; If the target address matches the network resource address in the interception list, the intercepted network resource request is forwarded normally; Set the maximum cache time of the interception task queue, obtain the cache time of the network resource request in the interception task queue, and delete the corresponding network resource request if the cache time exceeds the maximum cache time; Receive user authentication information, confirm that the user authentication information is consistent with the standard authentication information cached locally, and forward the network resource request in the interception task queue.
[0013] In a second aspect, the present invention provides a page inactivation detection system, comprising: A monitoring module is used to monitor network resource requests and record network resource requests and time nodes; The timing module is used to calculate the waiting time based on the system time and the time node of the latest network resource request; The determination module is used to determine that the waiting time exceeds a set time threshold, then determine that the page is inactivated and close the corresponding main thread.
[0014] In a third aspect, a device is provided, comprising: A memory, used for storing a page inactivation detection program; The processor is used to implement the steps of the page inactivation detection method provided in the first aspect when executing the page inactivation detection program.
[0015] In a fourth aspect, a computer-readable storage medium is provided, on which a page inactivation detection program is stored. When the page inactivation detection program is executed by a processor, the steps of the page inactivation detection method provided in the first aspect are implemented.
[0016] The beneficial effects of the present invention are that the page inactivation detection method, system, device and storage medium provided by the present invention can reduce security risks and enable users to use the system more confidently by detecting and closing inactive pages, without worrying about information leakage and other problems caused by long-term inactivity of the page, and releasing invalid resources improves resource utilization efficiency. In addition, by analyzing user behavior data to set a time threshold, inactive pages can be detected more reasonably, improving detection accuracy.
[0017] In addition, the invention has a reliable design principle, a simple structure and a very broad application prospect. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0019] Figure 1 is a schematic flow chart of a method according to an embodiment of the present invention.
[0020] Figure 2 is a schematic block diagram of a system according to an embodiment of the present invention.
[0021] Figure 3 A schematic diagram of the structure of a device provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0022] In order to enable those skilled in the art to better understand the technical solutions in the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.
[0023] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art of the present invention. The terms used in the specification of the present invention herein are only for the purpose of describing specific embodiments and are not intended to limit the present invention.
[0024] The page inactivation detection method provided by the embodiment of the present invention is executed by a computer device, and accordingly, the page inactivation detection system runs in the computer device.
[0025] Figure 1 is a schematic flow chart of a method according to an embodiment of the present invention. Figure 1 The execution subject may be a page inactivation detection system. According to different requirements, the order of the steps in the flow chart may be changed, and some may be omitted.
[0026] like Figure 1 As shown, the method includes: S1, monitors network resource requests and records network resource requests and time nodes.
[0027] After the page is loaded, the browser starts listening to all network resource requests by calling the relevant APIs provided by the browser (such as using fetch event listeners in Web development). These requests include but are not limited to requests to load resources such as HTML files, CSS style sheets, JavaScript scripts, images, and videos.
[0028] When monitoring each network resource request, in addition to allowing the request to proceed normally, the detailed information of the request should also be recorded. The recorded content includes the requested URL address, which clarifies the target resource of the request; the request method (such as GET, POST, PUT, etc.), which is used to understand the type of operation requested; and the time node of the request initiation, which accurately records the position of the request on the system timeline. This time node can obtain the current timestamp by calling the system's time acquisition function (such as Date.now() in JavaScript).
[0029] Store the recorded network resource request information and the corresponding time nodes in a specific data structure. You can choose to use arrays, objects or databases to store this information for subsequent query and analysis. For example, in JavaScript, you can create an array, each array element is an object, and the object contains properties such as url, method, timestamp, etc. to store the corresponding request information and time nodes.
[0030] S2, calculates the waiting time based on the system time and the time node of the latest network resource request.
[0031] At each moment when the waiting time needs to be calculated (it can be triggered at a certain time interval, such as every second), obtain the current system time, and also obtain the timestamp by calling the system's time acquisition function. At the same time, obtain the time node of the latest network resource request from the previously stored records. If it is the first time to calculate the waiting time and no network resource request has been recorded, the waiting time is temporarily set to 0.
[0032] Subtract the time node of the latest network resource request from the current system time, and the time difference is the waiting time. For example, if the timestamp of the current system time is 1632456789000 and the timestamp of the latest network resource request is 1632456780000, then the waiting time is 1632456789000 - 1632456780000 = 9000 milliseconds (i.e. 9 seconds).
[0033] S3: If it is confirmed that the waiting time exceeds the set time threshold, the page is determined to be inactivated and the corresponding main thread is closed.
[0034] According to the business needs of the application and user habits, set an appropriate time threshold. This threshold can be fixed, such as 10 minutes, 30 minutes, etc.; it can also be dynamically adjusted according to different page types or user operation history. For example, for some pages that require real-time interaction, the time threshold can be set relatively short; while for some browsing pages, the time threshold can be appropriately extended.
[0035] The calculated waiting time is compared with the set time threshold. If the waiting time exceeds the set time threshold, it means that no new network resource requests have occurred for a long time, which probably means that the user has stopped interacting with the page, and the page is therefore determined to be inactive.
[0036] Once the page is determined to be inactive, appropriate measures need to be taken to close the corresponding main thread. In different programming environments, the methods of closing the main thread are different. In the Web browser environment, you can stop the operation of the main thread and release related resources by calling the window.close() method (under certain conditions) or using Web Workers related technologies.
[0037] In an embodiment of the present invention, based on step S1, a possible embodiment is given below to illustrate its specific implementation scheme in a non-limiting manner.
[0038] Configure the monitored network resource address; intercept the network resource request using a script running in the background, and extract the target address from the network resource request, if the target address matches the network resource address, record the network resource request and time node; forward the network resource request.
[0039] Specifically, the following steps are included: S101. Create an asynchronous task queue, save the network resource request intercepted by the main thread to the asynchronous task queue, and the main thread forwards the saved completed network resource request.
[0040] In a specific example, the request processing flow based on the Service Worker thread is as follows: In the JavaScript code of the main page, you first need to register the Service Worker: <!DOCTYPE html> <meta charset="UTF-8"> <script>if ('serviceWorker' in navigator) { navigator.serviceWorker.register('service - worker.js') .then(function (registration) { console.log('Service Worker 注册成功');}) .catch(function (error) { console.log('ServiceWorker 注册失败: ', error);});}< / script> .
[0041] (1) Create an asynchronous task queue: define a global array taskQueue as an asynchronous task queue.
[0042] (2) Intercept network resource requests: By listening to the fetch event, all network resource requests are intercepted in the Service Worker. When a request comes in, the request object is added to the taskQueue queue, and the event.respondWith method is used to continue forwarding the request to ensure that the request can proceed normally.
[0043] The following is another specific request interception and saving process: (1) Create a global asynchronous task queue to store intercepted network resource requests. In Python, this can be achieved using lists.
[0044] (2) Use the Flask framework to intercept network requests. Flask's routing system can capture all incoming requests.
[0045] (3) In the function that processes the request, add the request object to the task queue.
[0046] import asyncio async def save_to_queue(request): task_queue.append(request) print(f"Request {request.url} has been saved to the queue") async def handle_request(request): await save_to_queue(request) # Continue processing the request # Here you can forward the request or do other processing based on the actual situation return "The request has been processed".
[0047] (4) In the handle_request function, after completing the request and saving it to the queue, you can continue forwarding the request.
[0048] if __name__ == '__main__': app.run(debug=True).
[0049] S102. Utilize a background thread to extract a network resource address and a sending time from the network resource request saved in the asynchronous task queue, and update the sending time to a structure pre-constructed for the network resource address.
[0050] Obtain a monitoring object, which includes one or more network resource addresses; construct a unique corresponding structure for the network resource address, and name the corresponding structure after the network resource address; use a background thread to extract the network resource address and sending time from the network resource request saved in the asynchronous task queue, and if the background thread confirms that the extracted network resource address belongs to the monitoring object, save the extracted sending time to the corresponding structure.
[0051] In a specific example, the specific method of using the Service Worker thread to monitor requests includes the following process: (1) Initialization part: Create an empty asynchronous task queue taskQueue to store intercepted network resource requests.
[0052] Define the listeningObjects array, which contains one or more network resource addresses that need to be listened.
[0053] Initialize the resourceStructures object to store the structure corresponding to each monitored network resource address.
[0054] (2) Intercept the request and forward it: Use self.addEventListener('fetch',...) to listen to all network resource requests.
[0055] When a request is listened to, the request object is added to the taskQueue queue, and the request is forwarded using the event.respondWith method to ensure that the request can get a response normally.
[0056] (3) Background thread processing: Use setInterval to create a timed task that executes once a second to simulate a background thread.
[0057] Each time it is executed, check if there is a request in the taskQueue queue. If so, take a request out of the queue.
[0058] Extract the requested URL (i.e., network resource address) and current time as the sending time.
[0059] Check if the extracted network resource address is in the listeningObjects array. If so, create or get a corresponding structure for the address and add the send time to the sendTimes array of the structure.
[0060] The code example is as follows: / / Create an asynchronous task queue const taskQueue = []; / / Listening object, containing one or more network resource addresses const listeningObjects = [ 'https: / / example.com / api / data', 'https: / / example.com / images / logo.png' ]; / / Structure for storing network resource addresses and send times const resourceStructures = {}; / / Listen for fetch events and intercept network resource requests self.addEventListener('fetch', function (event) { const request =event.request; / / Save the request to the asynchronous task queue taskQueue.push(request); console.log('The request has been added to the queue:', request.url); / / The main thread forwards the saved network resource request event.respondWith( fetch(request) .then(response =>{ console.log('The request has been forwarded and a response has been received:', request.url); return response;}) .catch(error =>{console.error('Error forwarding request:', error);}) );}); / / Background thread extracts information from asynchronous task queue regularly setInterval(() =>{ if (taskQueue.length>0) { const request =taskQueue.shift(); const resourceAddress = request.url; const sendTime = newDate().getTime(); / / Confirm that the extracted network resource address belongs to the listening object if(listeningObjects.includes(resourceAddress)) { / / Build a unique corresponding structure for the network resource address, and name the corresponding structure after the network resource address if (!resourceStructures[resourceAddress]) { resourceStructures[resourceAddress]= { sendTimes: []};} / / Save the extracted send time to the corresponding structure resourceStructures[resourceAddress].sendTimes.push(sendTime); console.log('The send time has been saved to the structure:',resourceAddress, sendTime);}}}, 1000). .
[0061] In an embodiment of the present invention, based on step S2, a possible embodiment is given below to illustrate its specific implementation scheme in a non-limiting manner.
[0062] S201. New scheduled tasks: Add a setInterval timer task, which is executed every 5 seconds (can be adjusted according to actual needs).
[0063] At each execution, get the current system time currentTime.
[0064] S202. Traversing the structure: Use the for...of loop to iterate over each network resource address in the listeningObjects array.
[0065] Check whether there is a structure corresponding to the network resource address in the resourceStructures object.
[0066] S203. Calculate the time difference: If the structure exists and the sendTimes array in the structure has records, get the last send time lastSendTime in the array.
[0067] Calculate the difference between the current system time and the last sending time, timeDiff.
[0068] S204. Output waiting time: The calculated time difference timeDiff is output in the format of "the waiting time of the monitoring object [resource address] is: [time difference] milliseconds".
[0069] If the sendTimes array is empty, it means that the monitoring object has no sending record yet, and the corresponding prompt information is output.
[0070] If there is no corresponding structure, the corresponding prompt information is also output.
[0071] In an embodiment of the present invention, based on step S3, a possible embodiment is given below to illustrate its specific implementation scheme in a non-limiting manner.
[0072] S301. Set a time threshold.
[0073] (1) Data acquisition First, collect data through logging or user behavior tracking systems to obtain user behavior data. On the front end, you can use some browser APIs (such as history objects to record page access history, performance.now() to obtain timestamps, etc.), combined with the storage and query functions of the back-end database, to obtain user behavior data within a specified period. The specified period here can be set according to specific business needs, such as the past week, month, etc. User behavior data includes the addresses visited by users (such as complete URLs) and the corresponding access times, which will serve as the basis for subsequent analysis.
[0074] (2) Data grouping After obtaining the user behavior data, divide the data according to the access address. You can use the data structure and algorithm in the programming language to implement this operation. For example, in Python, you can use a dictionary to store data groups of different access addresses. Traverse the user behavior data list, and for each data record, use the access address as the key and add the record to the value list of the corresponding key. In this way, each key corresponds to an access address, and its value is a data group consisting of all access records of the address.
[0075] (3) Clustering processing Before clustering the data groups divided by access addresses, the data needs to be preprocessed. Since we are concerned about the time when a user accesses a certain access address within a specified period, the access time in each data group is extracted to form a time series. For example, for a data group of an access address, the extracted access time series may be [1600000000000, 1600000010000, 1600000020000,...], and these timestamps represent the specific time when the user accesses the address each time.
[0076] Convert the time series into a format suitable for DBSCAN algorithm processing. Usually, DBSCAN algorithm processes points in two-dimensional or multi-dimensional space. Here we can regard each timestamp as a point in one-dimensional space. For the convenience of algorithm implementation, these timestamps are organized into a list, each element is a list containing a single time value, such as [[1600000000000], [1600000010000], [1600000020000],...].
[0077] Set epsilon (neighborhood radius), which defines the neighborhood range of a point. In the time series scenario, epsilon represents the maximum time interval between two access times. If the two time intervals are less than or equal to epsilon, the two accesses are considered to belong to the same neighborhood. The value of epsilon needs to be determined considering the business scenario and data characteristics. For example, if a user frequently visits a page in a short period of time, epsilon can be set relatively small; if the user's access interval may be large, epsilon needs to be appropriately increased. You can determine a suitable epsilon by experimenting with different values and combining business understanding, such as setting it to 60000 (indicating 60 seconds) first, and then adjusting it according to the clustering results.
[0078] Set minPts (minimum number of points). This parameter indicates the minimum number of points that must be included in a neighborhood to form a core point. In user access behavior analysis, minPts can be used to filter out some isolated and possibly abnormal accesses. For example, if minPts is set to 3, then there must be at least 3 access time points in a neighborhood before the points in the neighborhood can be considered core points. Similarly, the value of minPts also needs to be adjusted according to actual conditions. You can start with a smaller value, such as 2 or 3, to observe the clustering effect.
[0079] Initialize the DBSCAN algorithm, pass the prepared time series data and the set epsilon and minPts parameters into the algorithm. The algorithm starts to traverse each point in the data set. For each point, calculate the number of points in its neighborhood. If the number of points in the neighborhood is greater than or equal to minPts, the point is marked as a core point; if the number of points in the neighborhood is less than minPts and the point is not a neighborhood point of any core point, the point is marked as a noise point; if a point is a neighborhood point of a core point but is not a core point itself, the point is marked as a boundary point. Starting from a core point, the algorithm connects all points belonging to the same cluster through breadth-first search (BFS) or depth-first search (DFS) to form a cluster. This cluster represents the access request generated by a user's uninterrupted use behavior. During the traversal process, the core point will continuously expand its neighborhood and add the points in the neighborhood to the same cluster. Repeat the above steps until all points are marked as part of a cluster or noise points.
[0080] After the DBSCAN algorithm is executed, multiple clustering results and some noise points will be obtained. For the noise points, choose to ignore them according to business needs.
[0081] For each cluster, the access time points contained in it are mapped back to the original data records, so that the access request set generated by the user's uninterrupted use behavior at the access address is obtained. For example, a cluster contains the time points [16000000000000, 1600000010000, 1600000020000]. By searching the original data records, the specific access request information corresponding to these time points can be obtained, such as the request parameters, request type, etc.
[0082] (4) Calculate the maximum difference For each cluster obtained by the DBSCAN algorithm (ie, a set of access requests generated by a user's uninterrupted usage behavior), find the earliest access time and the latest access time.
[0083] The difference between the latest access time and the earliest access time is calculated, and this difference is the maximum difference in access time in the cluster. This maximum difference reflects the longest duration of the user's access to the address during this uninterrupted use behavior.
[0084] (5) Calculate the average value and set the time threshold Calculate the average of the maximum differences of all categories belonging to the same access address. Add the maximum differences calculated for each category and divide by the number of categories to get the average value. This average value is the time threshold corresponding to the access address. In this way, a personalized time threshold is set for each access address, which can reflect the user's behavior pattern and time interval characteristics at the address.
[0085] S302: Compare the waiting time of the monitored object obtained in S2 with the corresponding time threshold. If the waiting time reaches the time threshold, the page is determined to be inactivated.
[0086] For each monitored object, its waiting time is compared with the corresponding time threshold. If the waiting time is greater than or equal to the time threshold, it means that the user has not performed any new operations on the monitored object (access address) for a long enough time, which meets the judgment condition of page deactivation.
[0087] Once the waiting time of a monitoring object reaches the time threshold, the page related to the monitoring object is determined to be inactivated. Here, a flag or state variable can be set in the program to record the inactivation state of the page for subsequent operations.
[0088] S303. Close the main process of the deactivated page.
[0089] In a browser environment, each page usually corresponds to a separate process (or thread in some cases). The main process associated with the deactivated page can be identified through the API provided by the browser (for example, in the Chrome browser, use the chrome.tabsAPI to obtain page information).
[0090] After determining the main process of the inactivated page, take appropriate measures to close the main process. In the browser environment, you can use the chrome.tabs.remove() method (for Chrome extensions) or the window.close() method (in ordinary web scripts, under certain conditions) to close the corresponding page process. You can also initiate communication with the main thread through the Service Worker thread to inform the main thread to execute specific operations such as related exit logic and verification logic.
[0091] On the basis of the above embodiment, in order to avoid the problem that the user needs to log in again due to the service interruption caused by closing the main thread, in one embodiment, a buffer mechanism is set, which specifically includes: 1. Add the network resource addresses of network resource requests that are determined to be page inactivation to the interception list.
[0092] When a page is determined to be inactive (based on previously set time thresholds and other conditions), the network resource addresses of the network resource requests related to the page are recorded for subsequent interception operations. In the page inactivation determination logic module, once a page is determined to be inactive, the network resource addresses of all network resource requests generated by the page are obtained. These addresses can be recorded when monitoring network resource requests. For example, in the previous Service Worker's fetch event monitoring, we can maintain a global variable to store the request address information of each page.
[0093] Add the obtained network resource address to a special interception list. This interception list can be an array or a more complex data structure, such as a hash table, for fast search and matching. For example, in JavaScript: / / Define interception list let interceptionList = []; / / Assume that pageInactive function is the function that determines page inactivation function pageInactive(pageRequests) { / / pageRequests is an array of all network resource request addresses generated by the page interceptionList = interceptionList.concat(pageRequests);}.
[0094] 2. Use the script running in the background to intercept the network resource request, and match the target address of the intercepted network resource request with the network resource address in the interception list.
[0095] The Service Worker thread in S1 is used to intercept requests for specific network resources.
[0096] In the Service Worker environment, all network resource requests are intercepted by listening to the fetch event. In other application environments, there are also corresponding network request interception mechanisms. For example, in the Service Worker: self.addEventListener('fetch', function (event) { const targetAddress= event.request.url; / / Match the address const isMatch = interceptionList.some(address =>targetAddress.includes(address)); if (isMatch) { / / Execute the operation after matching} else { / / No match, forward the request normally event.respondWith(fetch(event.request));}}).
[0097] Compare the target address of the intercepted network resource request with each network resource address in the interception list. You can use string matching methods, such as the includes function (in JavaScript), to determine whether the target address contains an address in the interception list. If the match is successful, it means that the request needs to be further processed; if it does not match, the request is forwarded normally.
[0098] 3. If the target address matches the network resource address in the interception list, the intercepted network resource request is cached in the interception task queue.
[0099] When it is found that the target address matches the network resource address in the interception list, the request is temporarily cached for subsequent processing.
[0100] Create a data structure in memory to store intercepted network resource requests. This data structure is the interception task queue. You can use an array, linked list, or queue data structure to implement it. For example, use an array in JavaScript to implement it: let interceptionTaskQueue = [].
[0101] Add the successfully matched network resource request to the interception task queue. At the same time, record the cache time of the request for subsequent time management. For example: self.addEventListener('fetch', function (event) { const targetAddress = event.request.url; const isMatch = interceptionList.some(address =>targetAddress.includes(address)); if (isMatch) { const requestWithTime = {request: event.request, cacheTime: new Date().getTime()}; interceptionTaskQueue.push(requestWithTime); / / You can choose not to forward the request directly and wait for subsequent processing} else { event.respondWith(fetch(event.request));}}).
[0102] 4. If the target address matches the network resource address in the interception list, the intercepted network resource request is forwarded normally In some cases, even if the target address matches the network resource address in the interception list, the request needs to be forwarded normally to ensure that some necessary functions can run normally. This is because some requests are necessary for the page to resume activity or are some public requests that do not affect security.
[0103] After matching the target address, it is necessary to determine whether the request can be forwarded normally according to some set rules. These rules are based on the type of request (such as HTTP method is GET and the requested resource is some static resource), the parameters of the request, etc. For example: self.addEventListener('fetch', function (event) { const targetAddress= event.request.url; const isMatch = interceptionList.some(address =>targetAddress.includes(address)); if (isMatch) { const request =event.request; / / Determine that the request type is GET and the requested resource is a specific static resource if(request.method === 'GET'&&request.url.match( / \.css|\.js|\.png|\.jpg / )) {event.respondWith(fetch(request));} else { const requestWithTime = {request: event.request, cacheTime: new Date().getTime()};interceptionTaskQueue.push(requestWithTime);}} else { event.respondWith(fetch(event.request));}}).
[0104] 5. Set the maximum cache time of the interception task queue, obtain the cache time of the network resource request in the interception task queue, and delete the corresponding network resource request if the cache time exceeds the maximum cache time.
[0105] In order to prevent the requests in the interception task queue from occupying too much memory resources, manage the cache time. Set a reasonable maximum cache time according to business needs and system resources. This time can be a fixed value or dynamically adjusted according to different request types or system status. For example, set the maximum cache time to 5 minutes (300000 milliseconds).
[0106] Periodically check the cache time of each network resource request in the interception task queue. You can use the setInterval function (in JavaScript) to perform this check operation regularly. For each request, calculate the difference between the current time and the cache time. If the difference exceeds the maximum cache time, delete the request from the interception task queue.
[0107] 6. Receive user authentication information, confirm that the user authentication information is consistent with the standard authentication information cached locally, and forward the network resource request in the interception task queue.
[0108] On the user interface, a verification mechanism is provided to allow users to enter verification information. This verification information can be a password, verification code, fingerprint, etc. After the user enters the verification information, it is sent to the backend for verification. On the front end, the verification information can be sent to the backend through form submission or specific API calls.
[0109] In the background, the received user authentication information is compared with the locally cached standard authentication information. The locally cached standard authentication information can be the password set when the user registers, or the authentication data generated by other security mechanisms. If the two are consistent, it means that the user identity is legitimate and the network resource request in the interception task queue can be forwarded. For example: / / Assume that the receiveVerificationInfo function receives user verification information functionreceiveVerificationInfo(userInfo) { const storedInfo = localStorage.getItem('standardVerificationInfo'); if (userInfo === storedInfo) { / / Verification is successful, forwarding requests in the interception task queue interceptionTaskQueue.forEach(requestWithTime =>{ fetch(requestWithTime.request) .then(response =>{ / / Processing response}) .catch(error =>{console.error('Error in forwarding request:', error);});}); / / Clear the interception task queue interceptionTaskQueue = [];} else { console.log('User verification failed');}}.
[0110] In some embodiments, the page inactivation detection system may include multiple functional modules composed of computer program segments. The computer programs of each program segment in the page inactivation detection system may be stored in a memory of a computer device and executed by at least one processor to perform (see Figure 1 Description) Page inactivity detection function.
[0111] In this embodiment, the page inactivation detection system can be divided into multiple functional modules according to the functions it performs, such as Figure 2 As shown. The functional modules of the system may include: a monitoring module, a timing module and a determination module. The module referred to in the present invention refers to a series of computer program segments that can be executed by at least one processor and can complete fixed functions, which are stored in a memory. In this embodiment, the functions of each module will be described in detail in subsequent embodiments.
[0112] A monitoring module is used to monitor network resource requests and record network resource requests and time nodes; The timing module is used to calculate the waiting time based on the system time and the time node of the latest network resource request; The determination module is used to determine that the waiting time exceeds a set time threshold, then determine that the page is inactivated and close the corresponding main thread.
[0113] Figure 3 The page deactivation detection method provided for the embodiment of the present application can be applied to a device. Those skilled in the art will appreciate that the device structure involved in the embodiment of the present invention does not constitute a limitation on the device, and the device may include more or fewer components than shown, or combine certain components, or arrange components differently. In an embodiment of the present invention, the device includes but is not limited to a laptop computer, a desktop computer, a workbench, a personal digital assistant, a server, a blade server, a mainframe computer, and other suitable computers. The device may also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the embodiments of the present application described and / or required herein.
[0114] The device 300 may include: a processor 310, a memory 320 and a communication unit 330. These components communicate via one or more buses. Those skilled in the art will appreciate that the server structure shown in the figure does not limit the present invention, and it may be a bus structure or a star structure, and may include more or fewer components than shown in the figure, or combine certain components, or arrange components differently.
[0115] The memory 320 may be used to store the execution instructions of the processor 310, and the memory 320 may be implemented by any type of volatile or non-volatile storage device 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 memory, flash memory, magnetic disk or optical disk. When the execution instructions in the memory 320 are executed by the processor 310, the device 300 is enabled to perform some or all of the steps in the following method embodiments.
[0116] The processor 310 is the control center of the storage device, and uses various interfaces and lines to connect various parts of the entire electronic device. It runs or executes software programs and / or modules stored in the memory 320, and calls data stored in the memory to perform various functions of the electronic device and / or process data. The processor can be composed of an integrated circuit (IC), for example, it can be composed of a single packaged IC, or it can be composed of a plurality of packaged ICs with the same or different functions. For example, the processor 310 can include only a central processing unit (CPU). In an embodiment of the present invention, the CPU can be a single computing core or multiple computing cores.
[0117] The communication unit 330 is used to establish a communication channel so that the storage device can communicate with other devices, receive user data sent by other devices or send user data to other devices.
[0118] The present invention also provides a computer storage medium, wherein the computer storage medium may store a program, and when the program is executed, the program may include some or all of the steps in each embodiment provided by the present invention. The storage medium may be a magnetic disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM).
[0119] Those skilled in the art can clearly understand that the technology in the embodiments of the present invention can be implemented by means of software plus a necessary general hardware platform. Based on this understanding, the technical solution in the embodiments of the present invention, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a disk or an optical disk, and other media that can store program codes, including several instructions for enabling a computer device (which can be a personal computer, a server, or a second device, a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention.
[0120] In this specification, the same or similar parts between the various embodiments can be referred to each other. In particular, for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the description in the method embodiment.
[0121] In the several embodiments provided by the present invention, it should be understood that the disclosed systems and methods can be implemented in other ways. For example, the system embodiments described above are only schematic. For example, the division of the modules is only a logical function division. There may be other division methods in actual implementation, such as multiple modules or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of systems or modules, which can be electrical, mechanical or other forms.
[0122] The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical modules, that is, they may be located in one place or distributed on multiple network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0123] In addition, each functional module in each embodiment of the present invention may be integrated into one processing module, or each module may exist physically separately, or two or more modules may be integrated into one module.
[0124] Although the present invention has been described in detail with reference to the accompanying drawings and in combination with the preferred embodiments, the present invention is not limited thereto. Without departing from the spirit and essence of the present invention, a person of ordinary skill in the art may make various equivalent modifications or substitutions to the embodiments of the present invention, and these modifications or substitutions shall be within the scope of the present invention. Any person of ordinary skill in the art may easily think of changes or substitutions within the technical scope disclosed by the present invention, and these shall be within the scope of protection of the present invention.
Claims
1. A page inactivation detection method, characterized in that: include: Monitor network resource requests and record network resource requests and time nodes; Calculate the waiting time based on the system time and the latest time node of the network resource request; If it is confirmed that the waiting time exceeds the set time threshold, the page is determined to be inactivated and the corresponding main thread is closed.
2. The method according to claim 1, characterized in that Monitor network resource requests and record network resource requests and time nodes, including: Configure the monitored network resource address; Using a script running in the background to intercept the network resource request, and extracting the target address from the network resource request, if the target address matches the network resource address, then recording the network resource request and the time node; The network resource request is forwarded.
3. The method according to claim 1, characterized in that Monitor network resource requests and record network resource requests and time nodes, including: Creating an asynchronous task queue, saving the network resource request intercepted by the main thread to the asynchronous task queue, and the main thread forwarding the saved completed network resource request; A background thread is used to extract a network resource address and a sending time from the network resource request saved in the asynchronous task queue, and the sending time is updated to a structure pre-constructed for the network resource address.
4. The method according to claim 3, characterized in that Extracting the network resource address and sending time from the network resource request saved in the asynchronous task queue using a background thread, and updating the sending time to a structure pre-built for the network resource address, including: Obtaining a monitoring object, wherein the monitoring object includes one or more network resource addresses; Build a unique corresponding structure for the network resource address and name the corresponding structure after the network resource address; A background thread is used to extract a network resource address and a sending time from a network resource request saved in an asynchronous task queue. When the background thread confirms that the extracted network resource address belongs to a monitoring object, the extracted sending time is saved in a corresponding structure.
5. The method according to claim 3 or 4, characterized in that: Based on the system time and the time node of the latest network resource request, the waiting time is calculated, including: The structure is traversed, the time difference between the time in the structure and the current system time is calculated, and the time difference is output as the waiting time of the corresponding monitoring object.
6. The method according to claim 1, characterized in that The method further comprises: Obtaining user behavior data, the user behavior data including access addresses and access times within a specified period; Divide user behavior data into multiple data groups according to access addresses; Clustering is performed on multiple data groups respectively to obtain multiple categories corresponding to each access address; Calculate the maximum difference in access time in each category; An average value of maximum differences belonging to the same access address is calculated, and the average value is set as a time threshold corresponding to the access address.
7. The method according to claim 1, characterized in that After determining that the page is inactivated, the method further includes: Add the network resource addresses of network resource requests that are determined to be page inactivation to the interception list; Using the script running in the background to intercept network resource requests, and matching the target address of the intercepted network resource request with the network resource address in the interception list; If the target address matches the network resource address in the interception list, the intercepted network resource request is cached in the interception task queue; If the target address matches the network resource address in the interception list, the intercepted network resource request is forwarded normally; Set the maximum cache time of the interception task queue, obtain the cache time of the network resource request in the interception task queue, and delete the corresponding network resource request if the cache time exceeds the maximum cache time; Receive user authentication information, confirm that the user authentication information is consistent with the standard authentication information cached locally, and forward the network resource request in the interception task queue.
8. A page inactivation detection system, characterized in that: include: A monitoring module is used to monitor network resource requests and record network resource requests and time nodes; The timing module is used to calculate the waiting time based on the system time and the time node of the latest network resource request; The determination module is used to determine that the waiting time exceeds a set time threshold, then determine that the page is inactivated and close the corresponding main thread.
9. A page inactivation detection device, characterized in that: include: A memory, used for storing a page inactivation detection program; A processor, configured to implement the steps of the page inactivation detection method according to any one of claims 1 to 7 when executing the page inactivation detection program.
10. A computer-readable storage medium storing a computer program, characterized in that: The readable storage medium stores a page inactivation detection program, and when the page inactivation detection program is executed by the processor, the steps of the page inactivation detection method according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Data processing method and device
CN114579200A
Page control method and device, electronic equipment and computer readable storage medium
CN114629673A
Page dormancy method and device, equipment and storage medium
CN118796280A
Page exception processing method and device, equipment and storage medium
CN119088467A
A method and apparatus for tracking activity by a user's computer on a data network
GB0507670D0