goldendict-ng/website/docs/howto/how to debug dictionary js.md

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

54 lines
2 KiB
Markdown
Raw Normal View History

2023-08-30 08:19:24 +00:00
# How to debug dictionary javascript
2023-08-30 08:23:23 +00:00
- [How to debug dictionary javascript](#how-to-debug-dictionary-javascript)
- [background](#background)
- [goldendict-ng inspector](#goldendict-ng-inspector)
- [How to navigate to the specified element](#how-to-navigate-to-the-specified-element)
- [Modify the css style](#modify-the-css-style)
- [check javascript events](#check-javascript-events)
- [reproduce the issue in the goldendit](#reproduce-the-issue-in-the-goldendit)
2023-08-30 08:19:24 +00:00
## background
2023-08-30 03:11:42 +00:00
When some js functions do not work as expected, this article tries to give a debug solution to pinpoint the problem.
2023-08-30 08:19:24 +00:00
## goldendict-ng inspector
2023-08-30 03:11:42 +00:00
Goldendict-ng has embedded an inspector, you can trigger it manually using `F12`.
Screenshot:
![Inspector](../img/inspector.png)
2023-08-30 08:19:24 +00:00
## How to navigate to the specified element
2023-08-30 03:11:42 +00:00
Click the find element and move mouse to the specified element, click the element will navigate the source panel to the very place.
![steps](../img/inspector-steps.png)
2023-08-30 08:19:24 +00:00
## Modify the css style
2023-08-30 03:11:42 +00:00
you can play around with the css to modify the appearance of the html and check the results.
![style](../img/inspector-style.png)
2023-08-30 08:19:24 +00:00
## check javascript events
2023-08-30 03:11:42 +00:00
- navigate to the specified element
- check eventlisterner panel
- pay attention to the click events
- in the following screenshot ,there are two registered event listeners, one from the goldendict `gd-custom.js` and one from the html itself.
- click the above event listener location will locate to the right place in the javascript.
![event](../img/inspector-event.png)
If some desired event does not triggered , it can first check does the event listeners has been successfully registered. then set a breakpoint in the right place to check whether the event has been triggered and if it can executed successfully.
![breakpoint](../img/inspector-breakpoint.png)
2023-08-30 08:19:24 +00:00
## reproduce the issue in the goldendit
2023-08-30 03:11:42 +00:00
following your normal operations and debugging the javascript code and pay attention to the console output. Whether any errors happened.
2023-08-30 08:19:24 +00:00
![Alt text](../img/inspector-console.png)