# Invoking Application Functions on the Frontend Page
You can use the **Web** component to register application code with frontend pages. After the registration is done, frontend pages can use the registered object names to call application functions.
Two methods are available for registering the application code:
Call [javaScriptProxy()](../reference/apis-arkweb/ts-basic-components-web.md#javascriptproxy) during **Web** component initialization. Call [registerJavaScriptProxy()](../reference/apis-arkweb/js-apis-webview.md#registerjavascriptproxy) after **Web** component initialization.
The following example registers the **test()** function with the frontend page. This way, the **test()** function can be triggered and run on the frontend page.
- Sample code for using [javaScriptProxy()](../reference/apis-arkweb/ts-basic-components-web.md#javascriptproxy):
```ts
// xxx.ets
import { webview } from '@kit.ArkWeb';
class testClass {
constructor() {
}
test(): string {
return 'ArkTS Hello World!';
}
}
@Entry
@Component
struct WebComponent {
webviewController: webview.WebviewController = new webview.WebviewController();
// Declare the object to be registered.
@State testObj: testClass = new testClass();
build() {
Column() {
// Load the local index.html page.
Web({ src: $rawfile('index.html'), controller: this.webviewController})
// Inject the object to the web client.
.javaScriptProxy({
object: this.testObj,
name: "testObjName",
methodList: ["test"],
controller: this.webviewController,
// Optional parameter.
asyncMethodList: [],
permission: '{"javascriptProxyPermission":{"urlPermissionList":[{"scheme":"resource","host":"rawfile","port":"","path":""},' +
'{"scheme":"e","host":"f","port":"g","path":"h"}],"methodList":[{"methodName":"test","urlPermissionList":' +
'[{"scheme":"https","host":"xxx.com","port":"","path":""},{"scheme":"resource","host":"rawfile","port":"","path":""}]},' +
'{"methodName":"test11","urlPermissionList":[{"scheme":"q","host":"r","port":"","path":"t"},' +
'{"scheme":"u","host":"v","port":"","path":""}]}]}}'
})
}
}
}
```
- Sample code for using [registerJavaScriptProxy()](../reference/apis-arkweb/js-apis-webview.md#registerjavascriptproxy):
```ts
// xxx.ets
import { webview } from '@kit.ArkWeb';
import { BusinessError } from '@kit.BasicServicesKit';
class testClass {
constructor() {
}
test(): string {
return "ArkUI Web Component";
}
toString(): void {
console.log('Web Component toString');
}
}
@Entry
@Component
struct Index {
webviewController: webview.WebviewController = new webview.WebviewController();
@State testObj: testClass = new testClass();
build() {
Column() {
Button('refresh')
.onClick(() => {
try {
this.webviewController.refresh();
} catch (error) {
console.error(`ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`);
}
})
Button('Register JavaScript To Window')
.onClick(() => {
try {
this.webviewController.registerJavaScriptProxy(this.testObj, "testObjName", ["test", "toString"],
// Optional parameter: asyncMethodList
[],
// Optional parameter: permission
'{"javascriptProxyPermission":{"urlPermissionList":[{"scheme":"resource","host":"rawfile","port":"","path":""},' +
'{"scheme":"e","host":"f","port":"g","path":"h"}],"methodList":[{"methodName":"test","urlPermissionList":' +
'[{"scheme":"https","host":"xxx.com","port":"","path":""},{"scheme":"resource","host":"rawfile","port":"","path":""}]},' +
'{"methodName":"test11","urlPermissionList":[{"scheme":"q","host":"r","port":"","path":"t"},' +
'{"scheme":"u","host":"v","port":"","path":""}]}]}}'
);
} catch (error) {
console.error(`ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`);
}
})
Web({ src: $rawfile('index.html'), controller: this.webviewController })
}
}
}
```
> **NOTE**
>
> - If you use [registerJavaScriptProxy()](../reference/apis-arkweb/js-apis-webview.md#registerjavascriptproxy) to register a function, call [refresh()](../reference/apis-arkweb/js-apis-webview.md#refresh) for the function to take effect.
- The optional parameter permission is a JSON string. The following is an example:
```json
{
"javascriptProxyPermission": {
"urlPermissionList": [ // Object-level permission. If it is granted, all methods are available.
{
"scheme": "resource", // Exact match. The value cannot be empty.
"host": "rawfile", // Exact match. The value cannot be empty.
"port": "", // Exact match. If the value is empty, it is not checked.
"path": "" // Prefix match. If the value is empty, it is not checked.
},
{
"scheme": "https", // Exact match. The value cannot be empty.
"host": "xxx.com", // Exact match. The value cannot be empty.
"port": "", // Exact match. If the value is empty, it is not checked.
"path": "a/b/c" // Prefix match. If the value is empty, it is not checked.
}
],
"methodList": [
{
"methodName": "test",
"urlPermissionList": [ // Method-level permission.
{
"scheme": "https", // Exact match. The value cannot be empty.
"host": "xxx.com", // Exact match. The value cannot be empty.
"port": "", // Exact match. If the value is empty, it is not checked.
"path": "" // Prefix match. If the value is empty, it is not checked.
},
{
"scheme": "resource", // Exact match. The value cannot be empty.
"host": "rawfile", // Exact match. The value cannot be empty.
"port": "", // Exact match. If the value is empty, it is not checked.
"path": "" // Prefix match. If the value is empty, it is not checked.
}
]
},
{
"methodName": "test11",
"urlPermissionList": [ // Method-level permission.
{
"scheme": "q", // Exact match. The value cannot be empty.
"host": "r", // Exact match. The value cannot be empty.
"port": "", // Exact match. If the value is empty, it is not checked.
"path": "t" // Prefix match. If the value is empty, it is not checked.
},
{
"scheme": "u", // Exact match. The value cannot be empty.
"host": "v", // Exact match. The value cannot be empty.
"port": "", // Exact match. If the value is empty, it is not checked.
"path": "" // Prefix match. If the value is empty, it is not checked.
}
]
}
]
}
}
```
- Sample code for invoking application functions on the **index.html** frontend page:
```html