Communication method and device for web page and native application

By unifying the namespace domain and return body structure in JSB, the problem of cross-container calls and incomplete documentation of JSB is solved, and private JSB calls across containers are implemented and development complexity is reduced.

CN119396605APending Publication Date: 2025-02-07SHANGHAI BILIBILI TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411471654.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-21
Publication Date
2025-02-07

AI Technical Summary

Technical Problem

In the prior art, the strong binding feature of JSB and containers causes front-end developers to be unable to call private JSB capabilities of different services across containers, resulting in the need to repeatedly develop the same functions in different services and containers. At the same time, the documentation of the old version of JSB is not comprehensive, and the callback name and return body structure lack unified specifications, which increases the complexity of development and maintenance.

Method used

By obtaining the JSB callback method built based on the preset namespace domain, determining the target callback type based on the number of callbacks, creating a communication channel and registering the JSB callback method, the communication between the web page and the native application is realized. This method unifies the naming specifications and return volume data structure of JSB callback methods, supports single callback and listening callback types, making it convenient for front-end developers to use.

Benefits of technology

The private JSB ability to call different businesses across containers is realized, avoiding the repeated development of the same functions in different businesses and containers. Through unified naming specifications and return body structure, the complexity of development and maintenance is reduced, and the development efficiency and code maintainability are improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119396605A_ABST
    Figure CN119396605A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a communication method and device for a webpage and a native application, and the method comprises the steps: obtaining a JSB callback method obtained based on the construction of a preset namespace domain, and the JSB callback method has a corresponding callback frequency; determining a target callback type corresponding to the JSB callback method according to the number of callback times; creating a communication channel according to the target callback type, and registering the JSB callback method in the communication channel; communication between the web page and the native application is carried out through the communication channel so as to obtain a return body after the JSB callback method is executed, the return body comprises character codes of a preset type, and the character codes are used for representing information needing to be displayed on the web page. The naming specifications of the JSB callback method are unified through the preset namespace domain, the return body after the JSB callback method is designed and executed contains the character codes of the preset type, the data structure of the return body can be unified, and the complexity of development and maintenance is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the field of Internet technology, and in particular, to a method, apparatus, computer device, computer-readable storage medium, and computer program product for communication between a web page and a native application. Background Art

[0002] In the existing technology, with the rapid development of various businesses on the Internet platform, the diversified business needs have prompted many teams to develop private containers for their own businesses and JSB functions based on these containers based on the containers provided by NA native applications. However, due to the strong binding characteristics of JSB and containers, front-end developers cannot call the private JSB capabilities of different businesses across containers, which may lead to the need to repeatedly develop the same functions in different businesses and containers.

[0003] In addition, the documentation of the old version of JSB is not comprehensive. H5 and Na, general domain (public domain) and business domain (private domain) are maintained separately. Many JSB APIs can only be used in the old version code. However, the JSB callback names in the old version code are confusing and varied. There is no unified standard to guide and constrain the JSB callback form and name. Moreover, there are many forms of the return body of the JSB callback, and there is no unified specification.

[0004] It should be noted that the above content is not necessarily prior art, nor is it intended to limit the scope of patent protection of this application. Summary of the invention

[0005] The embodiments of the present application provide a method, apparatus, computer device, computer-readable storage medium, and computer program product for communication between a web page and a native application to solve or alleviate one or more of the technical problems raised above.

[0006] One aspect of an embodiment of the present application provides a method for communicating between a web page and a native application, the method comprising: Obtain a JSB callback method constructed based on a preset namespace domain, wherein the JSB callback method has a corresponding callback number; Determine the target callback type corresponding to the JSB callback method according to the callback number; Create a communication channel according to the target callback type, and register the JSB callback method in the communication channel; The web page communicates with the native application through the communication channel to obtain a return body after executing the JSB callback method, wherein the return body includes a character code of a preset type, and the character code is used to represent information that needs to be displayed on the web page.

[0007] Optionally, the method further comprises: When it is detected that the JSB callback method is not registered in the communication channel, an error code is returned.

[0008] Optionally, the creating a communication channel according to the target callback type includes: When the target callback type is a monitoring callback type, creating a first communication channel and registering a monitoring task for the first communication channel; or, When the target callback type is a single callback type, the front-end calling function of the JSB callback method is converted into a function for returning a Promise object.

[0009] Optionally, the method further comprises: When it is detected that the currently displayed webpage is closed, the monitoring task for the first communication channel is cancelled.

[0010] Optionally, determining a target callback type corresponding to the JSB callback method according to the callback number includes: In the case where multiple callbacks are registered and called multiple times in the JSB callback method, the target callback type is determined to be a listening callback type.

[0011] Optionally, the method further comprises: A JSB description document is generated for the JSB callback method to facilitate reference to the purpose and parameters related to the JSB callback method.

[0012] Optionally, the communicating between the web page and the native application through the communication channel includes: Based on a preset communication protocol, the web page communicates with the native application through the communication channel, wherein the preset communication protocol supports the implementation of interface calls in the new version of JSB.

[0013] Optionally, the creating a communication channel according to the target callback type includes: Based on the web page view dimension, a communication channel is created according to the target callback type.

[0014] Another aspect of an embodiment of the present application provides a communication device between a web page and a native application, characterized in that the device includes: A callback method acquisition module is used to acquire a JSB callback method constructed based on a preset namespace domain, wherein the JSB callback method has a corresponding callback number; A callback type determination module, used to determine a target callback type corresponding to the JSB callback method according to the callback number; A communication channel creation module, used to create a communication channel according to the target callback type, and register the JSB callback method in the communication channel; The page communication module is used to communicate between the web page and the native application through the communication channel to obtain the return body after executing the JSB callback method, wherein the return body contains a preset type of character code, and the character code is used to represent the information that needs to be displayed on the web page.

[0015] Another aspect of an embodiment of the present application provides a computer device, including: at least one processor; and a memory communicatively coupled to the at least one processor; Wherein: the memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the communication method between the web page and the native application as described above.

[0016] Another aspect of an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer instructions, and when the computer instructions are executed by a processor, the communication method between a web page and a native application as described above is implemented.

[0017] Another aspect of an embodiment of the present application provides a computer program product, including a computer program, which, when executed by a processor, implements the communication method between a web page and a native application as described above.

[0018] The above technical solution adopted in the embodiment of the present application may include the following advantages: unifying the naming conventions of JSB callback methods through a preset namespace domain, avoiding the problem of confusion in the names of JSB callback methods, thereby reducing the complexity of development and maintenance, and by designing the return body after executing the JSB callback method to include a preset type of character encoding, the data structure of the return body can be unified, further reducing the complexity of development and maintenance, and developers can implement the private JSB capability of calling different businesses across containers, thereby avoiding the situation where the same functions may need to be repeatedly developed in different businesses and containers. In addition, by distinguishing between single callback types and listening callback types, front-end developers can encapsulate the JSB of a single callback into a Promise object according to the callback type, which is convenient for front-end developers to use, and a set of standard event listening registration / deregistration methods can be encapsulated for the listening callback type to facilitate developers to use this type of JSB in a standardized manner. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] The accompanying drawings exemplarily illustrate the embodiments and constitute a part of the specification, and together with the text description of the specification, are used to explain the exemplary implementation of the embodiments. The embodiments shown are for illustrative purposes only and do not limit the scope of the claims. In all drawings, the same reference numerals refer to similar but not necessarily identical elements.

[0020] Figure 1 A schematic diagram of a JSB and Na communication framework in the prior art is shown; Figure 2 The flowchart schematically shows the communication method between a web page and a native application according to the first embodiment of the present application; Figure 3 A block diagram schematically shows a communication device between a web page and a native application according to the second embodiment of the present application; and Figure 4 The hardware architecture diagram of the computer device according to the third embodiment of the present application is schematically shown. DETAILED DESCRIPTION

[0021] In order to make the purpose, technical solutions and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not intended to limit the present application. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of the present application.

[0022] It should be noted that the descriptions involving "first", "second", etc. in the embodiments of the present application are only for descriptive purposes and cannot be understood as indicating or implying their relative importance or implicitly indicating the number of technical features indicated. Therefore, the features defined as "first" and "second" may explicitly or implicitly include at least one of the features. In addition, the technical solutions between the various embodiments can be combined with each other, but they must be based on the ability of ordinary technicians in the field to implement them. When the combination of technical solutions is contradictory or cannot be implemented, it should be deemed that such combination of technical solutions does not exist and is not within the scope of protection required by this application.

[0023] In the description of the present application, it should be understood that the numerical labels before the steps do not indicate the order in which the steps are executed, but are only used to facilitate the description of the present application and to distinguish each step, and therefore should not be understood as a limitation on the present application.

[0024] First, the following terms are explained: JSB: JavaScript-bridge is a technology used to implement communication between JavaScript and native applications in WebView. It is a communication bridge between H5 applications and native applications, allowing web and native applications to communicate with each other to achieve data sharing and mutual calls. This allows H5 applications to use capabilities that they do not have but native applications have.

[0025] Hybrid: Hybrid development is a mobile application development method that combines native and Web H5 technologies. With the upgrade and iteration of mobile phone hardware and the better support of the system for Web features (iOS 8+ introduces WKWebView, Android 4.4 + WebView introduces the Chromium kernel), H5 has gradually become the main force of most secondary businesses with its cross-platform compatibility, low development costs, and rapid iteration and update. With the support of offline package technology, it even has the ability to undertake some primary businesses.

[0026] Promise mode: an asynchronous programming mode that allows us to start a task execution first and get a credential object for obtaining the result of the task execution without waiting for the task to be completed before continuing to perform other operations. When the result of the task is needed, the relevant method of the credential object is called to obtain it. This avoids unnecessary waiting and increases the concurrency of the system.

[0027] Na: Native App, refers to an application developed using the same programming language as the operating system.

[0028] Secondly, in order to facilitate those skilled in the art to understand the technical solutions provided in the embodiments of the present application, the relevant technologies are described below: The widespread use of H5 is also inseparable from the ability to communicate with Na (APP native application) through JSB (JavaScript Bridge), such as Figure 1The figure shows a framework diagram of the communication between JSB and Na. Currently, the JSB used in some Internet platforms mainly uses Call and Callback to communicate between web pages and Na native applications. However, since the old version of JSB used in the Internet platform does not have a unified standard for the type and number of Callbacks, some JSB methods have multiple Callbacks. This multi-Callback API also has a pitfall (due to the self-incrementing CallbackId mechanism, when the business calls this API, each Callback parameter must have an ID placeholder, otherwise a call error will occur), which increases the complexity of development and maintenance. In addition, the parameter type and return format of JSB also lack unified specifications. Even for JSBs under the same business, the returned data structure is different.

[0029] With the continuous evolution of front-end technology, the Promise mode has gradually replaced the traditional Callback mode to provide a clearer and more modern asynchronous programming experience.

[0030] In the existing technology, the rapid development of various businesses on the Internet platform and the diversified business needs have prompted many teams to develop private containers for their respective businesses and JSB functions based on these containers based on the containers provided by NA native applications. However, due to the strong binding characteristics of JSB and containers, front-end developers cannot call the private JSB capabilities of different businesses across containers, which may lead to the need to repeatedly develop the same functions in different businesses and containers.

[0031] In addition, the documentation of the old version of JSB is not comprehensive. H5 and Na, general domain (public domain) and business domain (private domain) are maintained separately. Many JSB APIs can only be used in the old version code. However, the JSB callback names in the old version code are confusing and varied. There is no unified standard to guide and constrain the callback form and name of JSB. Moreover, there are many forms of JSB callback return bodies, and there is no unified specification. Some return bodies contain Code codes, while others do not. Those with Code codes are usually business attribute codes. There is no Code code designed for global and general error types.

[0032] To this end, the embodiment of the present application provides a technical solution and protocol specification for the communication between a web page and a native application. In this technical solution, by obtaining a JSB callback method constructed based on a preset namespace domain, the JSB callback method has a corresponding number of callbacks; according to the number of callbacks, the target callback type corresponding to the JSB callback method is determined; according to the target callback type, a communication channel is created; and the web page and the native application communicate through the communication channel to obtain the return body after executing the JSB callback method, and the return body contains a preset type of character encoding. It is possible to unify the naming specifications of the JSB callback method through the preset namespace domain, avoid the problem of confusion in the name of the JSB callback method, thereby reducing the complexity of development and maintenance. Moreover, by designing the return body after executing the JSB callback method to contain a preset type of character encoding, the data structure of the return body can be unified, further reducing the complexity of development and maintenance. Developers can implement the private JSB capability of calling different businesses across containers, thereby avoiding the situation where the same functions may need to be repeatedly developed in different businesses and containers. In addition, in this embodiment, the target callback type can include a single callback type and a listening callback type. By distinguishing between the single callback type and the listening callback type, the front-end developer can encapsulate the JSB of the single callback into a Promise object according to the callback type, which is convenient for the front-end developer to use. For the listening callback type, a set of standard event listening registration / unregistration methods can be encapsulated to facilitate the developer to use this type of JSB in a standardized manner. See below for details.

[0033] Embodiment 1 Figure 2 The flowchart schematically shows a method for communicating between a web page and a native application according to the first embodiment of the present application.

[0034] like Figure 2 As shown, the communication method between the web page and the native application may include steps S202 to S208, wherein: Step S202 , obtaining a JSB callback method constructed based on a preset namespace domain, wherein the JSB callback method has a corresponding callback number; Among them, the preset namespace domain can be called Namespace domain. The preset namespace domain can be used to express functions or modules with clear and concise names. The preset namespace domain can be named in camel case with the first letter in lowercase. The preset namespace domain has common capabilities, such as the currently available: ability, ui, share, auth, offline, net, utils, storage, teenagers and other capabilities. Namespace in the business private domain: It is divided into JSB with common business and pure business attributes. Among them, common business such as: pay; pure business private domain such as: liveLocationHalf, etc.

[0035] At the same time, the method names in the preset namespace domain should be clear, concise, and describe the function of the method. Camel case naming can be used with the first letter lowercase. If there are multiple versions, the version number can be included in the name.

[0036] Step S204 , determining the target callback type corresponding to the JSB callback method according to the callback number; Specifically, JSB can be divided into ordinary single callback type and listening callback type according to the number of callbacks of the JSB callback method. When a JSB has multiple callbacks, it will be classified as a listening type JSB, regardless of whether a single callback function is called multiple times or multiple different callbacks are called multiple times. In addition, for the case where multiple callbacks are registered in a JSB but only one of them is called and only once, or only one callback is called once (called once), it can be determined as a single callback type and processed in the same way as the single callback type.

[0037] Step S206 , creating a communication channel according to the target callback type, and registering the JSB callback method in the communication channel; In this embodiment, in order not to affect the normal operation of the old version of JSB and the unmodified H5 web page project, a communication channel is created according to the target callback type to realize the communication between the web page and the native application. Specifically, when creating a communication channel, the JSB callback method can be registered in the newly created communication channel, so that the web page can communicate with the native application through the newly created communication channel. If the JSB callback method is not registered in the newly created communication channel, it is impossible to communicate with the native application through the communication channel.

[0038] Step S208, the web page communicates with the native application through the communication channel to obtain the return body after executing the JSB callback method, the return body contains a preset type of character code, and the character code is used to represent the information that needs to be displayed on the web page.

[0039] In this embodiment, the web page communicates with the native application through a communication channel to obtain the return body after executing the JSB callback method, wherein the return body contains a preset type of character encoding, which is also a code code, used to represent the information that needs to be displayed on the web page. Specifically, the preset type can be an integer type Int, 0 represents normal (200 is not selected because most of the existing JSBs use 0 as the normal code code), 100-999 represents a general error code, and the common general code code enumeration is shown in Table 1 below.

[0040]

[0041] Table 1 In this embodiment, the JSB callback method can be registered in the newly created communication channel by registration, so that the JSB callback method can use the newly created communication channel for communication.

[0042] In an optional embodiment of the present application, the method further includes: When it is detected that the JSB callback method is not registered in the communication channel, an error code is returned.

[0043] Specifically, a new communication channel is added to the NA native application framework for the new version of JSB. useNative will call JSB through the new communication channel and will return an error for JSB that is not registered in the new communication channel. At the same time, JSB needs to indicate in the document whether the current JSB belongs to the new communication channel call or the old channel call.

[0044] In an optional embodiment of the present application, the creating a communication channel according to the target callback type includes: When the target callback type is a monitoring callback type, creating a first communication channel and registering a monitoring task for the first communication channel; or, When the target callback type is a single callback type, the front-end calling function of the JSB callback method is converted into a function for returning a Promise object.

[0045] In this embodiment, when a JSB callback method has multiple callbacks, it will be classified as a listening callback type JSB. This type of JSB can use the addChannel provided by the NA native application to create a channel and listen, and can also remove the channel listening through removeChannel; this type of listening type JSB will remove the Callback stack in js-bridge when executing removeChannel, and the NA channel listening center will also remove the event.

[0046] When the target callback type is a single callback type, the front-end call function of the JSB callback method can be converted into a function for returning a Promise object, that is, the front-end call of JSB is promise-ized to simplify the use of web page designers. In order not to affect the normal operation of old versions of JSB and unmodified web page projects, a new useNative will be added to the js-bridge library to execute the Promise-ized JSB call; when encountering some general errors OR call errors, it will go to Catch through the throw error method; JSB business errors need to be thrown to the framework, and the framework will give a 105 error Code, and the error information is placed in the Data. In this embodiment, a new communication channel can be added to the NA native application for the new JSB. useNative will be called through the new communication channel, and an error will be returned for JSB that is not registered in the new communication channel; at the same time, JSB needs to indicate in the document whether the current JSB belongs to a new communication channel call or an old communication channel call.

[0047] In an optional embodiment of the present application, the method further includes: When it is detected that the currently displayed webpage is closed, the monitoring task for the first communication channel is cancelled.

[0048] A unified channel monitoring center is provided through the client for JSB registration of channel monitoring type. All JSBs of monitoring types need to be uniformly registered with the channel monitoring center provided by the NA native application, and will be uniformly deployed by the channel monitoring center. In this embodiment, when it is monitored that the currently displayed web page is closed, specifically, when it is monitored that the web page executes beforeUnload, it means that it is monitored that the currently displayed web page is closed. At this time, the monitoring task of the registered first communication channel can be cleared to release the monitoring task of the NA application.

[0049] In an optional embodiment of the present application, determining the target callback type corresponding to the JSB callback method according to the callback number includes: In the case where multiple callbacks are registered and called multiple times in the JSB callback method, the target callback type is determined to be a listening callback type.

[0050] In this embodiment, the situation where multiple callbacks are registered and called multiple times in one JSB is abandoned. The JSB in this situation is determined as a general listening callback type, and the callback type is added by judging the business data of the Callback.

[0051] In an optional embodiment of the present application, the method further includes: A JSB description document is generated for the JSB callback method to facilitate reference to the purpose and parameters related to the JSB callback method.

[0052] In this embodiment, clear documents and comments are provided for each function and method to explain its purpose, parameters, return values ​​and possible error conditions. At this stage, JSB documents are scattered among the information of the private storage space of each business party. In the short term, an index document can be established to summarize the hyperlinks of the native application and the JSB documents of each business party; the long-term plan is for the research members of the native application to design a JSB document center and automatically generate new JSB description documents through some automated methods to avoid the need to generate JSB description documents manually, improve the accuracy of the information in the JSB description documents, and improve the efficiency of generating JSB description documents. The generated JSB description documents are convenient for users to check the purpose and parameters related to the JSB callback method.

[0053] Specifically, in order to automatically generate JSB documentation, you can extract the comments, type information, and other metadata corresponding to the JSB callback method from the source code of the native application, and then store these data as documents that are easy to read and understand. This process can be implemented in a variety of ways, such as using existing document generation tools (such as TypeDoc, JSDoc 3, or Doxygen document generators), configuring the document generation tool used so that the document generation tool can correctly read the source code and generate documents, integrating the configured document generation tool into the source code build process, and finally running the document generation tool to automatically generate the JSB documentation.

[0054] In an optional embodiment of the present application, the communicating between the web page and the native application through the communication channel includes: Based on a preset communication protocol, the web page communicates with the native application through the communication channel, wherein the preset communication protocol supports the implementation of interface calls in the new version of JSB.

[0055] In the old version of JSB, the H5 web page sends messages to the client through the window.Inject.postMessage method, and the client replies to the H5 application through the window.Inject.biliCallbackReceived method.

[0056] For the standard version of JSB, a new InjectV2.postMessage method is added, and the client uses the InjectV2.biliCallbackReceived method to make a callback. The client adds a set of JSB implementation interfaces specifically for new communication methods. For the situation where the old version of the JSB implementation interface cannot be called in the V2 method, all incremental JSBs are implemented using the new version method, and the subsequent existing JSBs also need to be migrated to the standard version of the JSB implementation solution.

[0057] In an optional embodiment of the present application, the creating a communication channel according to the target callback type includes: Based on the web page view dimension, a communication channel is created according to the target callback type.

[0058] In this embodiment, a communication channel can be maintained for each web view Webview for channel monitoring of H5 web pages, and its life cycle follows Webview. In fact, the original JSB method is wrapped with channel to make it a channel monitoring type.

[0059] As an example, JSB calls the global.registerChannel method and passes in the parameters { key: string,...params: any} to register the listener, and the client uses callbackId to callback the result.

[0060] JSB calls the global.unregisterChannel method and passes in the parameters { key: string, callbackId: string} (CallbackId is the callback ID of Register) to cancel the monitoring.

[0061] Among them, Key is the event name, and the naming method of Key still needs to follow the camel case naming method to support judgment and avoid naming conflicts. H5 can register and unregister listening through the addChannel and removeChannel methods provided by js-bridge.

[0062] In this embodiment, in order to reduce the development of private domain JSB, the general JSB capabilities that match it are reused or expanded as much as possible, which may include: 1. Capabilities that can be implemented by H5 do not need to be implemented by JSB; 2. Similar JSB capabilities already exist, and existing capabilities should be used as much as possible.

[0063] By formulating a unified JSB method naming specification, a unified JSB callback structure, a unified JSB call input parameter, and a unified JSB callback method, we can avoid confusion in JSB callback method names and inconsistent return body structures, thereby reducing the complexity of development and maintenance. Developers can implement the private JSB capability of calling different businesses across containers, thereby avoiding the situation where the same functions may need to be repeatedly developed in different businesses and containers.

[0064] Embodiment 2 Figure 3 The block diagram of the communication device between a web page and a native application according to the second embodiment of the present application is schematically shown. The device can be divided into one or more program modules, one or more program modules are stored in a storage medium, and are executed by one or more processors to complete the embodiment of the present application. The program module referred to in the embodiment of the present application refers to a series of computer program instruction segments that can complete specific functions. The following description will specifically introduce the functions of each program module in this embodiment. Figure 3 As shown, the communication device 300 between the web page and the native application may include: a callback method acquisition module 310, a callback type determination module 320, a communication channel creation module 330 and a return body acquisition module 340, wherein: A callback method acquisition module 310 is used to acquire a JSB callback method constructed based on a preset namespace domain, wherein the JSB callback method has a corresponding callback number; A callback type determination module 320, configured to determine a target callback type corresponding to the JSB callback method according to the callback number; A communication channel creation module 330, configured to create a communication channel according to the target callback type and register the JSB callback method in the communication channel; The page communication module 340 is used to communicate between the web page and the native application through the communication channel to obtain the return body after executing the JSB callback method, and the return body contains a preset type of character code, which is used to represent the information that needs to be displayed on the web page.

[0065] In an optional embodiment of the present application, the device further includes: The error code returning module is used to return an error code when it is detected that the JSB callback method is not registered in the communication channel.

[0066] In an optional embodiment of the present application, the communication channel creation module 430 includes: a first communication channel creation submodule, configured to create a first communication channel and register a monitoring task for the first communication channel when the target callback type is a monitoring callback type; or The second communication channel creation submodule is used to convert the front-end calling function of the JSB callback method into a function for returning a Promise object when the target callback type is a single callback type.

[0067] In an optional embodiment of the present application, the communication channel creation module 330 further includes: The second communication channel creation submodule is used to cancel the monitoring task for the first communication channel when it is monitored that the currently displayed web page is closed.

[0068] In an optional embodiment of the present application, the callback type determination module 320 includes: The single callback type determination submodule is used to determine that the target callback type is a single callback type when multiple callback methods are registered in the JSB callback method or one callback method is called multiple times.

[0069] In an optional embodiment of the present application, the preset type is an integer type.

[0070] In an optional embodiment of the present application, the device further includes: The JSB description document generation module is used to generate a JSB description document for the JSB callback method, so as to facilitate the reference to the purpose and parameters related to the JSB callback method.

[0071] In an optional embodiment of the present application, the page communication module 340 includes: The page communication submodule is used to communicate between the web page and the native application through the communication channel based on a preset communication protocol, wherein the preset communication protocol supports the implementation of interface calls in the new version of JSB.

[0072] In an optional embodiment of the present application, the communication channel creation module 330 includes: The communication channel creation submodule is used to create a communication channel based on the web page view dimension and the target callback type.

[0073] Embodiment 3 Figure 4The schematic diagram of the hardware architecture of a computer device 10000 suitable for implementing the communication method between a web page and a native application according to the third embodiment of the present application is shown schematically. In some embodiments, the computer device 10000 may be a terminal device such as a smart phone, a wearable device, a tablet computer, a personal computer, a vehicle terminal, a game console, a virtual device, a workbench, a digital assistant, a set-top box, a robot, etc. In other embodiments, the computer device 10000 may be a rack server, a blade server, a tower server, or a cabinet server (including an independent server, or a server cluster composed of multiple servers), etc. Figure 4 As shown, the computer device 10000 includes but is not limited to: a memory 10010, a processor 10020, and a network interface 10030 that can communicate with each other through a system bus. Among them: The memory 10010 includes at least one type of computer-readable storage medium, and the readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (such as 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 10010 can be an internal storage module of the computer device 10000, such as a hard disk or memory of the computer device 10000. In other embodiments, the memory 10010 can also be an external storage device of the computer device 10000, such as a plug-in hard disk equipped on the computer device 10000, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. Of course, the memory 10010 can also include both the internal storage module of the computer device 10000 and its external storage device. In this embodiment, the memory 10010 is generally used to store the operating system and various application software installed on the computer device 10000, such as program codes of the communication method between web pages and native applications, etc. In addition, the memory 10010 can also be used to temporarily store various data that have been output or will be output.

[0074] In some embodiments, the processor 10020 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other chips. The processor 10020 is generally used to control the overall operation of the computer device 10000, such as performing control and processing related to data interaction or communication with the computer device 10000. In this embodiment, the processor 10020 is used to run the program code stored in the memory 10010 or process data.

[0075] The network interface 10030 may include a wireless network interface or a wired network interface, and the network interface 10030 is generally used to establish a communication link between the computer device 10000 and other computer devices. For example, the network interface 10030 is used to connect the computer device 10000 to an external terminal through a network, and to establish a data transmission channel and a communication link between the computer device 10000 and the external terminal. The network may be a wireless or wired network such as an intranet, the Internet, the Global System of Mobile communication (GSM), Wideband Code Division Multiple Access (WCDMA), 4G network, 5G network, Bluetooth, Wi-Fi, etc.

[0076] It should be pointed out that Figure 4 Only a computer device having components 10010 - 10030 is shown, but it should be understood that implementing all of the components shown is not a requirement, and more or fewer components may alternatively be implemented.

[0077] In this embodiment, the communication method between the web page and the native application stored in the memory 10010 can also be divided into one or more program modules and executed by one or more processors (such as processor 10020) to complete the embodiment of the present application.

[0078] Embodiment 4 An embodiment of the present application further provides a computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the steps of the method for communicating between a web page and a native application in the embodiment are implemented.

[0079] In this embodiment, the computer-readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), 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, disk, optical disk, etc. In some embodiments, the computer-readable storage medium may be an internal storage unit of a computer device, such as a hard disk or memory of the computer device. In other embodiments, the computer-readable storage medium may also be an external storage device of a computer device, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. equipped on the computer device. Of course, the computer-readable storage medium may also include both an internal storage unit of a computer device and an external storage device thereof. In this embodiment, the computer-readable storage medium is generally used to store an operating system and various application software installed on a computer device, such as the program code of the communication method between a web page and a native application in the embodiment, etc. In addition, the computer-readable storage medium may also be used to temporarily store various types of data that have been output or are to be output.

[0080] Embodiment 5 An embodiment of the present application also provides a computer program product, including a computer program, which implements the method in the above embodiment when executed by a processor.

[0081] Obviously, those skilled in the art should understand that the modules or steps of the above-mentioned embodiments of the present application can be implemented by general-purpose computer devices, they can be concentrated on a single computer device, or distributed on a network composed of multiple computer devices, optionally, they can be implemented by executable program codes of computer devices, so that they can be stored in a storage device and executed by the computer device, and in some cases, the steps shown or described can be executed in a different order from that herein, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. In this way, the embodiments of the present application are not limited to any specific combination of hardware and software.

[0082] It should be noted that the above are only preferred embodiments of the present application, and the patent protection scope of the present application is not limited thereto. Any equivalent structure or equivalent process transformation made using the contents of the specification and drawings of the present application, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.

Claims

1. A method for communicating between a web page and a native application, characterized in that: The method comprises: Obtain a JSB callback method constructed based on a preset namespace domain, wherein the JSB callback method has a corresponding callback number; Determine the target callback type corresponding to the JSB callback method according to the callback number; Create a communication channel according to the target callback type, and register the JSB callback method in the communication channel; The web page communicates with the native application through the communication channel to obtain a return body after executing the JSB callback method, wherein the return body includes a character code of a preset type, and the character code is used to represent information that needs to be displayed on the web page.

2. The method for communicating between a web page and a native application according to claim 1, characterized in that: The method further comprises: When it is detected that the JSB callback method is not registered in the communication channel, an error code is returned.

3. The method for communicating between a web page and a native application according to claim 1, characterized in that: The creating a communication channel according to the target callback type includes: When the target callback type is a monitoring callback type, creating a first communication channel and registering a monitoring task for the first communication channel; or, When the target callback type is a single callback type, the front-end calling function of the JSB callback method is converted into a function for returning a Promise object.

4. The method for communicating between a web page and a native application according to claim 3, characterized in that: The method further comprises: When it is detected that the currently displayed webpage is closed, the monitoring task for the first communication channel is cancelled.

5. The method for communicating between a web page and a native application according to claim 1, characterized in that: The determining, according to the callback number, a target callback type corresponding to the JSB callback method includes: In the case where multiple callbacks are registered and called multiple times in the JSB callback method, the target callback type is determined to be a listening callback type.

6. The method for communicating between a web page and a native application according to claim 1, characterized in that: The method further comprises: A JSB description document is generated for the JSB callback method to facilitate reference to the purpose and parameters related to the JSB callback method.

7. The method for communicating between a web page and a native application according to claim 1, characterized in that: The communicating between the web page and the native application through the communication channel includes: Based on a preset communication protocol, the web page communicates with the native application through the communication channel, wherein the preset communication protocol supports the implementation of interface calls in the new version of JSB.

8. The method for communicating between a web page and a native application according to claim 1, characterized in that: The creating a communication channel according to the target callback type includes: Based on the web page view dimension, a communication channel is created according to the target callback type.

9. A communication device between a web page and a native application, characterized in that: The device comprises: A callback method acquisition module is used to acquire a JSB callback method constructed based on a preset namespace domain, wherein the JSB callback method has a corresponding callback number; A callback type determination module, used to determine a target callback type corresponding to the JSB callback method according to the callback number; A communication channel creation module, used to create a communication channel according to the target callback type, and register the JSB callback method in the communication channel; The page communication module is used to communicate between the web page and the native application through the communication channel to obtain the return body after executing the JSB callback method, wherein the return body contains a preset type of character code, and the character code is used to represent the information that needs to be displayed on the web page.

10. A computer device, characterized in that: include: at least one processor; and a memory communicatively coupled to the at least one processor; wherein: The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the communication method between a web page and a native application according to any one of claims 1 to 8.

11. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and when the computer instructions are executed by a processor, the communication method between a web page and a native application according to any one of claims 1 to 8 is implemented.

12. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the communication method between a web page and a native application described in claims 1 to 8 are implemented.