Skip to content
Back to skills

Userscript Event Monitoring And Error Handling

ASecurity

A reusable pattern for monitoring page events (AJAX, DOM, visibility) with per-event-type throttling, and safely extracting/parsing error messages using XPath with conditional logic.

  • 438 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added May 30, 2026
educationnode

Security analysis

A100/100

Scanned May 30, 2026

npx -y skills add ECNU-ICALK/AutoSkill --skill userscript-event-monitoring-and-error-handling --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Userscript Event Monitoring And Error Handling?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Userscript Event Monitoring And Error Handling
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ecnu-icalk-userscript-event-monitoring-and-error-handling/badge)](https://www.skillsdirectory.com/skills/ecnu-icalk-userscript-event-monitoring-and-error-handling)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
id: "a38ddcee-2398-4e1b-afe3-050471c54bb4"
name: "Userscript Event Monitoring and Error Handling"
description: "A reusable pattern for monitoring page events (AJAX, DOM, visibility) with per-event-type throttling, and safely extracting/parsing error messages using XPath with conditional logic."
version: "0.1.0"
tags:
  - "userscript"
  - "event-monitoring"
  - "error-handling"
  - "xpath"
  - "throttling"
triggers:
  - "monitor page events userscript"
  - "throttle event logging per type"
  - "extract error message xpath safely"
  - "handle error messages with conditional logic"
  - "userscript event listener"
---

# Userscript Event Monitoring and Error Handling

A reusable pattern for monitoring page events (AJAX, DOM, visibility) with per-event-type throttling, and safely extracting/parsing error messages using XPath with conditional logic.

## Prompt

# Role & Objective
Act as a Userscript Developer. Create a script to monitor page events and handle error messages safely.

# Operational Rules & Constraints
1. **Event Monitoring**: Monitor XMLHttpRequest (loadstart, progress, load, error, abort), DOM mutations (MutationObserver), page visibility (visibilitychange), and page unload (beforeunload).
2. **Throttling**: Implement per-event-type throttling. Use a dictionary/object to track the last log time for each event type separately. Do not use a global timestamp that blocks all events.
3. **Error Extraction**: Create a function to extract text content using XPath. Wrap `document.evaluate` in a try-catch block. Return `null` if the node does not exist or an error occurs.
4. **Error Matching**: Use `String.prototype.includes()` to check if the error message contains specific text fragments. Implement conditional logic (if/else) to perform different actions based on the matched text.
5. **Variable Safety**: When incrementing numeric variables (e.g., counters, retries), explicitly cast them to `Number()` before addition to prevent string concatenation.

# Anti-Patterns
- Do not use a global throttle variable that blocks all event types.
- Do not assume XPath nodes always exist; always handle missing nodes gracefully.
- Do not perform arithmetic on variables without ensuring they are numbers.

## Triggers

- monitor page events userscript
- throttle event logging per type
- extract error message xpath safely
- handle error messages with conditional logic
- userscript event listener

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…