*/
function findOrCreateTypeLogContainer(logPrefix) {
const logType = logPrefix.split(':')[0];
const containerId = `${logType}_log`;
const existingContainer = document.getElementById(containerId);
if (existingContainer) {
return existingContainer;
}
const debugElement = document.getElementById('details');
const divider = document.createElement('div');
divider.className = 'divider';
debugElement.appendChild(divider);
const htmlItem = document.createElement('div');
htmlItem.className = 'item';
htmlItem.innerHTML = `
${logType}
`;
debugElement.appendChild(htmlItem);
return document.getElementById(containerId);
}
function generatePage() {
// If run not in browser (e.g. unit test), do nothing.
if (!globalThis.document.documentElement) {
return;
}
globalThis.document.documentElement.innerHTML = mapperPageSource;
// Create main log containers in proper order.
findOrCreateTypeLogContainer(log_js_1.LogType.debugInfo);
findOrCreateTypeLogContainer(log_js_1.LogType.bidi);
findOrCreateTypeLogContainer(log_js_1.LogType.cdp);
}
exports.generatePage = generatePage;
function stringify(message) {
if (typeof message === 'object') {
return JSON.stringify(message, null, 2);
}
return message;
}
function log(logPrefix, ...messages) {
// If run not in browser (e.g. unit test), do nothing.
if (!globalThis.document.documentElement) {
return;
}
// Skip sending BiDi logs as they are logged once by `bidi:server:*`
if (!logPrefix.startsWith(log_js_1.LogType.bidi)) {
// If `sendDebugMessage` is defined, send the log message there.
globalThis.window?.sendDebugMessage?.(JSON.stringify({ logType: logPrefix, messages }));
}
const typeLogContainer = findOrCreateTypeLogContainer(logPrefix);
// This piece of HTML should be added:
//
...log message...
const lineElement = document.createElement('div');
lineElement.className = 'pre';
lineElement.textContent = [logPrefix, ...messages].map(stringify).join(' ');
typeLogContainer.appendChild(lineElement);
if (typeLogContainer.childNodes.length > 200) {
typeLogContainer.removeChild(typeLogContainer.childNodes[0]);
}
}
exports.log = log;
//# sourceMappingURL=mapperTabPage.js.map