class ReactOnRails::ServerRenderingPool::RubyEmbeddedJavaScript

def console_polyfill

Save a handle to the original console if needed.
Reimplement console methods for replaying on the client
def console_polyfill
  <<~JS
    var debugConsole = console;
    var console = { history: [] };
    ['error', 'log', 'info', 'warn'].forEach(function (level) {
      console[level] = function () {
        var argArray = Array.prototype.slice.call(arguments);
        if (argArray.length > 0) {
          argArray[0] = '[SERVER] ' + argArray[0];
        }
        console.history.push({level: level, arguments: argArray});
      };
    });
  JS
end