Method and device for directly calling method by JavaScript program in browser extension, equipment and storage medium

CN122963832APending Publication Date: 2026-10-23BEIJING DARK SIDE OF THE MOON TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611128020.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-07-28
Publication Date
2026-10-23

AI Technical Summary

Technical Problem

[0004]但是这种方式存在一定的不足:该类脚本工具的脚本触发逻辑与调度机制高度绑定网页页面,仅能依托页面匹配规则、人工点击两种固定方式启动脚本,缺少独立于页面、可被外部程序主动发起调用的标准化请求通道;同时脚本运行后的输出结果仅在当前网页内展示,不存在统一标准化的数据输出规范,外部智能代理、调度程序无法统一读取脚本执行结果,外部自动化调度场景适配性较差

Benefits of technology

[0011]本发明实施例的技术方案,摒弃现有技术依赖页面URL匹配、人工右键点击的脚本触发模式,外部调用方无需依托目标网页即可主动下发命令指令,通过命令名定向调取指定JS程序模块执行,摆脱脚本运行与网页页面强绑定的限制,适配AI智能代理、调度任务、外部程序自动化发起请求的场景;可从命令指示符中解析提取执行参数并传入JS程序模块驱动业务运行,同时统一输出包含执行状态、业务数据的结构化数据对象并回传给调用方,解决现有脚本仅页面内展示结果、无法被外部程序程序化解析复用的问题,打通外部自动化调度的数据交互链路;将JS源码加载至浏览器扩展专属执行环境运行,而在执行环境独立于目标网页原生JS全局上下文的情况下,这种运行方式可以避免脚本与页面自有代码变量冲突、权限互相干扰,保障批量网页数据采集、自动化操作过程稳定安全;仅依靠纯字符串拆分逻辑完成命令名与参数解析,无需调用大模型进行语义推理、工具路由,消除大模型推理带来的响应延迟、结果不稳定问题,提升脚本调用响应速度与执行确定性。另外,本发明技术方案无需宿主程序与守护进程:JavaScript程序模块的存储与执行均在浏览器扩展内完成,无需在用户操作系统中安装独立的可执行程序或守护进程,天然跨操作系统。本发明技术方案同时具备跨调用方一致性:同一JS程序模块在不同调用方(人工输入、不同AI智能代理、不同外部程序)触发下执行结果一致,不受调用方推理能力差异的影响。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122963832A_ABST
    Figure CN122963832A_ABST
Patent Text Reader

Abstract

The application discloses a method and device for directly calling a JavaScript program in a browser extension, an apparatus and a storage medium. The method comprises the following steps: receiving a command indicator string carrying a special identification prefix transmitted by an external calling party, extracting a target command name and corresponding execution parameters by analyzing the string through string splitting logic; taking the target command name as a search identifier, matching a corresponding JS program module in a local persistent storage space of the browser extension, and reading the stored program execution source code; loading the program execution source code into an execution environment provided by the browser extension; transmitting the execution parameters into the program entry of the JS program module to drive the running of the JS program module, and calling the native capabilities exposed by the browser extension to complete data interaction with a target webpage and / or a website interface during the running; and after the execution of the JS program module is completed, generating a structured data object containing at least an execution state identifier and business data, and returning the structured data object to the external calling party.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer technology, and in particular to a method, apparatus, electronic device, and storage medium for direct invocation of JavaScript programs within a browser extension. Background Technology

[0002] With the rapid development of browser extensions, web page automation, and AI intelligent agent technologies, many scenarios require the use of browser environments to automatically collect web page data and perform page operations in batches. The industry generally uses JavaScript (JS) scripts to implement web page interaction logic, which has led to the development of various browser script execution tools.

[0003] Current mainstream technical solutions mainly use user script managers such as Tampermonkey, Greasemonkey, and Violetmonkey, which automatically inject JS scripts based on page URL matching rules or are manually triggered by users through the browser's right-click menu.

[0004] However, this approach has certain shortcomings: the script triggering logic and scheduling mechanism of this type of script tool are highly bound to the web page, and the script can only be started in two fixed ways: relying on page matching rules and manual clicks. It lacks a standardized request channel that is independent of the page and can be actively initiated and called by external programs. At the same time, the output results after the script runs are only displayed within the current web page, and there is no unified standardized data output specification. External intelligent agents and schedulers cannot uniformly read the script execution results, and the adaptability to external automated scheduling scenarios is poor. Summary of the Invention

[0005] This invention provides a method, apparatus, electronic device, storage medium, and computer program product for direct invocation of JavaScript programs within a browser extension.

[0006] According to one aspect of the present invention, a method for directly invoking JavaScript programs within a browser extension is provided, applied to a browser extension, the method comprising: Receive command indicator strings with unique identification prefixes transmitted by external callers, and extract the target command name and corresponding execution parameters through string splitting logic; Using the parsed target command name as the search identifier, the corresponding JavaScript program module (JS program module) is matched in the browser's extended local persistent storage space, and the program execution source code stored in the JS program module is read. Load the program's source code into the execution environment provided by the browser extension; The execution parameters are passed to the program entry point of the JS program module to drive the JS program module to run. During the running process, the native capabilities opened by the browser extension are called to complete data interaction with the target webpage and / or target site interface. After the JS program module finishes execution, a structured data object containing at least execution status identifiers and business data is generated, and the structured data object is sent back to the external caller.

[0007] According to another aspect of the present invention, a device for directly invoking JavaScript programs within a browser extension is provided, configured in a browser extension, comprising: The instruction receiving and parsing module is used to receive command indicator strings carrying a unique identification prefix transmitted by external callers, and extract the target command name and corresponding execution parameters through string splitting logic. The retrieval module is used to match the corresponding JS program module in the browser's extended local persistent storage space by using the parsed target command name as the retrieval identifier, and read the program execution source code stored in the JS program module. Loading modules are used to load the program's source code into the execution environment provided by the browser extension; The execution module is used to pass execution parameters to the program entry point of the JS program module, drive the JS program module to run, and call the native capabilities opened by the browser extension to complete data interaction with the target webpage and / or target site interface during the running process; The results generation and feedback module is used to generate a structured data object containing at least execution status identifiers and business data after the JS program module has been executed, and to send the structured data object back to the external caller.

[0008] According to another aspect of the present invention, an electronic device is provided, the electronic device comprising: At least one processor; and A memory that is communicatively connected to at least one processor; wherein, The memory stores a computer program that can be executed by at least one processor, such that the at least one processor is able to execute the browser extension JavaScript program direct invocation method of the present invention.

[0009] According to another aspect of the present invention, a computer-readable storage medium is provided, which stores computer instructions for causing a processor to execute the direct JavaScript program invocation method within a browser extension according to embodiments of the present invention.

[0010] According to another aspect of the present invention, a computer program product is provided, comprising a computer program that, when executed by a processor, implements the steps in the above-described method.

[0011] The technical solution of this invention abandons the script triggering mode of existing technologies that rely on page URL matching and manual right-clicking. External callers can actively issue commands without relying on the target webpage, and execute specified JS program modules by calling the command name. This breaks away from the limitation of strong binding between script execution and webpage pages, and is suitable for scenarios such as AI intelligent agents, scheduling tasks, and external programs automatically initiating requests. Execution parameters can be parsed and extracted from the command indicator and passed to the JS program module to drive business operation. At the same time, a structured data object containing execution status and business data is uniformly output and sent back to the caller. This solves the problem that existing scripts only display results within the page and cannot be parsed and reused by external programs, and opens up the data interaction link for external automated scheduling. The JS source code is loaded into the browser extension's dedicated execution environment. Since the execution environment is independent of the target webpage's native JS global context, this running method can avoid conflicts between script and page's own code variables and mutual interference of permissions, ensuring the stability and security of batch webpage data collection and automated operation processes. Command name and parameter parsing is completed only by pure string splitting logic, without calling large models for semantic reasoning and tool routing. This eliminates the response delay and result instability problems caused by large model reasoning, and improves the script call response speed and execution determinism. Furthermore, the technical solution of this invention requires no host program or daemon process: the storage and execution of the JavaScript program module are completed within the browser extension, eliminating the need to install a separate executable program or daemon process in the user's operating system, thus naturally being cross-operating system compatible. The technical solution of this invention also possesses cross-caller consistency: the same JS program module executes consistently under different callers (human input, different AI intelligent agents, different external programs), unaffected by differences in the caller's reasoning ability.

[0012] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of the present invention, nor is it intended to limit the scope of the invention. Other features of the invention will become readily apparent from the following description. Attached Figure Description

[0013] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0014] Figure 1This is a flowchart illustrating the direct method call between JavaScript programs within a browser extension, as provided in an embodiment of the present invention. Figure 2a This is a flowchart illustrating another method for direct JavaScript program call within a browser extension, provided in an embodiment of the present invention. Figure 2b This is a schematic diagram of the browser's extended local persistent storage space provided in an embodiment of the present invention; Figure 3 This is a schematic diagram of the structure of the device for directly calling JavaScript programs within a browser extension provided in an embodiment of the present invention; Figure 4 This is a schematic diagram of the structure of an electronic device that implements direct method invocation by JavaScript programs within a browser extension, as described in this embodiment of the invention. Detailed Implementation

[0015] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.

[0016] Example 1 Figure 1 This is a flowchart illustrating a method for directly invoking JavaScript within a browser extension, as provided in this embodiment of the invention. This embodiment is applicable to scenarios where external entities such as AI intelligent agents, external applications, and scheduled tasks need to bypass webpage limitations and use parameterized instructions to directly invoke browser JS program modules to automate webpage data collection and page operations, and to programmatically and uniformly read the program execution results. This method can be executed by a device for directly invoking JavaScript within a browser extension. This device can be implemented in hardware and / or software and can be configured in an electronic device. The browser extension involved in this invention is a lightweight third-party program independent of the browser itself, installable and uninstallable on demand, and possessing browser-specific high-privilege interfaces. It runs within a browser's built-in dedicated sandbox runtime system, enabling it to overcome the permission restrictions of ordinary webpage JavaScript and serving as the execution carrier for the overall technical solution of this invention.

[0017] like Figure 1 As shown, the direct method call by a JavaScript program within a browser extension includes steps S101-S105: S101: Receive the command indicator string carrying a unique identification prefix transmitted by the external caller, and extract the target command name and corresponding execution parameters through string splitting logic; S102. Using the parsed target command name as the search identifier, match the corresponding JS program module in the browser's extended local persistent storage space, and read the program execution source code stored in the JS program module. S103. Load the program's source code into the execution environment provided by the browser extension; S104. Pass the execution parameters to the program entry point of the JS program module to drive the JS program module to run, and call the native capabilities opened by the browser extension to complete data interaction with the target webpage and / or target site interface during the running process. S105. After the JS program module is executed, generate a structured data object that contains at least execution status identifiers and business data, and send the structured data object back to the external caller.

[0018] In step S101, the external caller refers to a request initiating entity independent of the browser extension, including any one of the following: human user, AI intelligent agent, third-party application, or scheduled automated task, distinct from the browser extension's internal triggering logic. The exclusive identification prefix is ​​a pre-agreed, fixed character marker used to uniquely identify a legitimate call instruction, distinguishing it from ordinary text, native webpage messages, and the invention's exclusive command indicator to avoid accidental triggering. For example, the exclusive identification prefix can be any of the following characters: / , @, #, !. The command indicator string is a complete text instruction formed by concatenating the exclusive identification prefix, the target command name, and execution parameters; it is the unique data carrier for the external caller to initiate the script call. The string splitting logic is a pure text processing logic based on text character matching, cutting, splitting, and parameter parsing, without relying on semantic understanding or large model inference. The target command name is an identifier uniquely bound to the JS program module, used for subsequent accurate retrieval and location of the corresponding script module. Execution parameters are the business input parameters required for this script execution, used to control the specific execution logic, operation objects, and execution scope of the JS program module.

[0019] In some embodiments, step S101 is specifically implemented as follows: the browser extension continuously listens to the request channel of the external caller, waiting for the caller to send a command indicator string; upon receiving the command indicator string, it identifies a fixed unique identification prefix at the front end of the command indicator string to confirm that the command indicator string is a valid call instruction; using the unique identification prefix as the starting point, it splits the command indicator string into strings to separate the target command name and multiple parameter strings; it parses the split parameter strings according to at least one of positional parameters, option parameters, and key-value pair parameters, converting them into structured execution parameters for passing into the JS program module. This process does not rely on an intelligent inference model throughout, but only completes the instruction parsing through the program's inherent text logic.

[0020] In other embodiments, the implementation process of step S101 may also include: the browser extension provides an external communication interface, the external caller actively pushes a command indicator string with a prefix through the interface, the browser extension first performs a validation check of the command indicator string, and then accurately extracts the command name and multiple sets of execution parameters through regular expression character matching, and automatically completes parameter formatting and empty parameter error handling.

[0021] In other embodiments, for batch scheduling scenarios, multiple consecutive command indicator strings are received, prefixes are identified and parsed line by line, and multiple sets of command names and corresponding execution parameters are extracted in batches to form a batch call instruction queue.

[0022] The benefits of this step are as follows: it completely eliminates the limitations of existing script tools that rely on page URL matching and manual click triggering, enabling proactive command invocation from external programs, AI agents, and scheduled tasks; it prevents accidental triggering and conflicts by using dedicated prefix verification; and it replaces large-model semantic reasoning with pure string parsing, significantly reducing invocation latency, improving the stability and determinism of command parsing, and providing a data foundation for subsequent accurate matching of JS program modules and parameterized controllable execution.

[0023] In step S102, the retrieval identifier refers to using the parsed target command name as a unique retrieval index to accurately locate the target script module. The local persistent storage space is a local storage medium within the browser extension itself that can store data for a long time. Data is not lost after power failure or browser restart, and it is used to persistently store various custom JS program modules. A JS program module is an executable code unit pre-stored locally by the browser extension, bound to a unique command name, and possessing independent and complete business logic. It can be dynamically added after the extension is installed without needing to redeploy the extension. The program execution source code is a text-based executable source code string stored within the JS program module; it is the actual code body that executes the business interaction logic.

[0024] In some embodiments, step S102 is specifically implemented by: using the parsed target command name as a retrieval identifier to initiate a local storage query request; matching the corresponding JS program module by at least one of the following methods: traversing each JS program module already stored in the local persistent storage space, comparing the command name bound to each JS program module one by one, and matching the JS program module that is completely consistent with the retrieval identifier; or, pre-storing each JS program module in a key-value mapping structure with the command name as the key and the JS program module as the value, and directly querying and locating the corresponding JavaScript program module with the target command name as the key; verifying the integrity of the matched JS program module and confirming that there is program execution source code in the JS program module; reading the program execution source code stored inside the JS program module and caching it in the extended running memory to wait for loading.

[0025] In this embodiment, a standardized exception flag is automatically returned when the matching fails. After a successful match, the integrity and legality of the source code are verified, and incomplete or illegal source code is filtered out to ensure that subsequent loading and execution are safe and reliable.

[0026] The beneficial effects of step S102 are as follows: it overcomes the shortcomings of traditional script tools that can only pre-package fixed code and rely on page-bound scripts, supports dynamic expansion after installation and persistent storage of multiple sets of JS program modules; it achieves the ability to call the corresponding script on demand through accurate search and matching of command names, supports the coexistence of multiple scripts without interference, and greatly improves the flexibility and scalability of browser script automatic scheduling.

[0027] In step S103, loading refers to importing the source code string in text form into a preset runtime environment, completing compilation, parsing, and initialization to make it runnable. The execution environment is a runtime context provided by the browser extension that can load and execute the source code string; in some embodiments, this execution environment is independent of the target webpage's native JavaScript context and isolated from the page's global scope. Therefore, step S103 mainly involves importing the read executable source code into a dedicated runtime carrier provided by the browser extension, making the source code runnable.

[0028] In some embodiments, the execution environment is provided by a browser extension, and the methods for loading the program execution source code into this environment include, but are not limited to, at least one of the following: Call the extended script injection API, pass the cached program execution source code to the API input parameters, and the API will load the program execution source code into an independent execution domain of the page that is isolated from the native JS global object of the target webpage; The program execution source code is read in the browser extension background service context, and the program execution source code is encapsulated into an executable function through a dynamic compilation mechanism and loaded. It is isolated from the page context and runs in an independent background execution context. Create an independent Web Worker sub-thread, and load the program's source code through the independent Web Worker sub-thread; Extend the creation of a blank sandbox iframe container, load the program's source code into the sandbox iframe to run, and complete data interaction through cross-container message channels to achieve a natural sandbox isolation effect; Call the user script management interface provided by the browser extension platform (such as the chrome.userScripts API of the Chrome extension platform) to dynamically register the program's source code or execute it directly in the script execution environment corresponding to the target page.

[0029] The beneficial effects of step S103 are: it completely solves the problems of traditional user scripts and native page code running together globally, variable conflicts, being tampered with by page scripts, and unstable operation; by running scripts in the execution environment, it avoids malicious web page code interfering with automation logic, and at the same time avoids automation scripts polluting the native business logic of the page, thus greatly improving the security, stability and compatibility of web page automation operations.

[0030] In step S104, the program entry point is the pre-defined unified input parameter call entry point of the JS program module, used to receive external execution parameters and start the module's business logic. The driver runs the module's complete business code logic based on the input custom parameters, relying on the execution environment. Extended native capabilities include browser-authorized proprietary interface capabilities, such as DOM manipulation, network requests, and tab control. The target webpage is the third-party business webpage currently displayed by the browser, serving as the interaction object for script data collection and automated operations.

[0031] In some embodiments, step S104 is specifically implemented by: encapsulating the execution parameters into a parameter object and passing the parameter object to the program entry function of the JS program module loaded into the execution environment; the execution environment starts the module code to drive the JS program module to execute business logic based on the passed parameters; during the operation of the JS program module, the native capabilities exposed by the browser extension are called to interact with the target webpage and / or site interface; wherein, the native capabilities include at least one of DOM page manipulation capabilities, network request capabilities, and browser tab control capabilities; the interaction process includes at least one of reading / modifying page DOM elements, submitting webpage forms, requesting site backend interfaces, and switching browser tabs.

[0032] The beneficial effects of step S104 are: to enable parameterized, controllable, and on-demand execution of scripts, which is different from the shortcomings of traditional scripts with fixed logic, fixed processes, and inability to dynamically adapt to business scenarios; and to break through the JS permission restrictions of ordinary web pages by relying on extended native high-privilege interfaces, so as to achieve more comprehensive and stable automated web page operations and adapt to diverse web page collection and manipulation scenarios.

[0033] In step S105, the execution status identifier is a standardized status field used to indicate whether the program module has succeeded or failed, facilitating quick identification of the execution result by external programs. Business data includes web page data, interface data, and operation result data collected, generated, and processed during the execution of the JS program module. Structured data objects are standardized data carriers with fixed fields, standardized formats, and the ability to be automatically parsed by machines.

[0034] In some embodiments, step S105 is specifically implemented as follows: after all business logic of the JS program module has been executed, the business data and execution status identifier generated during the execution process are captured; the browser extension assembles a structured data object based on the captured business data and execution status identifier; the structured data object is serialized into a preset transmission format (such as JSON format, Protobuf serialization format, or extended custom structured data format), and the serialized structured data object is sent back to the external caller that initiated the request along the original request link.

[0035] In some embodiments, after the JS program module finishes execution, it adds the capture of exception error information and assembles it into complete structured data containing execution status, business data, and error information, so as to achieve unified and standardized output of success results and exception results.

[0036] Step S105 can solve the core defects of existing user scripts, which only display results on the page, have no standardized output, and cannot be automatically read by external programs. Through a structured and unified feedback mechanism, it can realize the data connection between browser scripts, AI agents, automated scheduling systems, and third-party applications, support multi-level automated chain calls, and greatly expand the automated application scenarios of browser scripts.

[0037] Based on the technical solution of steps S101-S105 of this invention, the existing script triggering mode that relies on page URL matching and manual right-clicking is abandoned. External callers can actively issue commands without relying on the target webpage, and can directly call the specified JS program module for execution through the command name. This breaks free from the limitation of strong binding between script execution and webpage pages, and is suitable for scenarios such as AI intelligent agents, task scheduling, and automated request initiation by external programs. Execution parameters can be parsed and extracted from the command indicator and passed to the JS program module to drive business operation. Simultaneously, a structured data object containing execution status and business data is uniformly output and returned to the caller, solving the problem that existing scripts only display results within the page and cannot... This addresses the issue of external programs reusing and parsing code, establishing a data interaction link for external automated scheduling. By loading the JS source code into a browser extension's dedicated execution environment, which is independent of the target webpage's native JavaScript global context, this approach avoids conflicts between script and page-specific code variables and permission interference, ensuring the stability and security of batch webpage data collection and automated operations. Furthermore, it relies solely on pure string splitting logic to parse command names and parameters, eliminating the need for large models for semantic reasoning and tool routing. This removes the response latency and instability issues caused by large model inference, improving script call response speed and execution determinism.

[0038] Example 2 Figure 2a This invention provides a flowchart illustrating how a JavaScript program can directly call a method within a browser extension. See also... Figure 2a The method includes the following steps: S201. After the browser extension is installed, receive the JS program module generated by external import, and persistently write the JS program module to the local persistent storage space to form a JS program module collection that can be dynamically expanded.

[0039] The JS program module contains a uniquely bound command name and the program execution source code; the local persistent storage space includes at least one of the following: extended local storage interface (e.g., chrome.storage.local), IndexedDB, extended built-in local database, and cloud synchronous storage; the source of the JS program module includes at least one of the following: AI intelligent agent automatic generation, user browser operation recording and translation generation, developer manual writing, and import of third-party resources.

[0040] For example, see Figure 2b It illustrates a diagram of the browser's extended local persistent storage space. The local persistent storage space is split into two independent partitions. The generated JS program module will be written to both of these partitions simultaneously and permanently saved. Specifically: Partition 1: List of Dynamic Modules A linear list structure can be used, with each new module being appended directly to the end of the list; its function is to completely retain all imported JS program modules, support unlimited dynamic expansion, and continuously add programs without repackaging after the extension is installed, covering batch addition and batch import scenarios.

[0041] Partition 2: Command Name Index Mapping Table It adopts a key-value pair structure, using the unique command name of the current JS program module as the key and the complete JS program module entity as the value stored in the mapping table; its purpose is to establish a one-to-one correspondence index between command names and modules, providing underlying data support for fast retrieval.

[0042] Once storage is complete, the local storage contains two sets of data: a complete list of all modules (for traversing and matching scenarios one by one); and a command-name-specific index (for quickly locating scenarios by directly looking up the table). The two storage structures coexist in parallel without conflict. Based on this, when performing a search in step S203, the matching JS program can be retrieved by traversing one by one, or the matching JS program module can be quickly located by directly looking up the table.

[0043] S202: Receive the command instruction string carrying a unique identification prefix transmitted by the external caller, and extract the target command name and corresponding execution parameters through string splitting logic.

[0044] S203. Using the parsed target command name as the search identifier, match the corresponding JS program module in the browser's extended local persistent storage space, and read the program execution source code stored in the JS program module.

[0045] S204. Load the program's source code into the execution environment provided by the browser extension.

[0046] S205. Pass the execution parameters to the program entry point of the JS program module to drive the JS program module to run, and call the native capabilities opened by the browser extension to complete data interaction with the target webpage and / or site interface during the running process.

[0047] S206. After the JS program module is executed, generate a structured data object that contains at least an execution status identifier and business data, and send the structured data object back to the external caller.

[0048] The specific implementation of steps S202-S206 can be found in the description of the above embodiments, and will not be repeated here.

[0049] In this embodiment, the limitation of traditional extensions that can only package built-in fixed scripts is broken. After the extension is installed and running, custom JS program modules can be added at any time without repackaging, uploading and updating the extension, which greatly reduces the cost of adding and iterating scripts. It supports automatic generation and batch import of scripts from multiple sources, adapting to diverse automation scenarios such as manual writing, operation recording, and AI automatic generation, expanding the script supply channels. Multiple types of persistent storage media are available, taking into account both local offline use and cloud synchronization across multiple devices, providing flexible storage and stable data retention. Each module is bound to a unique command name, realizing the isolation and differentiation between modules, and providing underlying data support for subsequent targeted and precise invocation of specified script modules through command indicators.

[0050] To facilitate understanding of the technical solution of this invention, a complete and practical end-to-end call process example is provided, covering the entire chain from storage, triggering, execution, to result return. A specific example is as follows: 1. Storage phase, the specific implementation method is as follows: The browser extension receives externally passed JavaScript modules. The module data format is {"command":"content-search","source":"async function main(params) { …}"}; where the command field is the unique command name "content-search" bound to the JavaScript module, and the source field is the complete executable source code. The browser extension persistently stores this JavaScript module in the chrome.storage.local local storage using the command name as the key, forming a dynamically expandable collection of script modules.

[0051] 2. Triggering phase, the specific implementation method is as follows: The external caller (AI intelligent agent) issues a command instruction string with a unique prefix " / ": / content-search keyword=camping equipment limit=10. The browser extension recognizes the prefix " / " and determines it as a valid command; it splits the string using the prefix as the starting point, extracts the target command name "content-search", and parses the remaining parameter strings using key-value pairs, converting them into structured execution parameters {keyword:"camping equipment",limit:10}. The entire process involves no large-scale semantic reasoning model; parsing is completed solely through text splitting logic.

[0052] 3. Execution phase, the specific implementation method is as follows: Using content-search as the retrieval identifier, the corresponding JS program module is read from the local persistent storage, the cached program execution source code is read and loaded into the execution environment provided by the extension, and the structured execution parameters are passed to the module's unified entry function main(params) to start running.

[0053] During the execution of the JS program module, the native network request capabilities of the extended open platform are invoked to initiate network requests to the search site interface of a content sharing platform; it can also invoke DOM manipulation capabilities according to the parameter configuration to read the DOM elements of the current page's search results list and complete the data collection interaction.

[0054] 4. The result return stage is implemented as follows: Successful execution returns {"ok": true, "data": [{"title": "...", "url": "..."},...]}; failure returns {"ok": false, "error": {"code": "...", "message": "..."}}.

[0055] Example 3 Figure 3 This is a schematic diagram of a device for directly invoking JavaScript programs within a browser extension, provided as an embodiment of the present invention. This device can execute any of the methods for directly invoking JavaScript programs within a browser extension according to the present invention. Figure 3 As shown, the devices for direct JavaScript calls within a browser extension include: The instruction receiving and parsing module 301 is used to receive the command indicator string carrying a unique identification prefix transmitted by the external caller, and extract the target command name and corresponding execution parameters through string splitting logic parsing; The retrieval module 302 is used to match the corresponding JS program module in the browser's extended local persistent storage space with the parsed target command name as the retrieval identifier, and read the program execution source code stored in the JS program module. Load module 303, used to load the program's source code into the execution environment provided by the browser extension; Execution module 304 is used to pass execution parameters to the program entry point of the JS program module, drive the JS program module to run, and call the native capabilities exposed by the browser extension to complete data interaction with the target web page and / or site interface during the running process; The result generation and feedback module 305 is used to generate a structured data object containing at least execution status identifiers and business data after the JS program module has been executed, and to send the structured data object back to the external caller.

[0056] In some embodiments, the browser extension-based JS program direct invocation device further includes: The storage module is used to receive externally imported JS program modules after the browser extension is installed, and persistently write the JS program modules to the local persistent storage space to form a collection of JS program modules that can be dynamically expanded. The JS program module contains a uniquely bound command name and the program's execution source code; Local persistent storage space includes at least one of the following: extended local storage interface, IndexedDB, extended built-in local database, and cloud synchronous storage; The sources of JS program modules include at least one of the following: AI intelligent agent automatic generation, user browser operation recording and translation generation, manual writing by developers, and import of third-party resources.

[0057] In some embodiments, in matching the corresponding JS program module in the browser's extended local persistent storage space using the parsed target command name as the search identifier, and reading the program execution source code stored in the JS program module, the search module 302 is specifically used for: Using the parsed target command name as the search identifier, the corresponding JS program module is matched using at least one of the following methods: Iterate through all the JS program modules stored in the local persistent storage space, compare the command names bound to each JS program module one by one, and match the JS program modules that match the search identifier; or, A key-value mapping structure with command name as key and JS program module as value is used to pre-store each JS program module, and the corresponding JS program module is directly queried and located using the target command name as key; Verify the integrity of the matched JS program modules and confirm that the JS program modules contain executable source code; Read the program execution source code stored inside the JS program module, cache it in the extended runtime memory, and wait for it to be loaded.

[0058] In some embodiments, in receiving a command indicator string carrying a unique identification prefix transmitted by an external caller, and extracting the target command name and corresponding execution parameters through string splitting logic, the instruction receiving and parsing module 301 is specifically used for: The browser extension continuously listens to the request channel of the external caller, waiting for the caller to send a command instruction string; Upon receiving the command instruction string, the system identifies the fixed, unique prefix at the beginning of the command instruction string to confirm that the command instruction string is a valid call command. Starting from the unique identification prefix, the command instruction string is split and segmented to separate the target command name and multiple parameter strings. The parameter strings obtained from the splitting are parsed in at least one of the following ways: positional parameters, option parameters, and key-value pair parameters, and converted into structured execution parameters for passing into JS program modules.

[0059] In some embodiments, the execution environment is provided by a browser extension, and the implementation of loading the program execution source code into this environment includes at least one of the following methods: Call the extended script injection API to load the program's source code into an independent execution domain that is isolated from the target webpage's native JS global object; The program execution source code is read in the browser extension background service context, and the program execution source code is encapsulated into an executable function through a dynamic compilation mechanism and loaded. It is isolated from the page context and runs in an independent background execution context. The program executes its source code via a separate sub-thread of a Web Worker. The source code is loaded based on a sandbox iframe and a cross-context message channel. The program's source code is dynamically registered or directly executed in the script execution environment corresponding to the target page by calling the user script management interface provided by the browser extension platform.

[0060] In some embodiments, the execution module 304 is specifically used to: pass execution parameters to the program entry point of the JS program module to drive the JS program module to run, and in the process of running, call the native capabilities exposed by the browser extension to complete data interaction with the target webpage and / or target site interface. The execution parameters are uniformly encapsulated into an input parameter object, and the input parameter object is passed to the program entry function of the JS program module that has been loaded into the execution environment; The execution environment startup module code drives the JS program module to execute business logic based on the passed parameters; During the execution of the JS program module, the native capabilities exposed by the browser extension are invoked to interact with the target webpage and / or the target site's interface; the native capabilities include at least one of DOM page manipulation capabilities, network request capabilities, and browser tab control capabilities; the interaction process includes at least one of reading / modifying page DOM elements, submitting webpage forms, requesting site backend interfaces, and switching browser tabs.

[0061] In some embodiments, after the JS program module completes execution, a structured data object containing at least execution status identifiers and business data is generated, and the structured data object is returned to the external caller. The result generation and feedback module 305 is specifically used for: Once all business logic of the JS program module has been executed, capture the business data and execution status indicators generated during the execution process. The browser extension assembles structured data objects based on captured business data and execution status identifiers; The structured data object is serialized into a preset transmission format and then sent back to the external caller that initiated the request along the original request path.

[0062] The browser extension JavaScript direct calling device provided in the embodiments of the present invention can execute the browser extension JavaScript direct calling method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.

[0063] According to embodiments of the present invention, the present invention also provides an electronic device, a readable storage medium, and a computer program product.

[0064] Example 4 Figure 4 A schematic diagram of the structure of an electronic device 10 that can be used to implement embodiments of the present invention is shown. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the invention described and / or claimed herein.

[0065] like Figure 4 As shown, the electronic device 10 includes at least one processor 11 and a memory, such as a read-only memory 12 or a random access memory 13, communicatively connected to the at least one processor 11. The memory stores computer programs executable by the at least one processor. The processor 11 can perform various appropriate actions and processes based on the computer program stored in the read-only memory 12 or loaded from storage unit 18 into the random access memory 13. The random access memory 13 may also store various programs and data required for the operation of the electronic device 10. The processor 11, read-only memory 12, and random access memory 13 are interconnected via a bus 14. An input / output interface 15 is also connected to the bus 14.

[0066] Multiple components in electronic device 10 are connected to input / output interface 15, including: input unit 16; output unit 17, such as various types of displays, speakers, etc.; storage unit 18, such as disks, optical disks, etc.; and communication unit 19, such as network interface cards, modems, wireless transceivers, etc. Communication unit 19 allows electronic device 10 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.

[0067] Processor 11 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of processor 11 include, but are not limited to, central processing units, graphics processing units, various special-purpose artificial intelligence computing chips, various processors running machine learning model algorithms, digital signal processors, and any suitable processor, controller, microcontroller, etc. Processor 11 performs the various methods and processes described above, such as executing methods directly called by JavaScript programs within a browser extension.

[0068] In some embodiments, the in-browser extension JavaScript direct invocation method may be implemented as a computer program tangibly contained in a computer-readable storage medium, such as storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on electronic device 10 via read-only memory 12 and / or communication unit 19. When the computer program is loaded into random access memory 13 and executed by processor 11, one or more steps of the in-browser extension JavaScript direct invocation method described above may be performed. Alternatively, in other embodiments, processor 11 may be configured to execute the in-browser extension JavaScript direct invocation method by any other suitable means (e.g., by means of firmware).

[0069] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays, application-specific integrated circuits (ASICs), application-specific standard products (ASICs), systems-on-a-chip (SoCs), complex programmable logic devices, computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.

[0070] Computer programs used to implement the methods of the present invention can be written in any combination of one or more programming languages. These computer programs can be provided to the processor of a general-purpose computer, a special-purpose computer, or other programmable browser extension JavaScript program direct calling device, such that when executed by the processor, the computer programs cause the functions / operations specified in the flowcharts and / or block diagrams to be implemented. The computer programs can be executed entirely on the machine, partially on the machine, as a standalone software package partially on the machine and partially on a remote machine, or entirely on a remote machine or server.

[0071] In the context of this invention, a computer-readable storage medium can be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, apparatus, or device. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination thereof. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory, read-only memory, erasable programmable read-only memory, optical fibers, portable compact disk read-only memory, optical storage devices, magnetic storage devices, or any suitable combination thereof.

[0072] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device having: a display device or liquid crystal display for displaying information to a user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the electronic device. Other types of devices can also be used to provide interaction with a user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).

[0073] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or middleware components (e.g., application servers), or frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., communication networks). Examples of communication networks include local area networks (LANs), wide area networks (WANs), blockchain networks, and the Internet. The computing system can include clients and servers. Clients and servers are generally geographically separated and typically interact via communication networks. Client-server relationships are created by computer programs running on the respective computers and having client-server relationships with each other. The server can be a cloud server, also known as a cloud computing server or cloud host, a host product within the cloud computing service system, addressing the shortcomings of traditional physical hosts and virtual private servers, such as high management difficulty and weak business scalability.

[0074] It should be understood that the various forms of processes shown above can be used, with steps reordered, added, or deleted. For example, the steps described in this invention can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution of this invention can be achieved, and this is not limited herein.

[0075] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.

Claims

1. A method for directly calling JavaScript programs within a browser extension, characterized in that, Applied to browser extensions, the method includes: Receive command indicator strings with unique identification prefixes transmitted by external callers, and extract the target command name and corresponding execution parameters through string splitting logic; Using the parsed target command name as the retrieval identifier, the corresponding JavaScript program module (hereinafter referred to as JS program module) is matched in the browser's extended local persistent storage space, and the program execution source code stored in the JS program module is read. Load the program's source code into the execution environment provided by the browser extension; The execution parameters are passed to the program entry point of the JS program module to drive the JS program module to run. During the running process, the native capabilities opened by the browser extension are called to complete data interaction with the target webpage and / or target site interface. After the JS program module finishes execution, a structured data object containing at least an execution status identifier and business data is generated, and the structured data object is sent back to the external caller.

2. The method according to claim 1, characterized in that, Also includes: After the browser extension is installed, it receives the JS program module generated by external import and persistently writes the JS program module to the local persistent storage space to form a JS program module set that can be dynamically expanded. The JS program module contains a uniquely bound command name and the program execution source code; The local persistent storage space includes at least one of the following: extended local storage interface, IndexedDB, extended built-in local database, and cloud synchronous storage; The JS program module can be generated from at least one of the following sources: AI intelligent agent automatic generation, user browser operation recording and translation generation, developer manual writing, and import of third-party resources.

3. The method according to claim 1, characterized in that, Using the parsed target command name as the search identifier, the corresponding JS program module is matched in the browser's extended local persistent storage space, and the program execution source code stored in the JS program module is read, including: Using the parsed target command name as the search identifier, the corresponding JS program module is matched using at least one of the following methods: Iterate through all the JS program modules stored in the local persistent storage space, compare the command names bound to each JS program module one by one, and match the JS program modules that match the search identifier; or, A key-value mapping structure with command name as key and JS program module as value is used to pre-store each JS program module, and the corresponding JS program module is directly queried and located using the target command name as key; Verify the integrity of the matched JS program module and confirm that the JS program module contains executable source code; Read the program execution source code stored inside the JS program module, cache it in the extended runtime memory, and wait for it to be loaded.

4. The method according to claim 1, characterized in that, The command instruction string carrying a unique identification prefix transmitted by the external caller is parsed using string splitting logic to extract the target command name and corresponding execution parameters, including: The browser extension continuously listens to the request channel of the external caller, waiting for the caller to send a command indicator string; Upon receiving the command instruction string, the system identifies the fixed, unique prefix at the beginning of the command instruction string to confirm that the command instruction string is a valid call instruction. Using the unique identification prefix as the starting point, the command indicator string is split and segmented to separate the target command name and multiple parameter strings; The parameter strings obtained from the splitting are parsed in at least one of the following ways: positional parameters, option parameters, and key-value pair parameters, and converted into structured execution parameters for passing into JS program modules.

5. The method according to claim 1, characterized in that, Loading program source code into the execution environment provided by a browser extension can be achieved in at least one of the following ways: Call the extended script injection API to load the program's execution source code into an independent execution domain of the page, which is isolated from the target webpage's native JS global object; The program execution source code is read in the browser extension background service context, and the program execution source code is encapsulated into an executable function through a dynamic compilation mechanism and loaded. It is isolated from the page context and runs in an independent background execution context. The program's source code is loaded and executed via a separate sub-thread of a Web Worker. The program's source code is loaded and executed based on a sandbox iframe and a cross-context message channel. The program's source code is dynamically registered or directly executed in the script execution environment corresponding to the target page by calling the user script management interface provided by the browser extension platform.

6. The method according to claim 1, characterized in that, The step of passing the execution parameters to the program entry point of the JS program module to drive the JS program module to run, and during the running process, calling the native capabilities exposed by the browser extension to complete data interaction with the target webpage and / or target site interface, includes: The execution parameters are uniformly encapsulated into an input parameter object, and the input parameter object is passed to the program entry function of the JS program module that has been loaded into the execution environment; The execution environment startup module code drives the JS program module to execute business logic based on the input parameters; During the execution of the JS program module, the browser extension's native capabilities are invoked to interact with the target webpage and / or target site's interface; wherein, the native capabilities include at least one of DOM page manipulation capabilities, network request capabilities, and browser tab control capabilities; the interaction process includes at least one of reading / modifying page DOM elements, submitting webpage forms, requesting site backend interfaces, and switching browser tabs.

7. The method according to claim 1, characterized in that, After the JS program module completes execution, a structured data object containing at least execution status identifiers and business data is generated, and the structured data object is returned to the external caller, including: After all business logic of the JS program module has been executed, capture the business data and execution status identifiers generated during the execution process. The browser extension assembles structured data objects based on the captured business data and execution status identifiers; The structured data object is serialized into a preset transmission format and sent back to the external caller that initiated the request along the original request link.

8. A device for directly calling JavaScript programs within a browser extension, characterized in that, Configured as a browser extension, the device includes: The instruction receiving and parsing module is used to receive command indicator strings carrying a unique identification prefix transmitted by external callers, and extract the target command name and corresponding execution parameters through string splitting logic. The retrieval module is used to match the corresponding JS program module in the browser's extended local persistent storage space with the parsed target command name as the retrieval identifier, and read the program execution source code stored in the JS program module. The loading module is used to load the program's source code into the execution environment provided by the browser extension; The execution module is used to pass the execution parameters to the program entry point of the JS program module, drive the JS program module to run, and call the native capabilities opened by the browser extension to complete data interaction with the target webpage and / or target site interface during the running process; The result generation and feedback module is used to generate a structured data object containing at least an execution status identifier and business data after the JS program module has been executed, and to send the structured data object back to the external caller.

9. An electronic device, characterized in that, include: At least one processor; as well as A memory communicatively connected to the at least one processor; wherein, The memory stores a computer program that can be executed by the at least one processor to enable the at least one processor to perform the method of any one of claims 1-7.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions that cause a processor to execute the method of any one of claims 1-7.

11. A computer program product comprising a computer program / instructions that, when executed by a processor, implement the method of any one of claims 1-7.