Repository Public License
1// ORIX Navigator — Dev module: console mirror. OPT-IN, installed only while the Dev panel is capturing.2// World: PAGE (the only bundled script that runs there — `console` cannot be observed from an isolated world).3// It posts to `orixConsole`, a write-only handler that accepts nothing but display text: forging a message is4// equivalent to calling console.log, and grants no capability. No native object or reply is exposed.5(function () {6 "use strict";7 var handler = window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.orixConsole;8 if (!handler || window.console.__orixMirrored) return;9 var post = handler.postMessage.bind(handler);10 var stringify = JSON.stringify, slice = Array.prototype.slice, sent = 0;11 function render(value) {12 if (typeof value === "string") return value;13 if (value instanceof Error) return value.name + ": " + value.message;14 try { var json = stringify(value); if (json !== undefined) return json; } catch (e) {}15 try { return String(value); } catch (e) { return "(unprintable)"; }16 }17 ["log", "info", "warn", "error", "debug"].forEach(function (level) {18 var original = window.console[level];19 if (typeof original !== "function") return;20 window.console[level] = function () {21 try {22 if (++sent <= 2000) {23 var text = slice.call(arguments).map(render).join(" ");24 if (text.length > 4000) text = text.slice(0, 4000);25 post({ v: 1, kind: "console", payload: { level: level === "warn" ? "warning" : level, source: "console", message: text, url: "", line: 0, column: 0, time: Date.now() } });26 }27 } catch (e) {}28 return original.apply(this, arguments);29 };30 });31 try { Object.defineProperty(window.console, "__orixMirrored", { value: true, enumerable: false }); } catch (e) {}32})();33