javascriptdebuggingcross-platformibooksepub3

How to debug scripted ePub3 in iBooks?


I have an ePub3 book involving scripting which works fine with Readium, but only partially in iBooks. My guess is that the JavaScript is erroring out at some point (although as a standard web app the exact same code works fine in Safari). Any thoughts on how to go about debugging this?


Solution

  • Azardi Online can be used to read the file using the browser. The built-in or add-in console can be used from there to debug. Or a console shim can be created:

    if(!console) {
      console = {
        "_log" : [],
        "log" : function() {
          var arr = [];
          for ( var i = 0; i < arguments.length; i++ ) {
            arr.push( arguments[ i ] );
          }
          this._log.push( arr.join( ", ") );
        },
        "trace" : function() {
          var stack;
          try {
            throw new Error();
          } catch( ex ) {
            stack = ex.stack;
          }
          console.log( "console.trace()\n" + stack.split( "\n" ).slice( 2 ).join( "  \n" ) );
        },
        "dir" : function( obj ) {
          console.log( "Content of " + obj );
          for ( var key in obj ) {
            var value = typeof obj[ key ] === "function" ? "function" : obj[ key ];
            console.log( " -\"" + key + "\" -> \"" + value + "\"" );
          }
        },
        "show" : function() {
          alert( this._log.join( "\n" ) );
          this._log = [];
        }
      };
    
      window.onerror = function( msg, url, line ) {
        console.log("ERROR: \"" + msg + "\" at \"" + "\", line " + line);
      }
    
      window.addEventListener( "touchstart", function( e ) {
        if( e.touches.length === 3 ) {
          console.show();
        }
      } );
    }
    

    References