Skip to content

Commit 457cd17

Browse files
Move "debugging userscripts" to a different page
1 parent f78702d commit 457cd17

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed

content/docs/develop/userscripts/about-userscripts.md

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,3 @@ Each userscript file is a JavaScript module that exports a function. Scratch Add
128128
Userscripts are JavaScript modules, so they always run on ["strict mode"](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode). This also means that userscripts may use [top-level imports](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) to import other JavaScript files.
129129
130130
<!-- TODO: explain execution order isn't guaranteed -->
131-
132-
133-
## Debugging userscripts
134-
135-
<!-- TODO: revisit this section -->
136-
137-
**Make sure to refresh Scratch Addons from `chrome://extensions` after making any changes to your addon.**
138-
To debug userscripts, first of all make sure your addon is enabled.
139-
Then, go to a URL where you specified your userscript should run.
140-
Open the console by pressing Ctrl+Shift+J.
141-
You should see console logs by addons, including yours. If you're a devtools pro, you won't have any trouble setting breakpoints in your code.
142-
Protip: if you want to test the `addon.*` API without changing your file every time, make your addon `window.addon = addon;` (inside the main function), and you'll be able to access your addon's `addon` object from the console. Make sure to remove that line before contributing to the repo! Userscripts must not pollute the global object.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
title: Debugging userscripts
3+
description: Tips to easily debug userscripts.
4+
---
5+
6+
Tips to easily debug userscripts.
7+
8+
#### It's not always necessary to reload the extension
9+
10+
It's not necessary to reload the extension by going to `chrome://extensions` when changing the source of an already existing JavaScript or CSS files. In those cases, reloading the page is enough.
11+
12+
#### Use the addon.* API from the console
13+
14+
For development, you may choose to expose the `addon` object as a global variable, so that it can be accessed within the browser console.
15+
16+
```js
17+
export default async function ({ addon, console }) {
18+
window.addon = addon;
19+
// ...
20+
}
21+
```
22+
23+
#### Set breakpoints with the "debugger" keyword
24+
25+
The `debugger;` keyword in JavaScript will freeze the page when ran, if the developer tools are open. Setting breakpoints is useful to inspect the value of local variables during execution.
26+
27+
#### Filter console messages by addon ID
28+
29+
Enter the addon ID on the "filter" console search bar to only view logs and warnings, as well errors logged with `console.error()`. Keep in mind that this will hide all exceptions, unless you're explicitly logging them in your code.

0 commit comments

Comments
 (0)