/* OxygenHub report frame (oxygenhub#127): the hub adds this to a report's HTML pages. It tells the page around the frame how tall the report is, so the frame grows to fit instead of scrolling, and takes the hub's theme (data-theme="dark" or "light" on ) for report.css. It sends nothing but sizes, and reads nothing but the theme. */ (function () { if (window.parent === window) return; var root = document.documentElement, last = 0; var send = function () { var h = Math.ceil(Math.max(root.scrollHeight, document.body ? document.body.scrollHeight : 0)); if (h && h !== last) { last = h; window.parent.postMessage({ oxygenhubReport: { height: h } }, "*"); } }; window.addEventListener("message", function (e) { if (e.source !== window.parent) return; var t = e.data && e.data.oxygenhubTheme; if (t === "dark" || t === "light") root.dataset.theme = t; }); window.addEventListener("load", send); if (window.ResizeObserver) new ResizeObserver(send).observe(root); else setInterval(send, 500); // The frame interface (RP4): report.run() is the run on screen, and // report.history("frames.csv") that file of data/ across the report's // runs on its bookmark, oldest first, each { run, created_ms, current, // text }. Both are promises; outside the hub there is no report object. var asked = 0, waiting = {}; window.addEventListener("message", function (e) { var a = e.source === window.parent && e.data && e.data.oxygenhubAnswer; if (!a || !waiting[a.n]) return; var w = waiting[a.n]; delete waiting[a.n]; if (a.error) w.reject(new Error(a.error)); else w.resolve(a.value); }); var ask = function (what, dataset) { return new Promise(function (resolve, reject) { var n = ++asked; waiting[n] = { resolve: resolve, reject: reject }; window.parent.postMessage({ oxygenhubAsk: { n: n, what: what, dataset: dataset } }, "*"); setTimeout(function () { if (waiting[n]) { delete waiting[n]; reject(new Error("no answer from the hub")); } }, 30000); }); }; window.report = { run: function () { return ask("run"); }, history: function (dataset) { return ask("history", dataset); } }; window.parent.postMessage({ oxygenhubReport: { ready: true } }, "*"); })();