Implementation method and device for browser to acquire data
By installing the extension in the browser, using content scripts, background scripts and registered local applications, listening and parsing browser message data, calling original controls, COM components, etc. to obtain data, the browser cannot obtain data. Problem, cross-platform data acquisition is achieved.
Patent Information
- Application Number
- CN202510059084.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-15
- Publication Date
- 2025-02-18
- Estimated Expiration
- 2045-01-15
AI Technical Summary
The browser cannot obtain data by calling the original controls, COM components, etc., and does not want to change the calling method of the original controls, etc.
By installing and loading the extension in the browser, using content scripts, background scripts and registered local applications, listening to the browser's message data, parsing and calling the original controls, COM components, etc., the data is obtained.
It implements that the browser obtains data through an extension without changing the original controls and other calling methods, simplifies the data acquisition process and supports cross-platform.
Smart Images

Figure CN119474587A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of electronic information technology, and in particular relates to a method and device for implementing browser data acquisition. Background Art
[0002] In the early stages, browsers needed to obtain local data by calling controls, COM components, etc. With the development of information technology, browsers can no longer obtain data by calling the original controls, COM components, etc. Therefore, how to enable browsers to obtain data by calling the original controls, COM components, etc. without changing the calling method of the original controls, etc. is an issue that needs to be solved urgently. Summary of the invention
[0003] In order to solve the above technical problem, the present invention provides a method and device for implementing a browser to obtain data.
[0004] To this end, according to a first aspect of the present invention, a method for implementing a browser to obtain data is provided, the method being applicable to a browser having an extension installed, the extension including a content script, a background script, a registered local application, and a configuration file. When the extension is loaded by the browser through the configuration file, the method comprises: Step S1, the content script monitors data, obtains the message data when monitoring the message data sent by the browser, and sends the message data to the background script; Step S2, the background script receives the message data sent by the content script, and sends the message data to the registered local application; Step S3, the registered local application receives the message data, parses the message data, obtains the calling mode, the calling mode identifier, the calling method name corresponding to the calling mode, and the calling method parameters; Step S4, the registered local application determines the calling method and the parameters required by the method according to the calling method identifier and the calling method name corresponding to the calling method, and executes the calling method using the calling method parameters as the parameters required by the method to obtain an execution result; Step S5, the registered local application organizes the message response data according to the execution result, and sends the message response data to the background script; Step S6, the background script receives the message response data returned by the registered local application, and sends the message response data to the content script; Step S7: The content script receives the message response data sent by the background script, and sends the message response data to the browser.
[0005] According to a second aspect of the present invention, there is provided a device for implementing a browser to obtain data, the device comprising: a content script, a background script and a registered local application; The content script includes: a monitoring and obtaining module, a first sending module, and a first receiving module; The monitoring module is used to monitor data, and obtain the message data when monitoring the message data sent by the browser; The first sending module is used to send the message data to the background script; The first receiving module is used to receive the message response data sent by the background script; The first sending module is also used to send the message response data to the browser; The background script includes: a second receiving module and a second sending module; The second receiving module is used to receive the message data sent by the content script, and is also used to receive the message response data returned by the registered local application; The second sending module is used to send the message data to the registered local application, and is also used to send the message response data to the content script; The registered local application includes: a third receiving module, a parsing module, a determining module, an executing module, and a third sending module; The third receiving module is used to receive message data; The parsing module is used to parse the message data received by the third receiving module to obtain the calling mode of the control, the calling mode identifier, and the calling method name corresponding to the calling mode; The determination module is used to determine the calling method and the parameters required by the method according to the calling method identifier and the calling method name corresponding to the calling method; The execution module is used to execute the calling method using the calling method parameters as the parameters required by the method to obtain the execution result; The third sending module is further used to organize the execution result to obtain message response data, and send the message response data to the background script.
[0006] According to a third aspect of the present invention, a computer device, a memory, a processor and a computer program stored in the memory are provided, and the processor executes the computer program to implement a method for a browser to obtain data as described in the first aspect above.
[0007] According to a fourth aspect of the present invention, a computer-readable storage medium is provided, on which a computer program / instruction is stored, characterized in that when the computer program / instruction is executed by a processor, a method for implementing a browser to obtain data as described in the first aspect is implemented.
[0008] According to a fifth aspect of the present invention, a computer program product is provided, including a computer program / instruction, characterized in that when the computer program / instruction is executed by a processor, a method for implementing a browser to obtain data as described in the first aspect is implemented.
[0009] The beneficial effects brought about by the technical solution provided by the present invention include at least: The present invention provides a method and device for implementing data acquisition by a browser. The method comprises installing and loading an extension program in the browser, monitoring page events occurring in the browser, acquiring message data, parsing the message data to obtain a calling method, a calling method name, and calling method parameters, determining a calling method and the parameters required for the method, and executing the calling method using the calling method parameters as the parameters required for the method to obtain an execution result. With this solution, there is no need to publish multiple extensions corresponding to the calling method, and only one extension program is required to realize data acquisition through controls and the like. BRIEF DESCRIPTION OF THE DRAWINGS
[0010] For a clearer explanation, the embodiments of the present invention or the prior art are briefly introduced below in conjunction with the accompanying drawings. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other accompanying drawings can be obtained based on these accompanying drawings without creative work.
[0011] Figure 1 This is a flowchart of a method for implementing a browser to obtain data provided by the first embodiment of the present invention; Figure 2 It is a flowchart of an execution method of a registered local application in a method for implementing a browser to obtain data provided in Embodiment 3 of the present invention; Figure 3 It is a flowchart of an execution method of a registered local application in a method for implementing a browser to obtain data provided in a fourth embodiment of the present invention. DETAILED DESCRIPTION
[0012] To make the objectives, technical solutions and advantages of the present invention more clear, embodiments of the present invention will be described in further detail below with reference to the accompanying drawings.
[0013] When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present invention. Instead, they are only examples of devices and methods consistent with some aspects of the present invention as detailed in the attached claims.
[0014] Embodiment 1 Embodiment 1 of the present invention provides a method for implementing data acquisition by a browser, which is applicable to a browser with an extension program installed. Specifically, the extension program can call various controls, DLLs, and COM components to achieve data acquisition and operation, wherein the controls, DLLs, and COM components include but are not limited to the function of achieving data acquisition, and can also achieve other functions; Extensions include content scripts, background scripts, registered local applications, and configuration files. When an extension is loaded by the browser through a configuration file, such as Figure 1 As shown, the method specifically includes: Step 101, the content script monitors data, obtains the message data when monitoring the message data sent by the browser, and sends the message data to the background script; In one practicable manner, the message data is sent to the background script as follows: the content script sends the message data to the background script via an extension program interface provided by the browser; In one practicable manner, before sending the message data to the background script, the content script further includes: checking whether the message data is legal, and if so, sending the message data to the background script, otherwise, continuing to monitor the data; Step 102: The background script receives the message data sent by the content script, and sends the message data to the registered local application; Step 103: The registered local application receives the message data, parses the message data, and obtains the calling method, the calling method identifier, the calling method name corresponding to the calling method, and the calling method parameters; In an practicable manner, before executing step 104, the method further includes: the registered local application obtains the corresponding calling file according to the calling method identifier and the calling method name corresponding to the calling method, verifies the calling file, and executes step 104 if the verification is legal, and reports an error if the verification is illegal, and waits to receive the message data sent by the background script; Specifically, the verification of the called file includes: determining whether the signature information of the called file is complete, and determining whether the signature information of the called file is issued by a predetermined certificate. If both are true, the verification is legal, otherwise the verification is illegal; Step 104: The registered local application determines the calling method and the parameters required by the method according to the calling method identifier and the calling method name corresponding to the calling method, and executes the calling method using the calling method parameters as the parameters required by the method to obtain an execution result; In an practicable manner, step 104 specifically includes: the registered local application determines the calling method, the parameters required by the method and the parameter type according to the calling method identifier and the calling method name corresponding to the calling method, converts the calling method parameters according to the parameter type to obtain converted parameters, and executes the calling method using the converted parameters as the parameters required by the method to obtain an execution result; In an practicable manner, if the calling mode is the first mode, the registered local application determines the calling method and the parameters required by the method according to the calling mode identifier and the calling method name corresponding to the calling mode, including: the registered local application obtains the control or COM component corresponding to the calling mode identifier through an API function, obtains the calling method in the control or COM component according to the calling method name corresponding to the calling mode, and parses the calling method through the first preset method to obtain the method parameters; Further, if the calling method of the control is the first method, executing the calling method with the calling method parameters as the parameters required by the method to obtain the execution result is specifically: the registered local application executes the calling method with the calling method parameters as the parameters required by the method through the second preset method to obtain the execution result; In an practicable manner, if the calling mode is the second mode, the registered local application determines the calling method and the parameters required by the method according to the calling mode identifier and the calling method name corresponding to the calling mode, including: the registered local application obtains the corresponding dynamic link library according to the calling mode identifier, obtains the calling method in the dynamic link library with the same name as the calling method corresponding to the calling mode, and obtains the method parameters in the calling method; Step 105: The registered local application organizes the message response data according to the execution result, and sends the message response data to the background script; In an practicable manner, sending the message response data to the background script is specifically as follows: the registered local application sends the message response data to the background script through a native message transmission communication mechanism; Step 106: The background script receives the message response data returned by the registered local application, and sends the message response data to the content script; Step 107: The content script receives the message response data sent by the background script, and sends the message response data to the browser.
[0015] In an practicable manner, sending the message response data to the browser is specifically as follows: the content script sends the message response data to the browser through a first preset interface provided by the browser; In an practicable manner, the extension program is loaded by the browser through the configuration file, specifically comprising: the content script is started by the browser by obtaining the second preset field in the configuration file, the background script is started by the browser by obtaining the first preset field in the configuration file, and after the background script is started, an API function is called to start the registered local application; Specifically, after the background script is started, calling the API function to start the registered local application specifically includes: Step P1, the background script calls the API function and passes in the name of the local application as a parameter; Step P2, the background script finds the registered local application file with the same name as the passed-in parameter from the system registry through the API function; Step P3: The background script parses the registered local application file through the API function, obtains the local application path and starts the local application under the path.
[0016] Embodiment 2 Embodiment 2 of the present invention provides a method for implementing a browser to obtain data, which is applicable to a browser with an extension installed, wherein the extension includes a content script, a background script, a registered local application, and a configuration file. Specifically, the extension can call various controls, DLLs, COM components, etc., so as to obtain data, wherein the controls, DLLs, and COM components include but are not limited to the function of obtaining data, and can also implement other functions, and the data includes but is not limited to data stored in a local device, documents, and data stored in a smart device (such as UKEY) connected to the local device; One feasible manner includes, before implementing the method provided by the present invention, a process of installing an extension program in a browser. Specifically, the process of installing the extension program includes: the user installs it through an application store, or installs it through the extension program page of the browser, for example, when installing it in the Google Chrome browser, it is installed through the CRX file in the extension program page (the CRX file is the extension program file of the Google Chrome browser, and the CRX file contains all the files required for the browser extension program); when installing it in the Firefox browser, it is installed through the XPI file in the extension manager (XPI is the extension package file of the Firefox browser, which is usually used to implement the functions of the extended browser).
[0017] In this embodiment, installing the extension program also includes registering the system file (local application) including the name, path, and permissions into the system registry through an external program or installation package, so that when the browser is running, the extension program can find the registered system file and start it as a registered local application.
[0018] Specifically, the extension includes background scripts, content scripts, registered native applications (native message hosts), and configuration files (manifest.json files); In this embodiment, when the browser webpage is opened, the browser will load the extension program, determine the calling method required to obtain data through the extension program, and obtain data according to the determined calling method; Specifically, the browser loads the extension program as follows: obtaining a configuration file, and starting a background script, a content script, and a registered native message host in the extension program according to the configuration file. Furthermore, the configuration file is a file in JSON format, and the configuration file includes information such as name, permission, version, first preset field, and second preset field; For example, the configuration file is: { "manifest_version": 3, "name": "ex CA Chromium Extension", "version": "2.0.0.2", "description": "Chromium Native Messaging Extension for ex CA.", "author": "zl", "icons": { "32": "icon-32.png", "48": "icon-48.png", "128": "icon-128.png" }, "background": { "service_worker": "background_script.js" }, "content_scripts": [ { "matches": ["<all_urls> "], "js": [ "content_script.js" ] } ], "permissions": [ "nativeMessaging" ] }; In one practicable manner, the browser starts the background script, content script, and registered local application in the extension according to the configuration file, specifically including: Step A1, obtaining the first preset field in the configuration file to start the background script; For example, the first preset field is specifically: "background": { "service_worker": "background_script.js" }; Step A2: Obtain the second preset field in the configuration file, and start the content script through declarative injection; For example, the second preset field is specifically: "content_scripts": [ { "matches": ["<all_urls> "], "js": [ "content_script.js" ] } ]; Step A3: Start the registered local application by calling the API function through the background script; For example, the API function is specifically a connectNative function.
[0019] In this embodiment, a method for executing a content script in a method for implementing a browser to obtain data specifically includes: Step 201, the content script monitors data, and when monitoring message data sent by the browser script, sends the message data to the background script; In this embodiment, when the content script is started, the content script monitors data; In an practicable manner, the content script monitoring data specifically includes: the content script monitoring the message data sent by the browser script through a first monitor; In this embodiment, when the browser script detects that a page event is triggered and needs to interact with a local dynamic library, the browser script organizes the message data and calls the first preset interface to send the message data in the form of broadcast data; the first preset interface is specifically an API interface provided by the browser, which is independent of the operating system and can be called across browsers and platforms, and the behavior implemented on different operating systems is exactly the same.
[0020] Specifically, the browser script organizes the message data as follows: the js script in the browser page organizes the message data event.message, and the message data format is the JSON format. For example, the message data is as follows: {"org":"FEITIAN","Type":"1","dllname":"","clsid":"{A28A28DC-8AC5-442A-9BCD-7A2DB909AF5D}","method":"AddFormItem","in_param":[1, "name","zl"]}; Where "org" indicates company information, "Type" indicates the calling method, which includes the first method and the second method. The first method is to call controls or COM components, and the second method is to call DLL. If Type is 1, it means the calling method is the first method (controls or COM components), and if Type is 2, it means the calling method is the second method (DLL). "dllname" indicates the specific name of the DLL when the calling method is DLL, "clsid" indicates the unique identifier of the control when the calling method is a control or COM component, "method" indicates the calling method corresponding to the calling method, and "in_param" indicates the incoming parameters required for the calling method. For example, the first preset interface is window.postMessage(msg, "*"); For example, the message data obtained by the content script is: {"org":"FEITIAN","Type":"1","dllname":"","clsid":"{A28A28DC-8AC5-442A-9BCD-7A2DB909AF5D}","method":"AddFormItem","in_param":[1, "name","zl"]}; In this embodiment, the content script transmits data with the background script through the extension program interface provided by the browser; For example, in the Chrome browser, data transmission is carried out through the Chrome extension interface, and in the Firefox browser, data transmission is carried out through the interface provided by the WebExtensions API for implementing the message transmission function in the Firefox extension; In an practicable manner, before the content script sends the message data to the background script, the content script further includes: checking whether the message data is legal, and if so, sending the message data to the background script, otherwise, the message data is illegal and continues to be monitored; Specifically, the content script checks whether the message data is legal. Specifically, the content script determines whether the preset data in the message data meets the conditions. If yes, it is legal, otherwise it is illegal. For example, whether "org" in the message data is a preset value; Step 202: The background script sends the message data to the registered local application; In one practicable manner, the background script and the registered local application transmit data through the communication mechanism of NativeMessaging; Step 203: The registered local application receives the message data sent by the background script, parses the message data, and obtains the calling mode, calling mode identifier, calling method name corresponding to the calling mode, and calling method parameters; In this embodiment, the calling mode includes a first mode and a second mode; the first mode is specifically a control or a COM component, the second mode is specifically a dynamic link library, and the calling mode identifier includes a unique identifier of the control or COM component and a dynamic link library name; For example, the calling method names corresponding to the calling mode are: AddFormItem, USBKey_GenCertReq, USBKey_GetSN, USBKey_IsCertDNExist, USBKey_GetCertDN; Step 204: The registered local application determines the parameters required by the method according to the calling method identifier and the calling method name corresponding to the calling method; In an practicable manner, if the calling mode is the first mode, step 204 specifically comprises: obtaining a control or COM component corresponding to the calling mode identifier through an API function, obtaining a method in the control or COM component according to a calling method name corresponding to the calling mode, and obtaining parameters required by the method through a first preset method parsing the method; In an practicable manner, if the calling mode is the second mode, step 204 specifically comprises: obtaining a corresponding dynamic link library according to the calling mode identifier, obtaining a calling method in the dynamic link library having the same name as the calling method corresponding to the calling mode, and obtaining a method parameter in the calling method; For example, the calling method is AddFormItem ([in]BOOL IsShow, [in]DWORD index, [in]BSTRitemName, [in]BSTR itemContent, [out,retval]BSTR *ret), and the required parameters of the determined method include: [in]BOOL IsShow, [in]DWORD index, [in]BSTR itemName, [in]BSTR itemContent, [out,retval]BSTR *ret, and the parameter types are: Boolean data type, integer type, string type; In an practicable manner, before step 204, the following further includes: the registered local application obtains the corresponding calling file according to the calling method identifier and the calling method name corresponding to the calling method, verifies the calling file, and executes step 204 if the verification is legal, and reports an error if the verification is illegal, and waits to receive the message data sent by the background script; Specifically, the verification of the called file specifically includes determining whether the signature information of the called file is complete and whether the signature information of the called file is issued by a predetermined certificate. If both are true, the verification is legal; otherwise, the verification is illegal. For example, if the registered local application determines that the calling method is to obtain data by calling a control or COM component according to the "Type" field, the calling method identifier of the control is determined to be xxx.ocx according to the "clsid" field, and the calling file named xxx.ocx is obtained, and the calling file is verified; For example, if a registered local application determines according to the "Type" field that the calling method is to obtain data by calling a dynamic link library (DLL), the dynamic link library calling method identifier xxx.dll is obtained according to the "dllname" field, and a calling file named xxx.dll is obtained, and the calling file is verified.
[0021] In an practicable manner, step 204 specifically includes: the registered local application determines the calling method, the parameters required by the method and the parameter types according to the calling method identifier and the calling method name corresponding to the calling method, and converts the calling method parameters according to the determined parameter types to obtain converted parameters; Specifically, the parameter types include string BSTR, integer INT, integer type DWORD, Boolean data type BOOL, etc. In this embodiment, the registered local application matches the calling method parameters with the parameters required by the determined method, and converts the type of the calling method parameters into the determined parameter type; Specifically, if the determined parameter type is a Boolean data type, the calling method parameter is converted into a parameter of the Boolean data type; if the determined parameter type is an integer type, the calling method parameter is converted into a parameter of the integer type; if the determined parameter type is a string type, the calling method parameter is converted into a parameter of the string type; For example, if the calling method parameter is "in_param": [1, 1, "name", "zl"], the calling method parameter is matched with the required parameters determined in step 204 as follows: [in] BOOL IsShow corresponds to 1, [in] DWORD index corresponds to 1, [in] BSTR itemName corresponds to name, [in] BSTR itemContent corresponds to zl, and the parameter type conversion is as follows: 1 is converted to BOLL type as ture, 1 is converted to DWORD type as 1, name is converted to BSTR type, and zl is converted to BSTR type; Step 205: The registered local application uses the calling method parameters as the parameters required by the method to execute the calling method and obtain an execution result; In one possible implementation, step 205 includes: using the converted parameters as parameters required by the method to execute the calling method to obtain an execution result; In one possible implementation, if the calling method of the control is the first method, the calling method parameters are used as the parameters required by the method to execute the calling method to obtain the execution result, specifically: the registered local application executes the calling method by using the second preset method with the calling method parameters as the parameters required by the method to obtain the execution result; In one possible implementation, if the calling method of the control is the first method, the converted parameters are used as the parameters required by the method to execute the calling method to obtain the execution result, specifically: the registered local application uses the converted parameters as the parameters required by the method to execute the calling method to obtain the execution result through the second preset method; Specifically, the second preset method: GetInvokeDispatch; Step 206: The registered local application organizes the message response data according to the execution result, and sends the message response data to the background script; Step 207: The background script receives the message response data sent by the registered local application, and sends the message response data to the content script; For example, the message response data obtained by the background script is: {"org":"FEITIAN","Type":"1","dllname":"","clsid":"{A28A28DC-8AC5-442A-9BCD-7A2DB909AF5D}","method":"AddFormItem","code":"0","result":"name:zl"}; In one practicable manner, when the background script is started by the browser, the background script initializes the background page and starts the registered local application; Specifically, the background script starts the registered local application as follows: the background script calls an API function to start the registered local application; In one practicable manner, the background script calls an API function to start a registered local application, specifically including: Step 2071, the background script calls the API function and passes in the name of the local application as a parameter; Step 2072, the background script uses the API function to find a registered local application file with the same name as the input parameter from the system registry; Step 2073: The background script parses the registered local application file through the API function, obtains the local application path and starts the local application under the path; In this embodiment, the API function is specifically a browser extension API, for example, a connectNative function; in a Chrome browser, the API function is specifically: chrome.runtime.connectNative(), and in a Firefox browser, the API function is specifically: browser.runtime.connectNative(); Step 208, the content script sends the message response data to the browser; In an practicable manner, after sending the message response data to the browser, the method includes: a browser script receives the message response data, and parses the message response data to obtain result data; In this embodiment, the content script sends the message response data to the browser via the first preset interface; The method of organizing message data by using the above browser script can enable different browsers to obtain data through one extension program in different control calling modes.
[0022] Embodiment 3 Embodiment 3 of the present invention provides a method for implementing a browser to obtain data. In this embodiment, an extension program includes a background script, a content script, a registered local application, and a configuration file. When a browser web page is opened, the browser will load the extension program, determine the control calling method required to obtain data through the extension program, and obtain data according to the determined calling method. Specifically, the implementation method described in this embodiment includes the same extension program loading process as that of Embodiment 2 and the execution method of the background script and the content script, which will not be repeated here. Embodiment 3 uses the method of Embodiment 2 as the first method to obtain the calling method required for data, and takes the parameter types passed in by the registered local application to obtain data as strings as an example to describe in detail the execution method of the registered application in the implementation method, such as Figure 2 The figure shows a flowchart of an execution method of a registered local application in a method for implementing a method for obtaining data by a browser. The method specifically includes: Step 301: The registered local application receives the message data sent by the background script, and parses the message data to obtain the calling mode, calling mode identifier, calling method name corresponding to the calling mode, and calling method parameters; For example, the message data received by the registered local application is: {"org":"FEITIAN","Type":"1","dllname":"","clsid":"{A28A28DC-8AC5-442A-9BCD-7A2DB909AF5D}","method":"AddFormItem","in_param":[1,1,"name","zl"]}; For example, the calling method type required to obtain data is "Type":"1", the calling method identifier required to obtain data is "clsid":"{A28A28DC-8AC5-442A-9BCD-7A2DB909AF5D}", the calling method name corresponding to the calling method required to obtain data is "method":"AddFormItem", and the calling method parameters required to obtain data are "in_param":[1,1,"name","zl"]; Step 302: The registered local application obtains the control or COM component corresponding to the calling method identifier through an API function, and obtains the calling method in the control or COM component according to the calling method name corresponding to the calling method; For example, the API function is combaseapi; the obtained calling method is AddFormItem ([in]BOOLIsShow, [in]DWORD index, [in]BSTR itemName, [in]BSTR itemContent, [out, retval]BSTR *ret); Step 303: The registered local application parses the calling method through the first preset method to obtain the parameters and parameter types required by the method; For example, the first preset method is GetFuncDesc, which parses the parameters and parameter types in the method "AddFormItem". The parameters include [in]BOOL IsShow, [in]DWORD index, [in]BSTR itemName, [in]BSTRitemContent, [out,retval]BSTR *ret, and the parameter types include string BSTR, integer INT, integer type DWORD, Boolean data type BOOL, etc. Step 304: The registered local application converts the calling method parameters according to the determined parameter types to obtain converted parameters; In this embodiment, step 304 is specifically as follows: the registered local application matches the calling method parameters with the parameters required by the determined method, and converts the type of the calling method parameters into the determined parameter type; Specifically, if the determined parameter type is a Boolean data type, the calling method parameter is converted into a parameter of the Boolean data type; if the determined parameter type is an integer type, the calling method parameter is converted into a parameter of the integer type; if the determined parameter type is a string type, the calling method parameter is converted into a parameter of the string type; For example, if the calling method parameter is "in_param": [1, 1, "name", "zl"], the calling method parameter is matched with the required parameters determined in step 204 as follows: [in] BOOL IsShow corresponds to 1, [in] DWORD index corresponds to 1, [in] BSTR itemName corresponds to name, [in] BSTR itemContent corresponds to zl, and the parameter type conversion is as follows: 1 is converted to BOLL type as ture, 1 is converted to DWORD type as 1, name is converted to BSTR type, and zl is converted to BSTR type; Step 305: The registered local application uses the converted parameters as the parameters required by the method to execute the calling method and obtain the execution result through the second preset method; In an practicable manner, step 305 further includes: executing the calling method through the second preset method to obtain a status code of whether the method calling is successful; Specifically, the status code is code. If the code value is "0", it means success, and the execution result is obtained after success; For example, the second preset method is GetInvokeDispatch; the data type of the execution result is VARIANT*; Step 306: The registered local application converts the data type of the execution result and organizes the message response data according to the conversion result; For example, convert the execution result type VARIANT* to a string. For example, if the value of the VT_BSTR type is: name:zl, the converted value is: "name:zl"; In this embodiment, organizing the message response data according to the conversion result specifically includes converting the data type of the conversion result into a string type, and organizing the converted data into message response data in Jason format; For example, the message response data is: {"org":"FEITIAN","Type":"1","dllname":"","clsid":"{A28A28DC-8AC5-442A-9BCD-7A2DB909AF5D}","method":"AddFormItem","code":"0","result":"name:zl"}; Step 307: The registered local application sends the message response data to the background script.
[0023] Embodiment 4 Embodiment 4 of the present invention provides another method for implementing browser acquisition of data. In this embodiment, the extension program includes a background script, a content script, a registered local application, and a configuration file. When the browser web page is opened, the browser will load the extension program, determine the control calling method required for acquiring data through the extension program, and acquire data according to the determined calling method. Specifically, the loading process of the extension program and the execution method of the background script and the content script are the same as those in Embodiment 2, and will not be repeated here. Embodiment 4 mainly takes the registered local application side as the execution subject, and the control calling method required for acquiring data is a dynamic link library as an example for detailed description, such as Figure 3 As shown, a method for implementing a browser to obtain data specifically includes: Step 401: The registered local application receives the message data sent by the background script, and parses the message data to obtain the calling mode, calling mode identifier, calling method name corresponding to the calling mode, and calling method parameters; In one practicable manner, the parameter type in the message data received by the registered local application is a Jason string type; For example, the message data 1 received by the registered local application is: {"org":"FEITIAN","Type":"2","dllname":"ZTCertEnroll.dll","clsid":"","method":"USBKey_GenCertReq","param_type":"1","args":"{"CertDN":"ou=Customers,ou=ft,o=ft operation ca,c=cn,cn=653600000000001","iAlgType":4}"}; In an practicable manner, step 401 further includes: the registered local application determines an input parameter and an output parameter mode according to the calling method parameters, and the input parameter and output parameter mode includes no input parameter and no output parameter, input parameter and no output parameter, and input parameter and output parameter; Specifically, the registered local application determines the input and output parameter mode according to the calling method parameters: determines the input and output parameter mode according to a predetermined field in the calling method parameters, for example, the predetermined field is "param_inout"; For example, the message data 2 received by the registered local application is: {"org":"FEITIAN","Type":"2","dllname":"FTUSBKEY.dll","clsid":"","method":"USBKey_IsCertDNExist","param_type":"2","param_inout":"null","return_code":{"type":"BOOL"}}; According to "param_inout":"null", the input and output parameters are determined as no input and no output; For example, the message data 3 received by the registered local application is: {"org":"FEITIAN", "Type":"2", "dllname":"FTUSBKEY.dll", "clsid":"", "method":"USBKey_IsCertDNExist", "param_type":"2", "param_inout": { "param1": { "type":"IN", "key":"char_ptr", "value":"1234567890123456" }, "param2": { "type":"IN", "key":"int", "value":"1" }, }, "return_code": { "type":"BOOL" } }; According to "param_inout", the input and output parameters are determined as input parameters but no output parameters. For example, the message data 4 received by the registered local application is: "org":"FEITIAN", "Type":"2", "dllname":"FTUSBKEY.dll", "clsid":"", "method":"USBKey_GetCertDN", "param_type":"2", "param_inout": { "param1": { "type":"IN", "key":"char_ptr", "value":"1234567890123456" }, "param2": { "type":"IN", "key":"int", "value":"1" }, "param3": { "type":"OUT", "key":"char_ptr", "value":""}, "param4": { "type":"INOUT", "key":"int_ptr", "value":"100" }, }, "return_code": { "type":"BOOL" } }; According to "param_inout", the input and output parameters are determined as both input and output parameters; Step 402: The registered local application obtains the corresponding dynamic link library according to the calling method identifier, and determines the calling method and the parameters required by the method according to the calling method name corresponding to the calling method; For example, when the input and output mode is no input and no output, the confirmed calling method is: BOOL USBKey_IsCertDNExist(void) or int USBKey_IsCertDNExist(void) or char* USBKey_IsCertDNExist(void); For example, when the input and output parameter mode is input parameter but no output parameter, the determined calling method is: BOOL USBKey_IsCertDNExist(IN char* sn, IN int nIndex) or int USBKey_IsCertDNExist(IN char* sn, IN int nIndex) or char* USBKey_IsCertDNExist(IN char* sn, IN intnIndex), the required parameters of the determined method are: IN char* sn, IN int nIndex, and the determined parameter types include: basic data type char, integer data type int; For example, when the input and output parameter mode is both input and output, the determined calling method is: BOOL USBKey_GetCertDN(IN char* sn, IN int nIndex, OUT char* pDN, INOUT int* pDNLen) or int USBKey_GetCertDN(IN char* sn, IN int nIndex, OUT char* pDN, INOUT int*pDNLen) or char* USBKey_GetCertDN(IN char* sn, IN int nIndex, OUT char* pDN,INOUT int* pDNLen), the determined method requires parameters: IN char* sn, IN int nIndex, OUT char*pDN, INOUT int* pDNLen, the determined parameter type is the basic data type including: the basic data type char, the integer data type int; Step 403: The registered local application determines whether the parameter type needs to be converted according to the parameters required by the determination method. If so, step 404 is executed; otherwise, step 405 is executed; In this embodiment, the parameter passed in when calling a control, COM component, or DLL method can be a string or other types; In one practicable manner, the registered local application determines whether the parameter type needs to be converted according to the determined parameters required by the method. Specifically, the registered local application determines the parameter type of the parameter required by the method, and determines whether the parameter type of the parameter required by the method is consistent with the parameter type of the calling method parameter. If they are consistent, no conversion is required; if they are inconsistent, conversion is required. For example, if the parameter type of the method required parameter is the basic data type char, and the parameter type of the calling method parameter is BSTR, then no conversion is required; if the parameter type of the method required parameter is the integer type int, and the parameter type of the calling method parameter is BSTR, then conversion is required; Step 404: The registered local application performs parameter type conversion on the calling method parameters, uses the converted parameters as the parameters required by the method to execute the calling method to obtain the execution result, and then executes step 406; In one practicable manner, if it is determined that the parameter type of the method required parameter is a Boolean data type, the calling method parameter is converted into a parameter of the Boolean data type; if it is determined that the parameter type of the method required parameter is an integer type, the calling method parameter is converted into a parameter of the integer type; if it is determined that the parameter type of the method required parameter is a string type, the calling method parameter is converted into a parameter of the string type; Step 405: The registered local application uses the calling method parameters as the parameters required by the method to execute the calling method to obtain the execution result, and then executes step 406; In an practicable manner, step 404 or step 405 further includes: executing the calling method to obtain a status code of whether the method calling is successful; Specifically, the status code is code. If the code value is "0", it means success. The execution result is obtained after the call is successful. Step 406: The registered local application organizes message response data according to the execution result; For example, the execution result is: "return_msg":"{"RSAP10":"BASE64RSAP10","SM2P10":"BASE64SM2P10"}", or "return_code":{"type":"BOOL","value":"1"}; In an practicable manner, step 406 further includes: the registered local application converting the data type of the execution result, and organizing the message response data according to the converted data; For example, the message response data 1 corresponding to the message data 1 is: {"org":"FEITIAN","Type":"2","dllname":"ZTCertEnroll.dll","clsid":"","method":"USBKey_GenCertReq","code":"0","par am_type":"1","return_code":"0","return_msg":"{"RSAP10":"BASE64RSAP10","SM2P10":"BASE64SM2P10"}","err_msg":"ok!"}; For example, the message response data 2 corresponding to the message data 2 is: {"org":"FEITIAN","Type":"2","dllname":"FTUSBKEY.dll","clsid":"","method":"USBKey_IsCertDNExist ","code":"0","param_type":"2","param_inout":"null","return_code":{"type":"BOOL","value":"1"}}; For example, the message response data 3 corresponding to the message data 3 is: {"org":"FEITIAN","Type":"2","dllname":"FTUSBKEY.dll","clsid":"","method":"USBKey_IsCertDNExist ","code":"0","param_type":"2","param_inout":"null","return_code":{"type":"BOOL","value":"1"}}; For example, the message response data 4 corresponding to the message data 4 is: {"org":"FEITIAN","Type":"2","dllname":"FTUSBKEY.dll","clsid":"","method":"USBKey_GetCertDN","code":"0","param_type":"2", "param_inout": { "param1": { "type":"OUT", "key":"char_ptr", "value":"12abcd1234567890" }, "param2": { "type":"INOUT", "key":"int_ptr", "value":"16" }, }, "return_code":{"type":"BOOL","value":"1"}}; Step 406: The registered local application sends the message response data to the background script.
[0024] The present invention provides a method for implementing data acquisition by a browser. An extension program is installed and loaded in the browser. The extension program acquires message data when monitoring page events sent by the browser through a preset interface. A calling mode for acquiring data and a calling method corresponding to the calling mode are determined through the message data, thereby acquiring data through the determined calling mode and the corresponding calling method. With this solution, there is no need to publish multiple extensions corresponding to the calling mode. Only one extension program is needed to meet the needs of data acquisition. Moreover, the communication between the extension program and the browser is implemented through an interface, does not rely on an operating system, and can realize cross-platform data acquisition. This solution can acquire data by registering a local application in the system without changing the calling mode of the original control, etc., and the browser starts the registered local application to call the original control, COM component, etc.
[0025] The following are embodiments of the apparatus of the present invention, which can be used to implement the embodiments of the method of the present invention. For details not disclosed in the embodiments of the apparatus of the present invention, reference can be made to the embodiments of the method of the present invention.
[0026] An exemplary embodiment of the present invention provides a device for implementing a browser to obtain data, the device comprising a content script, a background script, and a registered local application; Specifically, the content script includes: a monitoring and obtaining module, a first sending module, and a first receiving module; The monitoring module is used to monitor data and obtain message data when monitoring message data sent by the browser; The first sending module is used to send the message data to the background script; The first receiving module is used for receiving the message response data sent by the background script; The first sending module is also used to send the message response data to the browser; Specifically, the background script includes: a startup module, a second receiving module, and a second sending module; The startup module is used to call the API function to start the registered local application; The second receiving module is used to receive message data sent by the content script, and is also used to receive message response data returned by the registered local application; The second sending module is used to send the message data to the registered local application, and is also used to send the message response data to the content script; Specifically, the registered local application includes: a third receiving module, a parsing module, a determining module, a converting module, an executing module, and a third sending module; The third receiving module is used to receive message data; The parsing module is used to parse the message data received by the third receiving module to obtain the calling mode, the calling mode identifier, the calling method name corresponding to the calling mode, and the calling method parameters; The determination module is used to determine the calling method and the parameters required by the method according to the calling method identifier and the calling method name corresponding to the calling method; The execution module is used to execute the calling method using the calling method parameters as the parameters required by the method to obtain the execution result; The third sending module is used to organize the message response data according to the execution result, and send the message response data to the background script; In an practicable manner, the first sending module is specifically used to send the message data to the background script through the extension program interface provided by the browser; In one practicable manner, the content script further includes a checking module, which is used to check whether the message data is legal, and if so, trigger the first sending module, otherwise, continue to monitor the data; In an practicable manner, the registered local application further includes a verification module, which is used to obtain a corresponding calling file according to the calling method identifier and the calling method name corresponding to the calling method, and verify the calling file. If the verification is legal, the obtaining module is triggered, and if the verification is illegal, an error is reported, and the message data sent by the background script is waited for to be received; Furthermore, the verification module is specifically used to determine whether the signature information of the called file is complete and whether the signature information of the called file is issued by a predetermined certificate. If both are true, the verification is legal; otherwise, the verification is illegal. In an practicable manner, if the calling mode is the first mode, the acquisition module is specifically used to obtain the control or COM component corresponding to the calling mode identifier through the API function, obtain the calling method in the control or COM component according to the calling method name corresponding to the calling mode, and parse the calling method through the first preset method to obtain the method parameters; If the calling mode is the second mode, the acquisition module is specifically used to acquire the corresponding dynamic link library according to the calling mode identifier, acquire the calling method with the same name as the calling method corresponding to the calling mode in the dynamic link library, and acquire the method parameters in the calling method.
[0027] In an implementable manner, the third sending module is specifically used to send the message response data to the background script through the communication mechanism of native message transmission; In an practicable manner, the first sending module is specifically used to send the message response data to the browser through a first preset interface provided by the browser; In an practicable manner, the device further comprises a loading module, which is used to start the content script by acquiring the second preset field in the configuration file, and to start the background script by acquiring the first preset field in the configuration file; Specifically, the background script also includes a startup module, which is used to call an API function to start a registered local application; Furthermore, the startup module is specifically used to call the API function to pass in the name of the local application as a parameter, find a registered local application file with the same name as the passed-in parameter from the system registry through the API function, parse the registered local application file through the API function, obtain the local application path and start the local application under the path.
[0028] It should be noted that the implementation device for obtaining data by a browser provided in the above embodiment only uses the division of the above functional modules as an example when executing the implementation method for obtaining data by a browser. In actual applications, the above functions can be allocated and completed by different functional modules as needed, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. In addition, the implementation device for obtaining data by a browser provided in the above embodiment and the implementation method for obtaining data by a browser are of the same concept, and the implementation process thereof is specifically shown in the method embodiment, which will not be repeated here.
[0029] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.
[0030] An embodiment of the present invention further provides a computer device, including a memory, a processor, and a computer program stored in the memory, wherein the processor executes the computer program to implement the steps of any of the aforementioned method embodiments.
[0031] The embodiment of the present invention further provides a computer-readable storage medium on which a computer program / instruction is stored, and when the program / instruction is executed by a processor, the steps of the method of any of the above embodiments are implemented. The computer-readable storage medium may include, but is not limited to, any type of disk, including a floppy disk, an optical disk, a DVD, a CD-ROM, a micro drive, and a magneto-optical disk, a ROM, a RAM, an EPROM, an EEPROM, a DRAM, a VRAM, a flash memory device, a magnetic card or an optical card, a nanosystem (including a molecular memory IC), or any type of medium or device suitable for storing instructions and / or data.
[0032] An embodiment of the present invention provides a computer program product, including a computer program / instruction, wherein the computer program / instruction, when executed by a processor, implements the steps of any of the methods in the aforementioned embodiments.
[0033] In the present invention, the terms "first", "second", etc. are only used for descriptive purposes and cannot be understood as indicating or implying relative importance or order; the term "plurality" refers to two or more, unless otherwise clearly defined. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can represent: the existence of A alone, the existence of A and B at the same time, and the existence of B alone. The character " / " generally indicates that the objects associated with each other are in an "or" relationship. Terms such as "install", "connect", "connect", and "fix" should be understood in a broad sense. For example, "connection" can be a fixed connection, a detachable connection, or an integral connection; "connection" can be a direct connection or an indirect connection through an intermediate medium. For those of ordinary skill in the art, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.
[0034] In the description of the present invention, it is necessary to understand that the directions or positional relationships indicated by the terms "upper" and "lower" etc. are based on the directions or positional relationships shown in the accompanying drawings, and are only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or unit referred to must have a specific direction, be constructed and operated in a specific orientation. Therefore, it cannot be understood as a limitation on the present invention.
[0035] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed by the present invention, which should be included in the protection scope of the present invention. Therefore, equivalent changes made according to the claims of the present invention are still within the scope covered by the present invention.
Claims
1. A method for implementing a browser to obtain data, the method being applicable to a browser with an extension installed, characterized in that: The extension program includes a content script, a background script, a registered local application and a configuration file. When the extension program is loaded by the browser through the configuration file, the method includes: Step S1, the content script monitors data, obtains the message data when monitoring the message data sent by the browser, and sends the message data to the background script; Step S2, the background script receives the message data sent by the content script, and sends the message data to the registered local application; Step S3, the registered local application receives the message data, parses the message data to obtain the calling mode, calling mode identifier, calling method name corresponding to the calling mode, and calling method parameters; Step S4, the registered local application determines the calling method and the parameters required by the method according to the calling method identifier and the calling method name corresponding to the calling method, and executes the calling method using the calling method parameters as the parameters required by the method to obtain an execution result; Step S5, the registered local application organizes the message response data according to the execution result, and sends the message response data to the background script; Step S6, the background script receives the message response data returned by the registered local application, and sends the message response data to the content script; Step S7: The content script receives the message response data sent by the background script, and sends the message response data to the browser.
2. The method for implementing the browser to obtain data according to claim 1, characterized in that: The sending of the message data to the background script specifically includes: the content script sending the message data to the background script through an extension program interface provided by the browser.
3. The method for implementing the browser to obtain data according to claim 1, characterized in that: Before sending the message data to the background script, the process also includes: the content script checks whether the message data is legal, and if so, sends the message data to the background script, otherwise, continues to monitor data.
4. The method for implementing the browser to obtain data according to claim 1, characterized in that: Before executing step S4, it also includes: the registered local application obtains the corresponding calling file according to the calling method identifier and the calling method name corresponding to the calling method, verifies the calling file, and executes step S4 if the verification is legal; if the verification is illegal, an error is reported, and waits to receive the message data sent by the background script.
5. The method for implementing the browser to obtain data as claimed in claim 4, characterized in that: The verification of the calling file specifically includes: determining whether the signature information of the calling file is complete, and determining whether the signature information of the calling file is issued by a predetermined certificate. If both are yes, the verification is legal, otherwise the verification is illegal.
6. The method for implementing the browser to obtain data according to claim 1, characterized in that: If the calling method is the first method, the registered local application determines the calling method according to the calling method identifier and the calling method name corresponding to the calling method, and the parameters required by the method include: The registered local application obtains the control or COM component corresponding to the calling method identifier through an API function, obtains a method in the control or COM component according to the calling method name corresponding to the calling method, and parses the method through a first preset method to obtain parameters required by the method.
7. The method for implementing the browser to obtain data according to claim 1, characterized in that: If the calling method is the second method, the registered local application determines the calling method according to the calling method identifier and the calling method name corresponding to the calling method, and the parameters required by the method include: The registered local application obtains the corresponding dynamic link library according to the calling method identifier, obtains the calling method with the same name as the calling method corresponding to the calling method in the dynamic link library, and obtains the parameters required by the method in the calling method.
8. The method for implementing a browser to obtain data as claimed in claim 1, characterized in that: The sending the message response data to the background script specifically includes: the registered local application sending the message response data to the background script through a communication mechanism of native message delivery.
9. The method for implementing the browser to obtain data as claimed in claim 1, characterized in that: The sending the message response data to the browser specifically includes: the content script sending the message response data to the browser through a first preset interface provided by the browser.
10. The method for implementing a browser to obtain data according to claim 1, characterized in that: The extension program is loaded by the browser through the configuration file specifically including: the content script is started by the browser by obtaining the second preset field in the configuration file, the background script is started by the browser by obtaining the first preset field in the configuration file, and after the background script is started, an API function is called to start the registered local application.
11. The method for implementing a browser to obtain data according to claim 10, characterized in that: After the background script is started, calling the API function to start the registered local application specifically includes: Step P1, the background script calls the API function and passes in the name of the local application as a parameter; Step P2, the background script finds a registered local application file with the same name as the input parameter from the system registry through the API function; Step P3: The background script parses the registered local application file through the API function, obtains the local application path and starts the local application under the path.
12. A device for implementing a browser to obtain data, the device comprising a content script, a background script and a registered local application; The content script includes: A monitoring and acquiring module, a first sending module, and a first receiving module; The monitoring module is used to monitor data, and obtain the message data when monitoring the message data sent by the browser; The first sending module is used to send the message data to the background script; The first receiving module is used to receive the message response data sent by the background script; The first sending module is also used to send the message response data to the browser; The background script includes: a second receiving module and a second sending module; The second receiving module is used to receive the message data sent by the content script, and is also used to receive the message response data returned by the registered local application; The second sending module is used to send the message data to the registered local application, and is also used to send the message response data to the content script; The registered local application includes: a third receiving module, a parsing module, a determining module, a converting module, an executing module, and a third sending module; The third receiving module is used to receive message data; The parsing module is used to parse the message data received by the third receiving module to obtain the calling mode, the calling mode identifier, the calling method name corresponding to the calling mode, and the calling method parameters; The determination module is used to determine the calling method and the parameters required by the method according to the calling method identifier and the calling method name corresponding to the calling method; The execution module is used to execute the calling method using the calling method parameters as the parameters required by the method to obtain the execution result; The third sending module is used to organize the execution result to obtain message response data, and send the message response data to the background script.
13. A computer device comprising a memory, a processor and a computer program stored in the memory, characterized in that: The processor executes the computer program to implement the steps of the method according to any one of claims 1 to 11.
14. A computer-readable storage medium having a computer program / instruction stored thereon, characterized in that: When the computer program / instructions are executed by a processor, the steps of the method according to any one of claims 1 to 11 are implemented.
15. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instructions are executed by a processor, the steps of the method according to any one of claims 1 to 11 are implemented.
Citation Information
Patent Citations
Data processing method, device and system
CN105553976A
Method and system for realizing browser access to intelligent key device
CN106203144A
Method for providing signature service and system thereof
CN106878319A
Method and device for interaction between client and webpage
CN106899455A
Cited By
Component object model calling method and device, equipment and storage medium
CN120560738A