1+ /**
2+ * 00_Core.js - The Master Bridge Core for NetWebView2Lib
3+ * This script acts as the primary communication layer between the Browser and AutoIt.
4+ */
5+
6+ // Ο διακόπτης ελέγχου. Η AutoIt μπορεί να τον αλλάξει δυναμικά με ExecuteScript.
7+ window . DEBUG_ENABLED = window . DEBUG_ENABLED || false ;
8+
9+ /**
10+ * window.Log
11+ * Η κεντρική συνάρτηση αποστολής μηνυμάτων στην AutoIt.
12+ * @param {string|object } msg - Το μήνυμα ή το αντικείμενο προς καταγραφή.
13+ * @param {string } type - Το επίπεδο του log (DEBUG, INFO, ERROR, κλπ).
14+ */
15+ window . Log = function ( msg , type = "DEBUG" ) {
16+ if ( ! window . DEBUG_ENABLED ) return ;
17+
18+ // Αν το msg είναι αντικείμενο, το μετατρέπουμε σε string για την AutoIt
19+ let output = ( typeof msg === 'object' ) ? JSON . stringify ( msg ) : msg ;
20+
21+ const logData = {
22+ type : "CONSOLE_LOG" ,
23+ level : type ,
24+ message : output ,
25+ timestamp : new Date ( ) . toLocaleTimeString ( )
26+ } ;
27+
28+ try {
29+ window . chrome . webview . postMessage ( JSON . stringify ( logData ) ) ;
30+ } catch ( e ) {
31+ // Fallback αν το WebView2 δεν είναι ακόμα έτοιμο
32+ console . warn ( "WebView2 Bridge not ready yet." ) ;
33+ }
34+ } ;
35+
36+ /**
37+ * Console Hijacking
38+ * Μετατρέπουμε τα κλασικά console.log, console.error κλπ σε window.Log
39+ */
40+ ( function ( ) {
41+ const originalConsole = {
42+ log : console . log ,
43+ error : console . error ,
44+ warn : console . warn ,
45+ info : console . info
46+ } ;
47+
48+ console . log = function ( ) {
49+ window . Log ( arguments [ 0 ] , "BROWSER-LOG" ) ;
50+ originalConsole . log . apply ( console , arguments ) ;
51+ } ;
52+
53+ console . error = function ( ) {
54+ window . Log ( arguments [ 0 ] , "BROWSER-ERROR" ) ;
55+ originalConsole . error . apply ( console , arguments ) ;
56+ } ;
57+
58+ console . warn = function ( ) {
59+ window . Log ( arguments [ 0 ] , "BROWSER-WARN" ) ;
60+ originalConsole . warn . apply ( console , arguments ) ;
61+ } ;
62+ } ) ( ) ;
63+
64+ /**
65+ * Global Error Handler
66+ * Πιάνει όλα τα JavaScript σφάλματα (π.χ. ReferenceErrors) και τα στέλνει στην AutoIt.
67+ */
68+ window . onerror = function ( message , source , lineno , colno , error ) {
69+ if ( window . DEBUG_ENABLED ) {
70+ let errorMsg = `${ message } | Source: ${ source } | Line: ${ lineno } ` ;
71+ window . Log ( errorMsg , "CRITICAL-JS-ERROR" ) ;
72+ }
73+ return false ; // Επιτρέπει στο σφάλμα να εμφανιστεί και στα DevTools
74+ } ;
75+
76+ /**
77+ * Heartbeat (Προαιρετικό)
78+ * Ενημερώνει την AutoIt ότι το Bridge είναι ενεργό στη συγκεκριμένη σελίδα.
79+ */
80+ window . Log ( "Core Bridge Initialized and Ready" , "SYSTEM" ) ;
0 commit comments