3434import com .foxdebug .browser .Emulator ;
3535import com .foxdebug .browser .Menu ;
3636import com .foxdebug .system .Ui ;
37+ import java .io .BufferedReader ;
38+ import java .io .File ;
39+ import java .io .FileReader ;
40+ import java .io .IOException ;
3741
3842public class Browser extends LinearLayout {
3943
@@ -42,7 +46,7 @@ public class Browser extends LinearLayout {
4246 public Menu menu ;
4347 public WebView webView ;
4448 private Ui .Theme theme ;
45- private Context context ;
49+ public Context context ;
4650 private TextView urlText ;
4751 private LinearLayout main ;
4852 private ImageView favicon ;
@@ -628,23 +632,56 @@ public void onPageFinished(WebView view, String url) {
628632 // Inject console for external sites
629633 // this is not a good solution but for now its good, later we'll improve this
630634 if (!url .startsWith ("http://localhost" )) {
631- String script =
632- "" +
633- "if(!window.eruda){" +
634- " var script = document.createElement('script');" +
635- " script.src = 'https://cdn.jsdelivr.net/npm/eruda';" +
636- " script.onload = function() {" +
637- " eruda.init({" +
638- " theme: 'dark'" +
639- " });" +
640- " eruda._shadowRoot.querySelector('.eruda-entry-btn').style.display = 'none';" +
641- " sessionStorage.setItem('__console_available', true);" +
642- " document.addEventListener('showconsole', function() { eruda.show(); });" +
643- " document.addEventListener('hideconsole', function() { eruda.hide(); });" +
644- " };" +
645- " document.head.appendChild(script);" +
646- "}" ;
647- browser .webView .evaluateJavascript (script , null );
635+ try {
636+ File eruaFile = new File (browser .context .getFilesDir (), "eruda.js" );
637+ StringBuilder scriptContent = new StringBuilder ();
638+ BufferedReader reader = new BufferedReader (new FileReader (eruaFile ));
639+ String line ;
640+ while ((line = reader .readLine ()) != null ) {
641+ scriptContent .append (line );
642+ scriptContent .append ("\n " );
643+ }
644+ reader .close ();
645+
646+ // Inject the script content directly
647+ String script =
648+ "if(!window.eruda){" +
649+ " var script = document.createElement('script');" +
650+ " script.textContent = `" +
651+ scriptContent .toString () +
652+ "`;" +
653+ " document.head.appendChild(script);" +
654+ " eruda.init({" +
655+ " theme: 'dark'" +
656+ " });" +
657+ " eruda._shadowRoot.querySelector('.eruda-entry-btn').style.display = 'none';" +
658+ " sessionStorage.setItem('__console_available', true);" +
659+ " document.addEventListener('showconsole', function() { eruda.show(); });" +
660+ " document.addEventListener('hideconsole', function() { eruda.hide(); });" +
661+ "}" ;
662+
663+ browser .webView .evaluateJavascript (script , null );
664+ } catch (IOException e ) {
665+ e .printStackTrace ();
666+ // Fallback to CDN if local file fails
667+ String fallbackScript =
668+ "if(!window.eruda){" +
669+ " var script = document.createElement('script');" +
670+ " script.src = 'https://cdn.jsdelivr.net/npm/eruda';" +
671+ " script.crossOrigin = 'anonymous';" +
672+ " script.onload = function() {" +
673+ " eruda.init({" +
674+ " theme: 'dark'" +
675+ " });" +
676+ " eruda._shadowRoot.querySelector('.eruda-entry-btn').style.display = 'none';" +
677+ " sessionStorage.setItem('__console_available', true);" +
678+ " document.addEventListener('showconsole', function() { eruda.show(); });" +
679+ " document.addEventListener('hideconsole', function() { eruda.hide(); });" +
680+ " };" +
681+ " document.head.appendChild(script);" +
682+ "}" ;
683+ browser .webView .evaluateJavascript (fallbackScript , null );
684+ }
648685 browser .menu .setChecked ("Console" , false );
649686 } else {
650687 browser .webView .evaluateJavascript (
0 commit comments