From a335941a99db4f94c285d792a87a259f7cf460ec Mon Sep 17 00:00:00 2001
From: Lucie Bader <167515375+Lucie-Bdr@users.noreply.github.com>
Date: Tue, 18 Feb 2025 18:07:16 +0100
Subject: [PATCH] Robustesse logger.js

---
 manifest.json       | 14 ++++++++++++++
 src/utils/logger.js | 38 ++++++++++++++++++++++++++------------
 src/utils/stats.js  |  1 +
 3 files changed, 41 insertions(+), 12 deletions(-)

diff --git a/manifest.json b/manifest.json
index 120ad98..399a0d4 100644
--- a/manifest.json
+++ b/manifest.json
@@ -38,6 +38,11 @@
     "default_title": "ff2BaLex"
   },
 
+  "options_ui": {
+    "page": "src/options/options.html",
+    "open_in_tab": false
+  },
+
   "sidebar_action": {
     "default_title": "BaLex",
     "default_panel": "src/sidebar/sidebar.html",
@@ -59,7 +64,16 @@
         "src/utils/stats.js"],
       "css": ["src/context_menu/custom_context_menu.css"],
       "run_at": "document_idle"
+    },
+    {
+      "matches": ["<all_urls>"],
+      "js": [
+        "src/utils/logger.js",
+        "src/utils/stats.js"
+      ],
+      "run_at": "document_end"
     }
+
   ],
 
   "web_accessible_resources": [
diff --git a/src/utils/logger.js b/src/utils/logger.js
index 79a5229..1455361 100644
--- a/src/utils/logger.js
+++ b/src/utils/logger.js
@@ -2,16 +2,30 @@
  * Mode debug : affiche les logs dans la console
  * Mode prod : masque les logs ainsi que les identifiants des lexiques
 */
-const DEBUG = true; // false en prod
-
-function log(...args) {
-  if (DEBUG) {
-    console.log(...args);
+(function () {
+  if (typeof window !== 'undefined') {
+    if (typeof window.DEBUG === 'undefined') {
+      window.DEBUG = true; // ou false en production
+    }
+    if (!window.log) {
+      function log(...args) {
+        if (window.DEBUG) {
+          console.log(...args);
+        }
+      }
+      window.log = log;
+    }
+  } else if (typeof self !== 'undefined') {
+    if (typeof self.DEBUG === 'undefined') {
+      self.DEBUG = true;
+    }
+    if (!self.log) {
+      function log(...args) {
+        if (self.DEBUG) {
+          console.log(...args);
+        }
+      }
+      self.log = log;
+    }
   }
-}
-
-if (typeof window !== 'undefined') {
-  window.log = log;
-} else if (typeof self !== 'undefined') {
-  self.log = log;
-}
+})();
diff --git a/src/utils/stats.js b/src/utils/stats.js
index c86ddb8..114c53e 100644
--- a/src/utils/stats.js
+++ b/src/utils/stats.js
@@ -1,3 +1,4 @@
+log("Stats.js chargé.");
 (function () {
 
     if (window.hasRun) {
-- 
GitLab