Skip to content

Commit

Permalink
Add enableDebug init option reference and add it in the debug guide
Browse files Browse the repository at this point in the history
  • Loading branch information
epanholz committed Jan 7, 2025
1 parent 8b05e88 commit 6b08de1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class Example
}
```

In this example, the Java program uses `Runtime.getRuntime().exec(command)` to open a URL in the default web browser on a Linux system. The command `xdg-open` is typically used to launch a URL in the browser.On Windows, a similar behavior is achieved with the command `cmd /c start`.
In this example, the Java program uses `Runtime.getRuntime().exec(command)` to open a URL in the default web browser on a Linux system. The command `xdg-open` is typically used to launch a URL in the browser. On Windows, a similar behavior is achieved with the command `cmd /c start`.

We can now implement the same behavior in JavaScript, here’s how:

Expand All @@ -57,7 +57,7 @@ function execCb(cmdPath, argsArray) {

In this JavaScript function, we check if the incoming command is `xdg-open`. If it matches, we use `window.open()` to open a new browser tab with the specified URL.

We can now pass this function to `cheerpjInit` using the [`execCallback`] option. This ensures that the function is invoked whenever an external command is executed in Java.
We can now pass this function to [`cheerpjInit`] using the [`execCallback`] option. This ensures that the function is invoked whenever an external command is executed in Java.

```ts title="index.html"
function execCb(cmdPath, argsArray) {
Expand Down
12 changes: 12 additions & 0 deletions sites/cheerpj/src/content/docs/11-guides/cheerpj-debug.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ If your application passes all these checks but still isn't working correctly, y

If you do so, make sure to provide additional context, such as a HAR file and the browser's console output. This will make it easier for us to assist you. Instructions on how to generate these are provided in the following steps.

## Enable advanced debug logs in CheerpJ

Before saving the browser console output, it's important to enable advanced debug logs in CheerpJ using the [`enableDebug`] CheerpJ [`initOption`].

```js
cheerpjInit({ enableDebug: true });
```

This option enables advanced debug logging, which is helpful for troubleshooting issues with CheerpJ. It provides a lot of extra information in case an actual error occurs and will speed up the process of solving the problem you are encountering.

## Saving the browser console output

You can follow these steps to save the browser console output:
Expand Down Expand Up @@ -57,3 +67,5 @@ You can save a HAR following these steps:
[`cheerpjRunJar`]: /docs/reference/cheerpjRunJar
[`cheerpjRunMain`]: /docs/reference/cheerpjRunMain
[virtual filesystem]: /docs/guides/File-System-support
[`enableDebug`]: /docs/reference/cheerpjInit#enableDebug
[`initOption`]: /docs/reference/cheerpjInit
19 changes: 17 additions & 2 deletions sites/cheerpj/src/content/docs/12-reference/00-cheerpjInit.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ async function cheerpjInit(options?: {
tailscaleLoginUrlCb?: (url: string) => void;
tailscaleIpCb?: (ip: string) => void;
licenseKey?: string;
execCallback?: function(cmdPath, argsArray) {};
execCallback?: (cmdPath: string, argsArray: string []) => void;
enableDebug?: boolean;
}): Promise<void>;
```

Expand Down Expand Up @@ -377,7 +378,7 @@ cheerpjInit({ licenseKey: "YourLicenseKey" });
### `execCallback`

```ts
execCallback?: function(cmdPath, argsArray) {};
execCallback?: (cmdPath: string, argsArray: string []) => void;
```

> [!note] Important
Expand All @@ -402,6 +403,20 @@ cheerpjInit({

Learn more about the `execCallback` option in our [intercept external commands guide](/docs/guides/Intercept-external-commands).

### `enableDebug`

```ts
enableDebug?: boolean;
```

This option enables advanced debug logging, which is helpful for troubleshooting issues with CheerpJ.

Example of usage:

```js
cheerpjInit({ enableDebug: true });
```

[cjGetRuntimeResources]: /docs/reference/cjGetRuntimeResources
[Promise]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
[`java`]: /docs/reference/cheerpjInit#java-mode
Expand Down

0 comments on commit 6b08de1

Please sign in to comment.