Browser plug-in based Eval function execution method, device, equipment and medium
By configuring the execution function in the injected script of the webpage, obtaining the Eval source code data and executing it in the browser plugin, the compatibility problem of the Eval function under different specifications is solved, and compatibility execution under the ManifestV3 specification is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-10-17
- Publication Date
- 2026-04-07
AI Technical Summary
The Eval function is not compatible with the ManifestV2 and ManifestV3 specifications, causing browser plugins to fail to execute properly under different specifications.
By obtaining the webpage injection script, configuring the webpage injection execution function, calling the Eval source code data and sending it to the browser plugin, and using the browser plugin to introduce and execute the webpage injection execution script into the webpage to be loaded, the compatibility of the Eval function is achieved.
It achieves compatibility of the Eval function under different extension specifications for browser plugins, avoiding the complex executable configuration process.
Smart Images

Figure CN115795209B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of Internet technology, and in particular to a method, apparatus, device and medium for executing the Eval function based on a browser plugin. Background Technology
[0002] With the rapid development of terminal technology, terminals are possessing more and more functions, and browsers have become a standard feature of terminals. Users can browse web pages and obtain the information they need through browsers. Browser loading of web pages can be driven by browser plugins.
[0003] JavaScript is a web scripting language widely used in web application development. It's commonly used to add various dynamic functionalities to web pages, providing users with a smoother and more aesthetically pleasing browsing experience. The `Eval` function is a built-in JavaScript function that allows dynamic execution of JavaScript source code. Many scenarios require using `Eval` to obtain the execution result of a code snippet, such as replacing some native functions in the webpage context. Under the Manifest.v2 specification, the `Eval` function was allowed to execute in the browser plugin's background; however, this is prohibited under the Manifest.v3 specification, making `Eval` incompatible across different specifications. Summary of the Invention
[0004] The purpose of this application is to provide a method, apparatus, device, and medium for executing the Eval function based on a browser plugin, so as to solve the technical problem that the Eval function is not compatible under different specifications in related technologies.
[0005] To address the aforementioned technical problems, this application provides a method for executing the Eval function based on a browser plugin, employing the following technical solution:
[0006] Obtain the web page injection script and configure the web page injection execution function in the web page injection script;
[0007] The web page injection execution function is called to obtain Eval source code data, obtain the web page injection execution script, and send the web page injection execution script to the browser plugin;
[0008] The browser plugin introduces the webpage injection execution script into the webpage to be loaded, and executes the Eval source code data in the webpage injection execution script to obtain the execution result.
[0009] Furthermore, the step of executing the Eval source code data in the webpage injection execution script to obtain the execution result includes:
[0010] The browser plugin receives the Eval source code data from the web page injection execution script through the plugin background, and calls the pre-set web page injection function to pass the Eval source code data to the web page script of the web page to be loaded.
[0011] The Eval source code data is transmitted to the script execution function of the browser plugin via the web page script;
[0012] The script execution function executes the Eval source code data to obtain the execution result.
[0013] Furthermore, the step of calling a pre-set webpage injection function to pass the Eval source code data to the webpage script to be loaded includes:
[0014] The web page script of the web page to be loaded is introduced and loaded through a pre-set web page injection function;
[0015] In response to the completion of the loading of the web page script, the web page injection event in the web page injection function is triggered;
[0016] Based on the webpage injection event, the Eval source code data is passed to the webpage script.
[0017] Furthermore, the step of introducing and loading the webpage script of the webpage to be loaded through a pre-set webpage injection function includes:
[0018] The path attribute corresponding to the web page script is obtained from the script tag through the web page injection function, and the web page script is obtained according to the path attribute.
[0019] The webpage script is executed through the webpage injection function to load resources.
[0020] Furthermore, before the step of executing the Eval source code data through the script execution function to obtain the execution result, the following is also included:
[0021] Call the tag retrieval function of the browser plugin to obtain the tag information of the webpage to be loaded, and obtain the tag identifier from the tag information;
[0022] The plugin backend passes the tag identifier to the browser plugin's script execution function.
[0023] Furthermore, the step of executing the Eval source code data through the script execution function to obtain the execution result includes:
[0024] The script execution function is invoked to obtain the URL of the webpage to be loaded based on the tag identifier;
[0025] The Eval source code data is injected into the webpage to be loaded based on the webpage URL using the webpage injection function.
[0026] The script execution function is called to execute the Eval source code data and obtain the execution result.
[0027] Furthermore, the step of sending the webpage injection execution script to the browser plugin includes:
[0028] The webpage injection execution function is used to call the browser message passing function to send the webpage injection execution script to the browser plugin.
[0029] To address the aforementioned technical problems, this application also provides an Eval function execution device based on a browser plugin, employing the following technical solution:
[0030] The configuration module is used to obtain the web page injection script and configure the web page injection execution function in the web page injection script;
[0031] The acquisition module is used to call the web page injection execution function to obtain Eval source code data, obtain the web page injection execution script, and send the web page injection execution script to the browser plugin;
[0032] The execution module is used to introduce the web page injection execution script into the web page to be loaded through the browser plugin, and execute the Eval source code data in the web page injection execution script to obtain the execution result.
[0033] To address the aforementioned technical problems, this application also provides a computer device that employs the following technical solution:
[0034] The computer device includes a memory and a processor. The memory stores computer-readable instructions, and the processor executes the computer-readable instructions to implement the steps of the browser plugin-based Eval function execution method as described above.
[0035] To address the aforementioned technical problems, this application also provides a computer-readable storage medium, employing the technical solution described below:
[0036] The computer-readable storage medium stores computer-readable instructions, which, when executed by a processor, implement the steps of the browser plugin-based Eval function execution method as described above.
[0037] Compared with the prior art, the embodiments of this application have the following main advantages:
[0038] This application obtains a webpage injection script, configures a webpage injection execution function within the script, calls the script to retrieve Eval source code data, obtains the webpage injection execution script, and transmits it to a browser plugin. The browser plugin then imports the webpage injection execution script into the webpage to be loaded and executes the Eval source code data within it, obtaining the execution result. This application, by using the webpage injection execution function configured in the script to call the Eval source code data and obtain the execution script, and by importing and executing the script into the webpage to be loaded via a browser plugin, enables the browser plugin to execute the Eval function under different extension specifications, achieving compatibility of the Eval function. Attached Figure Description
[0039] To more clearly illustrate the solutions in this application, the accompanying drawings used in the description of the embodiments of this application will be briefly introduced below. Obviously, the accompanying drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0040] Figure 1 This is an exemplary system architecture diagram to which this application can be applied;
[0041] Figure 2 This is a flowchart of an embodiment of the browser plugin-based Eval function execution method according to this application;
[0042] Figure 3 yes Figure 2 A flowchart of a specific implementation of step S203;
[0043] Figure 4 This is a schematic diagram of a structure of an embodiment of the browser plugin-based Eval function execution device according to this application;
[0044] Figure 5 This is a schematic diagram of the structure of one embodiment of the computer device according to this application. Detailed Implementation
[0045] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application pertains; the terminology used herein in the specification of the application is for the purpose of describing particular embodiments only and is not intended to be limiting of the application; the terms "comprising" and "having," and any variations thereof, in the specification, claims, and foregoing drawings of this application, are intended to cover non-exclusive inclusion. The terms "first," "second," etc., in the specification, claims, or foregoing drawings of this application are used to distinguish different objects, not to describe a particular order.
[0046] In this document, the term "embodiment" means that a particular feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of this application. The appearance of this phrase in various places throughout the specification does not necessarily refer to the same embodiment, nor is it a separate or alternative embodiment mutually exclusive with other embodiments. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.
[0047] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings.
[0048] This application provides a browser plugin-based Eval function execution method, which can be applied to, for example... Figure 1 In the system architecture 100 shown, the system architecture 100 may include terminal devices 101, 102, and 103, a network 104, and a server 105. The network 104 is used as a medium to provide a communication link between the terminal devices 101, 102, and 103 and the server 105. The network 104 may include various connection types, such as wired or wireless communication links or fiber optic cables, etc.
[0049] Users can use terminal devices 101, 102, and 103 to interact with server 105 via network 104 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 101, 102, and 103, such as web browser applications, shopping applications, search applications, instant messaging tools, email clients, social media platform software, etc.
[0050] Terminal devices 101, 102, and 103 can be various electronic devices with displays and support web browsing, including but not limited to smartphones, tablets, e-book readers, MP3 players (Moving Picture Experts Group Audio Layer III), MP4 players (Moving Picture Experts Group Audio Layer IV), laptops, and desktop computers, etc.
[0051] Server 105 can be a server that provides various services, such as a backend server that supports the pages displayed on terminal devices 101, 102, and 103.
[0052] It should be noted that the browser plugin-based Eval function execution method provided in this application embodiment is generally executed by a server / terminal device, and correspondingly, the browser plugin-based Eval function execution device is generally set in the server / terminal device.
[0053] It should be understood that Figure 1 The number of terminal devices, networks, and servers shown is merely illustrative. Depending on implementation needs, any number of terminal devices, networks, and servers can be included.
[0054] The `Eval` function is a built-in JavaScript function that allows dynamic execution of JavaScript source code. It's used in many scenarios to obtain the execution result of a code snippet. Under the Manifest.v2 specification, `Eval` is allowed to execute in the background of browser plugins; however, it is prohibited under the Manifest.v3 specification. To address the issue of `Eval` being prohibited in the background of browser plugins under the latest Manifest.v3 specification, this application proposes a browser plugin-based method for executing the `Eval` function. (References) Figure 2 The flowchart illustrates an embodiment of the browser plugin-based Eval function execution method according to this application, including the following steps:
[0055] Step S201: Obtain the web page injection script and configure the web page injection execution function in the web page injection script.
[0056] In this embodiment, the web page injection script is the script code injected into the web page by the browser plugin, denoted as contentScript. A function is defined in the web page injection script contentScript, that is, a web page injection execution function is pre-configured. The web page injection execution function is denoted as runtimeInjectPageScript. The web page injection execution function defines source code call parameters to obtain Eval source code data.
[0057] Step S202: Call the web page injection execution function to obtain Eval source code data, get the web page injection execution script, and send the web page injection execution script to the browser plugin.
[0058] In this embodiment, the source code call parameter in the web page injection execution function runtimeInjectPageScript is called to obtain the Eval source code data, and the Eval source code data is passed to the parameter value corresponding to the source code call parameter to obtain the web page injection execution script.
[0059] The `Eval` source code data consists of the code executed through the `Eval` function. This data is passed as a string, corresponding to the parameter value in the source code call. For example, when calling the web page injection execution function `runtimeInjectPageScript` with a code snippet declaring a variable and assigning it the value 123, the result is `runtimeInjectPageScript('var test=123')`. In this case, the web page injection execution function within the injected script `contentScript` is `runtimeInjectPageScript('var test=123')`, and the script at this point is the web page injection execution script.
[0060] In this embodiment, the web page injection execution script is passed to the browser plugin through the runtimeInjectPageScript function.
[0061] At least one browser is installed on each of the terminal devices 101, 102, and 103. Each browser has a browser plugin installed. These browser plugins, as third-party applications, can be pre-generated by developers and testers. After the terminal devices 101, 102, and 103 are manufactured, the developers and testers can install the generated browser plugins into the browsers. The browser plugins can be used to drive the browser to execute scripts injected into web pages, thereby causing the Eval function to execute the corresponding source code data, enabling the browser to load the web page.
[0062] The browser plugin's SDK (Software Development Kit) includes the following functions: browser.runtime.sendMessage for sending messages, browser.runtime.onMessage for receiving messages, browser.tabs.query for retrieving tab information, and browser.scripting.executeScript for executing scripts.
[0063] It should be emphasized that, to further ensure the privacy and security of the webpage injection execution script, the aforementioned webpage injection execution script can also be stored in a blockchain node.
[0064] The blockchain referred to in this application is a novel application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanisms, and encryption algorithms. Essentially, a blockchain is a decentralized database, a chain of data blocks linked together using cryptographic methods. Each data block contains information about a batch of network transactions, used to verify the validity of the information (anti-counterfeiting) and generate the next block. A blockchain can include an underlying blockchain platform, a platform product service layer, and an application service layer.
[0065] Step S203: Inject a web page injection execution script into the web page to be loaded through a browser plugin, and execute the Eval source code data in the web page injection execution script to obtain the execution result.
[0066] In this embodiment, the browser plugin introduces a web page injection execution script into the web page to be loaded. The web page injection execution script will then be executed automatically in the web page to generate page information. The Eval source code data is part of the web page injection execution script. During the execution of the web page injection execution script, the built-in Eval function will be called to execute the Eval source code data and generate the execution result.
[0067] This application obtains the web injection execution script by calling the Eval source code data through the web injection execution function configured in the web injection script. Based on the browser plugin, the web injection execution script is introduced into the web page to be loaded and executed. This allows the browser plugin to execute the Eval function under different extension specifications, such as executing the Eval function in the latest ManifestV3 specification, thus achieving compatibility of the Eval function.
[0068] In some optional implementations of this embodiment, the step of injecting the Eval source code data in the execution script into the webpage in step S203 above to obtain the execution result includes:
[0069] Step S301: Receive the Eval source code data from the web page injection execution script through the browser plugin's plugin backend, and call the pre-set web page injection function to pass the Eval source code data to the web page script to be loaded.
[0070] In this embodiment, the browser plugin's background is represented by "background". "Background" is primarily used for logic processing, such as network interception. After receiving the Eval source code data, "background" calls a pre-set webpage injection function to pass the Eval source code data to the webpage script to be loaded.
[0071] The web page injection function is custom-defined and denoted by injectPageScript. It is mainly used to insert target code into the web page.
[0072] In this embodiment, the step of calling a pre-set webpage injection function to pass the Eval source code data to the webpage to be loaded includes:
[0073] The web page script of the web page to be loaded is introduced and loaded through a pre-set web page injection function;
[0074] In response to the completion of webpage script loading, the webpage injection event in the webpage injection function is triggered;
[0075] Based on the webpage injection event, the Eval source code data is passed to the webpage script.
[0076] The web page script is represented by the page-script.js script. The web page injection function injectPageScript imports the page-script.js script. When the page-script.js script finishes loading, the web page injection event is triggered. The web page injection event is contained within the web page injection function injectPageScript and is represented by the custom event injectPageScript.
[0077] The `page-script.js` script listens for the custom event `injectPageScript` and calls the `Eval` function to execute the `Eval` source code data. When the custom event `injectPageScript` is triggered, the `injectPageScript` function passes the `Eval` source code data. Simultaneously, when the `page-script.js` script detects that the custom event `injectPageScript` has been triggered, it receives the `Eval` source code data passed from the `injectPageScript` function.
[0078] In this embodiment, by passing the Eval source code data to the imported web page script, the web page script can call the Eval function to execute the Eval source code data. This can overcome the execution barriers of the Eval function under different extension specifications, achieve compatibility in executing the Eval function, and avoid the complex process of configuring the executable program.
[0079] Step S302: Transfer the Eval source code data to the browser plugin's script execution function via the web page script.
[0080] In this embodiment, the webpage script page-script.js transmits the received Eval source code data to the browser plugin's script execution function browser.scripting.executeScript, and finally uses the script execution function browser.scripting.executeScript to achieve the effect of the Eval function.
[0081] Step S303: Execute the Eval source code data through the script execution function to obtain the execution result.
[0082] In this embodiment, the script execution function browser.scripting.executeScript calls the web page injection function injectPageScript, and the web page injection function injectPageScript executes the Eval source code data.
[0083] Specifically, the web page injection function `injectPageScript` executes the `Eval` source code data. The `injectPageScript` function imports the web page script `page-script.js`, which in turn calls the `Eval` function to execute the `Eval` source code data and obtain the execution result.
[0084] In this embodiment, the script execution function browser.scripting.executeScript acts as a concatenation mechanism, linking the Eval function with the browser plugin. This allows the Eval function to be executed under different versions of the extended specification, such as ManifestV2 and ManifestV3, thus achieving compatibility of the Eval function and making it unrestricted by specification versions.
[0085] In this embodiment, the steps of introducing and loading the webpage script of the webpage to be loaded through a pre-set webpage injection function include:
[0086] The path attribute corresponding to the web page script is obtained from the script tag through the web page injection function, and the web page script is obtained based on the path attribute.
[0087] Execute web page scripts by injecting functions to load resources.
[0088] When customizing the webpage injection function `injectPageScript`, it first creates a script tag (`script`), which has a path attribute (`src`). The `src` attribute is the resource path, i.e., the location of the referenced resource.
[0089] In this embodiment, the resource link set by the src attribute is the link to the page-script.js script. After the src attribute is set to the link to the page-script.js script, the web page injection function injectPageScript will automatically load the resource of this link, that is, the page-script.js script will be loaded.
[0090] In this embodiment, obtaining script resources through path attributes can improve resource acquisition efficiency.
[0091] In some alternative implementations, the following steps are included before executing the Eval source code data via a script execution function to obtain the execution result:
[0092] Call the browser plugin's tag retrieval function to obtain the tab information of the webpage to be loaded, and extract the tag identifier from the tab information;
[0093] The tag identifier is passed to the browser plugin's script execution function through the plugin backend.
[0094] In this embodiment, while defining the custom webpage injection function `injectPageScript`, the tab information of the webpage to be loaded is obtained by calling the browser plugin's tab retrieval function. The tab retrieval function will then directly return all tab information of the current webpage to be loaded.
[0095] The tag retrieval function is browser.tabs.query. After receiving the Eval source code data, the browser plugin's background calls browser.tabs.query to obtain all the tab information of the webpage to be loaded. The tab information includes, but is not limited to, tag identifiers (i.e., tag IDs), index, whether active is selected, and title. The tag identifiers are extracted from the tab information, and the background then passes the tag identifiers to the script execution function browser.scripting.executeScript.
[0096] In this embodiment, the tag identifier of the webpage to be loaded is obtained by calling the tag acquisition function in the background of the browser plugin, and then passed to the script execution function. This can realize the location of the webpage to be loaded, so that the Eval source code data can be executed on the webpage to be loaded later.
[0097] In this embodiment, the step S303 above, which involves executing the Eval source code data through a script execution function to obtain the execution result, includes:
[0098] The script execution function is called to obtain the URL of the webpage to be loaded based on the tag identifier;
[0099] The Eval source code data is injected into the webpage to be loaded based on the webpage URL using a webpage injection function.
[0100] The script execution function is called to execute the Eval source code data and obtain the execution result.
[0101] The plugin's background passes the tag identifier to the script execution function `browser.scripting.executeScript`. `browser.scripting.executeScript` retrieves the URL of the webpage to be loaded based on the tag identifier, then calls the webpage injection function `injectPageScript`. Based on the webpage URL, `Eval` source code data is injected into the webpage to be loaded. Finally, the `page-script.js` script calls the `Eval` function to execute the `Eval` source code data and obtain the execution result.
[0102] In this embodiment, the script execution function browser.scripting.executeScript receives three parameters: a tag identifier, the webpage injection function injectPageScript, and the Eval source code data. The script execution function browser.scripting.executeScript uses these three parameters, along with the triggering and listening of the custom event injectPageScript, to ultimately achieve the effect of the eval function and return the execution result.
[0103] For example, assuming the Eval source code data is "var test=123", the script execution function browser.scripting.executeScript receives three parameters: the tag identifier, the webpage injection function injectPageScript, and the Eval source code data, as follows:
[0104] browser.scripting.executeScript(target:{tabId:tab.id}, / / Tab ID
[0105] func:injectPageScript, / / Web page injection function injectPageScript
[0106] args:['var test=123']) / / Eval source code data
[0107] Press F12 in your browser to open the console, select the console tab, type "test", and you will see the console output that the value of "test" is 123, indicating that the whole process was successful and the Eval function was finally implemented.
[0108] In this embodiment, the browser plugin receives three parameters—tag identifier, webpage injection function injectPageScript, and Eval source code data—through the script execution function browser.scripting.executeScript. The page-script.js script is then imported through the webpage injection function injectPageScript. The page-script.js script calls the Eval function to execute the Eval source code data, enabling the browser plugin to execute the Eval function under the latest ManifestV3 specification, thereby making the Eval function unrestricted by the specification.
[0109] In some optional implementations of this embodiment, the step of sending the webpage injection execution script to the browser plugin includes:
[0110] The web page injection execution function calls the browser's message passing function to send the web page injection execution script to the browser plugin.
[0111] The browser message passing function is a method contained in the browser plugin itself, namely the function browser.runtime.sendMessage. After the web page injection execution function runtimeInjectPageScript obtains the Eval source code data, this function internally sends the web page injection execution script to the browser plugin by calling the function browser.runtime.sendMessage, which is then processed by the plugin's background.
[0112] This embodiment utilizes the browser plugin's own functions for data transmission, which is simple and convenient, requires no additional configuration, and saves development costs.
[0113] This application can be used in a wide variety of general-purpose or special-purpose computer system environments or configurations. Examples include: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, and distributed computing environments including any of the above systems or devices. This application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc., that perform specific tasks or implement specific abstract data types. This application can also be practiced in distributed computing environments where tasks are performed by remote processing devices connected via a communication network. In distributed computing environments, program modules can reside in local and remote computer storage media, including storage devices.
[0114] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by instructing related hardware with computer-readable instructions. These computer-readable instructions can be stored in a computer-readable storage medium. When executed, the program can include the processes of the embodiments of the above methods. The aforementioned storage medium can be a non-volatile storage medium such as a magnetic disk, optical disk, or read-only memory (ROM), or random access memory (RAM).
[0115] It should be understood that although the steps in the flowcharts of the accompanying figures are shown sequentially as indicated by the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the accompanying figures may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily completed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the sub-steps or stages of other steps.
[0116] Further reference Figure 4 As a response to the above Figure 2 To implement the method shown, this application provides an embodiment of an Eval function execution device based on a browser plugin. This device embodiment is similar to... Figure 2 Corresponding to the method embodiments shown, this device can be specifically applied to various electronic devices.
[0117] like Figure 4As shown, the browser plugin-based Eval function execution device 400 described in this embodiment includes: a configuration module 401, an acquisition module 402, and an execution module 403. Wherein:
[0118] Configuration module 401 is used to obtain the web page injection script and configure the web page injection execution function in the web page injection script;
[0119] The acquisition module 402 is used to call the web page injection execution function to obtain Eval source code data, get the web page injection execution script, and send the web page injection execution script to the browser plugin;
[0120] The execution module 403 is used to introduce a web page injection execution script into the web page to be loaded through a browser plugin, and execute the Eval source code data in the web page injection execution script to obtain the execution result.
[0121] It should be emphasized that, to further ensure the privacy and security of the webpage injection execution script, the aforementioned webpage injection execution script can also be stored in a blockchain node.
[0122] Based on the aforementioned browser plugin-based Eval function execution device 400, the Eval source code data is called through the web injection execution function configured in the web injection script to obtain the web injection execution script. The browser plugin introduces and executes the web injection execution script into the web page to be loaded, which enables the browser plugin to execute the Eval function under different extension specifications, thus achieving compatibility of the Eval function.
[0123] In some optional implementations, the execution module 403 includes a first transmission submodule, a second transmission submodule, and an execution submodule, wherein:
[0124] The first transmission submodule is used to receive Eval source code data from the web page injection execution script through the browser plugin's plugin background, and call the pre-set web page injection function to pass the Eval source code data to the web page script to be loaded.
[0125] The second transmission submodule is used to transmit the Eval source code data to the browser plugin's script execution function via the web page script;
[0126] The execution submodule is used to execute the Eval source code data through the script execution function and obtain the execution result.
[0127] This embodiment uses the browser.scripting.executeScript function to link the Eval function with the browser plugin, enabling the Eval function to be executed under different versions of the extension specification, such as ManifestV2 and ManifestV3, thus achieving compatibility of the Eval function and not being limited by the specification version.
[0128] In this embodiment, the first transmission submodule includes a loading unit, a triggering unit, and a transmission unit. The loading unit is used to introduce and load the web script of the web page to be loaded through a pre-set web page injection function. The triggering unit is used to trigger the web page injection event in the web page injection function in response to the completion of the web page script loading. The transmission unit is used to transfer the Eval source code data to the web page script based on the web page injection event.
[0129] This embodiment passes the Eval source code data to the imported web page script, which can then call the Eval function to execute the Eval source code data. This overcomes the execution barriers of the Eval function under different extension specifications, achieving compatibility in executing the Eval function and avoiding complex executable configuration processes.
[0130] In some optional implementations of this embodiment, the loading unit is further configured to: obtain the path attribute corresponding to the web page script in the script tag through the web page injection function, obtain the web page script according to the path attribute, and execute the web page script through the web page injection function to load resources.
[0131] This embodiment obtains script resources through path attributes, which can improve resource acquisition efficiency.
[0132] In this embodiment, the execution module 403 further includes a tag acquisition submodule, which is used to: call the tag acquisition function of the browser plugin to obtain the tag information of the webpage to be loaded, and obtain the tag identifier from the tag information; and pass the tag identifier to the script execution function of the browser plugin through the plugin background.
[0133] This embodiment obtains the tag identifier of the webpage to be loaded by calling the tag acquisition function in the browser plugin's background, and passes it to the script execution function. This enables the location of the webpage to be loaded so that the Eval source code data can be executed on the webpage to be loaded later.
[0134] In this embodiment, the execution submodule includes an acquisition unit, an injection unit, and an execution unit, wherein:
[0135] The retrieval unit is used to call the script execution function to obtain the URL of the webpage to be loaded based on the tag identifier;
[0136] The injection unit is used to inject Eval source code data into the webpage to be loaded based on the webpage URL by using the webpage injection function.
[0137] The execution unit is used to call the script execution function to execute the Eval source code data and obtain the execution result.
[0138] This embodiment enables browser plugins to execute the Eval function under the latest ManifestV3 specification, thereby making the Eval function unrestricted by the specification.
[0139] In some optional implementations of this embodiment, the acquisition module 402 includes a transmission submodule, which is used to call the browser message passing function using the web page injection execution function to send the web page injection execution script to the browser plugin.
[0140] This embodiment utilizes the browser plugin's own functions for data transmission, which is simple and convenient, requires no additional configuration, and saves development costs.
[0141] To address the aforementioned technical problems, embodiments of this application also provide a computer device. Please refer to [link / reference needed]. Figure 5 , Figure 5 This is a basic structural block diagram of the computer device in this embodiment.
[0142] The computer device 5 includes a memory 51, a processor 52, and a network interface 53 that are interconnected via a system bus. It should be noted that only the computer device 5 with components 51-53 is shown in the figure; however, it should be understood that it is not required to implement all the shown components, and more or fewer components can be implemented alternatively. Those skilled in the art will understand that the computer device described here is a device capable of automatically performing numerical calculations and / or information processing according to pre-set or stored instructions, and its hardware includes, but is not limited to, microprocessors, application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), digital signal processors (DSPs), embedded devices, etc.
[0143] The computer device can be a desktop computer, laptop, handheld computer, or cloud server, etc. The computer device can interact with the user via a keyboard, mouse, remote control, touchpad, or voice control.
[0144] The memory 51 includes at least one type of readable storage medium, including flash memory, hard disk, multimedia card, card-type memory (e.g., SD or DX memory), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, magnetic disk, optical disk, etc. In some embodiments, the memory 51 may be an internal storage unit of the computer device 5, such as the hard disk or memory of the computer device 5. In other embodiments, the memory 51 may also be an external storage device of the computer device 5, such as a plug-in hard disk, smart media card (SMC), secure digital (SD) card, flash card, etc., equipped on the computer device 5. Of course, the memory 51 may include both the internal storage unit and its external storage device of the computer device 5. In this embodiment, the memory 51 is typically used to store the operating system and various application software installed on the computer device 5, such as computer-readable instructions for executing the Eval function based on a browser plugin. In addition, the memory 51 can also be used to temporarily store various types of data that have been output or will be output.
[0145] In some embodiments, the processor 52 may be a central processing unit (CPU), controller, microcontroller, microprocessor, or other data processing chip. The processor 52 is typically used to control the overall operation of the computer device 5. In this embodiment, the processor 52 is used to execute computer-readable instructions stored in the memory 51 or to process data, for example, to execute computer-readable instructions of the browser plugin-based Eval function execution method.
[0146] The network interface 53 may include a wireless network interface or a wired network interface, which is typically used to establish communication connections between the computer device 5 and other electronic devices.
[0147] This embodiment implements the steps of the browser plugin-based Eval function execution method described above by executing computer-readable instructions stored in memory through the processor. The Eval source code data is called by the web injection execution function configured in the web injection script to obtain the web injection execution script. The web injection execution script is introduced into the web page to be loaded by the browser plugin and executed. This allows the browser plugin to execute the Eval function under different extension specifications, thus achieving compatibility of the Eval function.
[0148] This application also provides another implementation method, namely, providing a computer-readable storage medium storing computer-readable instructions that can be executed by at least one processor to cause the at least one processor to perform the steps of the browser plugin-based Eval function execution method described above. By calling the Eval source code data through the web page injection execution function configured in the web page injection script, the web page injection execution script is obtained. The web page injection execution script is introduced into the web page to be loaded based on the browser plugin and executed. This allows the browser plugin to execute the Eval function under different extension specifications, achieving compatibility of the Eval function.
[0149] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes several instructions to cause a terminal device (which may be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in the various embodiments of this application.
[0150] Obviously, the embodiments described above are only some embodiments of this application, not all embodiments. The accompanying drawings show preferred embodiments of this application, but do not limit the patent scope of this application. This application can be implemented in many different forms; rather, the purpose of providing these embodiments is to provide a more thorough and comprehensive understanding of the disclosure of this application. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art can still modify the technical solutions described in the foregoing specific embodiments, or make equivalent substitutions for some of the technical features. Any equivalent structures made using the content of this application's specification and drawings, directly or indirectly applied to other related technical fields, are similarly within the scope of patent protection of this application.
Claims
1. A method for executing the Eval function based on a browser plugin, characterized in that, Includes the following steps: Obtain the web page injection script and configure the web page injection execution function in the web page injection script; The web page injection execution function is called to obtain Eval source code data, thus obtaining the web page injection execution script. The web page injection execution script is then sent to the browser plugin. The Eval source code data is the code content executed by the Eval function, and the Eval source code data is passed as a string to the parameter value corresponding to the source code call parameter. The browser plugin introduces the webpage injection execution script into the webpage to be loaded, and executes the Eval source code data in the webpage injection execution script to obtain the execution result. Specifically, this includes: receiving the Eval source code data in the webpage injection execution script through the browser plugin's plugin backend, and calling a pre-set webpage injection function to pass the Eval source code data to the webpage script of the webpage to be loaded; transmitting the Eval source code data to the script execution function of the browser plugin through the webpage script; and executing the Eval source code data through the script execution function to obtain the execution result.
2. The method for executing the Eval function based on a browser plugin according to claim 1, characterized in that, The step of calling a pre-set webpage injection function to pass the Eval source code data to the webpage to be loaded includes: The web page script of the web page to be loaded is introduced and loaded through a pre-set web page injection function; In response to the completion of the loading of the web page script, the web page injection event in the web page injection function is triggered; Based on the webpage injection event, the Eval source code data is passed to the webpage script.
3. The method for executing the Eval function based on a browser plugin according to claim 2, characterized in that, The step of introducing and loading the webpage script of the webpage to be loaded through a pre-set webpage injection function includes: The path attribute corresponding to the web page script is obtained from the script tag through the web page injection function, and the web page script is obtained according to the path attribute. The webpage script is executed through the webpage injection function to load resources.
4. The method for executing the Eval function based on a browser plugin according to claim 1, characterized in that, Before the step of executing the Eval source code data through the script execution function and obtaining the execution result, the method further includes: Call the tag retrieval function of the browser plugin to obtain the tag information of the webpage to be loaded, and obtain the tag identifier from the tag information; The plugin backend passes the tag identifier to the browser plugin's script execution function.
5. The method for executing the Eval function based on a browser plugin according to claim 4, characterized in that, The step of executing the Eval source code data through the script execution function to obtain the execution result includes: The script execution function is invoked to obtain the URL of the webpage to be loaded based on the tag identifier; The Eval source code data is injected into the webpage to be loaded based on the webpage URL using the webpage injection function. The script execution function is called to execute the Eval source code data and obtain the execution result.
6. The method for executing the Eval function based on a browser plugin according to any one of claims 1 to 5, characterized in that, The step of injecting the webpage into the execution script and transmitting it to the browser plugin includes: The webpage injection execution function is used to call the browser message passing function to send the webpage injection execution script to the browser plugin.
7. A browser plugin-based Eval function execution device, characterized in that, include: The configuration module is used to obtain the web page injection script and configure the web page injection execution function in the web page injection script; The acquisition module is used to call the web page injection execution function to obtain Eval source code data, obtain the web page injection execution script, and send the web page injection execution script to the browser plugin. The Eval source code data is the code content executed by the Eval function, and the Eval source code data is passed as a string to the parameter value corresponding to the source code call parameter. The execution module is used to introduce the webpage injection execution script into the webpage to be loaded through the browser plugin, and execute the Eval source code data in the webpage injection execution script to obtain the execution result. Specifically, it includes: receiving the Eval source code data in the webpage injection execution script through the plugin background of the browser plugin, and calling a pre-set webpage injection function to pass the Eval source code data to the webpage script of the webpage to be loaded; passing the Eval source code data to the script execution function of the browser plugin through the webpage script; and executing the Eval source code data through the script execution function to obtain the execution result.
8. A computer device comprising a memory and a processor, the memory storing computer-readable instructions, wherein the processor, when executing the computer-readable instructions, implements the steps of the browser plugin-based Eval function execution method as described in any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-readable instructions, which, when executed by a processor, implement the steps of the browser plugin-based Eval function execution method as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Method for interaction between flash plug-in of client and webpage script of server IE (internet explorer)
CN103544067A
Method for de-obfuscating JavaScript code in web page
CN108694042A