1.0.10 • Published 10 months ago

@waba/js-console-error-interceptor v1.0.10

Weekly downloads
-
License
ISC
Repository
github
Last release
10 months ago

⚠️ JS Console Error Interceptor

📝 Description

The AI-Driven Console Error Interceptor is a powerful JavaScript library designed to enhance developer productivity by providing real-time solutions to JavaScript errors directly in the browser console. When an error occurs in the console, this library automatically intercepts the error message and sends it to OpenAI's API for analysis. The library then retrieves an AI-generated solution and displays it beneath the original error message in the console, offering instant guidance to developers on how to resolve the issue.

This library is still in beta and hasn't been thoroughly tested with all Js frameworks/libraries. If you would like to contribute, writing tests, documentation, handling scenarios, please don't hesitate to raise PRs.

EF587FAD-DDD3-42AE-8F29-B3008B4F533B_1_201_a

Getting Started

😐 Prerequisites

  • node >= 18
  • BYO OpenAI API key

Installing

npm i @waba/js-console-error-interceptor

🎬 Executing

Import and execute the library as shown below in a file that is the starting point of the application.

Examples:
  • index.js/App.js/index.html in React
  • main.ts in Angular
  • main.js/index.html in Vite, etc

Import

import { overrideConsoleError } from "@waba/js-console-error-interceptor";

Usage

overrideConsoleError(apiKey);

main.jsx - Vite

import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
import App from "./App.jsx";
import "./index.css";
import { overrideConsoleError } from "@waba/js-console-error-interceptor";

overrideConsoleError(apiKey);

createRoot(document.getElementById("root")).render(
  <StrictMode>
    <App />
  </StrictMode>
);

index.html - Vite

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <link rel="icon" type="image/svg+xml" href="/vite.svg" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Vite + React</title>
    <script type="module">
      import { overrideConsoleError } from "@waba/js-console-error-interceptor";
      const apiKey = "YOUR_API_KEY"
      overrideConsoleError(apiKey);
    </script>
  </head>
  <body>
    <div id="root"></div>
    <script type="module" src="/src/main.jsx"></script>
  </body>
</html>

😮‍💨 Common issues

  1. This utility only identifies errors on the console logged by "console.error()". If you want to see the error messages in the console (and allow the custom console.error override to work), you'll need to disable the framework's (Vite, React, etc) error overlay during development as shown below

// vite.config.js
export default {
  server: {
    hmr: {
      overlay: false, // Disable Vite's error overlay
    },
  },
};

🤓 Version History

  • 1.0.0
    • Initial Release
  • 1.0.3
    • Added console styling + QoL improvements
1.0.10

10 months ago

1.0.9

10 months ago

1.0.8

10 months ago

1.0.7

10 months ago

1.0.6

10 months ago

1.0.5

10 months ago

1.0.4

10 months ago

1.0.3

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago