From ef43c7831fbd38d70a53da0dfc53cc4a42190a13 Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll Date: Wed, 13 Mar 2024 09:08:37 -0400 Subject: [PATCH] - Added JS debug lib --- asset/negundo/js/debug.js | 46 +++++++++++++++++++++++++++++++++++++++ composer.json | 3 +++ meta/config.php | 9 ++++++++ meta/negundo.php | 11 ++++++++++ 4 files changed, 69 insertions(+) create mode 100644 asset/negundo/js/debug.js create mode 100644 meta/config.php diff --git a/asset/negundo/js/debug.js b/asset/negundo/js/debug.js new file mode 100644 index 0000000..41c07a3 --- /dev/null +++ b/asset/negundo/js/debug.js @@ -0,0 +1,46 @@ + +class ErrorHandler +{ + constructor(options) { + if ( options ) { + if ( "url" in options ) { + this.url = options['url']; + } + } + + this.catchError(); + } + + catchError() { + window.onerror = function(message, url, line, column, error) { + fetch(this.url ? this.url : window.location.href, { + method: "post", + headers: { + 'Accept': "application/json", + 'Content-Type': "application/json", + 'User-Agent': "NegundoClient/1.0" + }, + body: JSON.stringify({ + message: message, + url: url, + line: line, + column: column, + stack: error.stack, + location: window.location.toString() + }) + }).then( response => response ).then(data => { + console.info("Error reported", data); + }); + + return false; + }.bind(this); + } + + get url() { + return this._url; + } + + set url(set) { + return this._url = set; + } +} diff --git a/composer.json b/composer.json index 645b3e3..9265694 100644 --- a/composer.json +++ b/composer.json @@ -25,6 +25,9 @@ "autoload": { "definitions" : [ "meta/negundo.php" + ], + "config": [ + "meta/config.php" ] } } diff --git a/meta/config.php b/meta/config.php new file mode 100644 index 0000000..b057dbe --- /dev/null +++ b/meta/config.php @@ -0,0 +1,9 @@ + [ + 'autoload' => [ + 'assets.negundo' + ] + ], +]; diff --git a/meta/negundo.php b/meta/negundo.php index 67fb3ee..e5150c0 100644 --- a/meta/negundo.php +++ b/meta/negundo.php @@ -9,4 +9,15 @@ return [ NegundoMiddleware::class => autowire(NegundoMiddleware::class), Dump::class => autowire(Dump::class), Task::class => autowire(Task::class), + + 'assets.negundo' => [ + 'picea' => [ + 'asset' => [ + [ + 'path' => implode(DIRECTORY_SEPARATOR, [ dirname(__DIR__), "asset", '' ]), + 'order' => 10 + ] + ] + ], + ], ];