Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 72 additions & 21 deletions webui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
<body>
<h1>Chrome Fleet</h1>
<p id="status">Loading...</p>
<table id="browsers-table"></table>
<div id="browsers-grid"
style="display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 15px;"></div>
<script>
const $ = id => document.getElementById(id);

Expand All @@ -29,8 +30,6 @@ <h1>Chrome Fleet</h1>
return data.ip_address ? data : null;
};

const linkify = address => `<a href="http://${address}" target="_blank">${address}</a>`;

const formatTimestamp = timestamp => timestamp ? timeago.format(new Date(timestamp * 1000)) : '-';

const update = async () => {
Expand All @@ -41,28 +40,80 @@ <h1>Chrome Fleet</h1>
}
const status = $('status');
status.textContent = browsers.length === 0 ? 'No browsers running!' : `${browsers.length} browser(s) running:`;
const table = $('browsers-table');
table.innerHTML = '';
const grid = $('browsers-grid');
grid.innerHTML = '';
browsers.forEach(browserId => {
const row = document.createElement('tr');
row.id = browserId;
const idCell = document.createElement('td');
idCell.textContent = browserId;
row.appendChild(idCell);
const ipCell = document.createElement('td');
ipCell.textContent = '-';
row.appendChild(ipCell);
const activityCell = document.createElement('td');
activityCell.textContent = '-';
row.appendChild(activityCell);
table.appendChild(row);
const container = document.createElement('div');
container.style.padding = '10px';
container.id = browserId;

const infoDiv = document.createElement('div');
infoDiv.style.marginBottom = '10px';

const nameSpan = document.createElement('span');
nameSpan.textContent = `${browserId} `;
nameSpan.style.fontWeight = 'bold';
infoDiv.appendChild(nameSpan);

const ipSpan = document.createElement('a');
ipSpan.textContent = '';
ipSpan.id = `${browserId}-ip`;
ipSpan.style.color = '#0066cc';
ipSpan.target = '_blank';
infoDiv.appendChild(ipSpan);

const activitySpan = document.createElement('span');
activitySpan.textContent = '';
activitySpan.id = `${browserId}-activity`;
activitySpan.style.fontSize = '0.8em';
activitySpan.style.color = '#666';
activitySpan.style.marginLeft = '10px';
infoDiv.appendChild(activitySpan);

const iframe = document.createElement('iframe');
iframe.src = 'about:blank';
iframe.style.width = '100%';
iframe.style.aspectRatio = '16 / 9';
iframe.style.border = '1px solid #888';
iframe.id = `${browserId}-iframe`;

const iframeContainer = document.createElement('div');
iframeContainer.style.position = 'relative';
iframeContainer.style.width = '100%';

const overlay = document.createElement('div');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This overlay is intention to prevent accidental clicks on the iframed live view.

overlay.style.position = 'absolute';
overlay.style.top = '0';
overlay.style.left = '0';
overlay.style.width = '100%';
overlay.style.height = '100%';
overlay.style.zIndex = '1';
overlay.style.backgroundColor = 'transparent';

iframeContainer.appendChild(iframe);
iframeContainer.appendChild(overlay);

container.appendChild(infoDiv);
container.appendChild(iframeContainer);
grid.appendChild(container);
});
for (const id of browsers) {
const browser = await getBrowser(id);
const row = $(id);
if (browser && row && row.cells[1]) {
row.cells[1].innerHTML = linkify(browser.ip_address);
row.cells[2].textContent = formatTimestamp(browser.last_activity_timestamp);
const container = $(id);
if (browser && container) {
const ipSpan = $(`${id}-ip`);
const activitySpan = $(`${id}-activity`);
const iframe = $(`${id}-iframe`);
if (ipSpan) {
ipSpan.textContent = ` (${browser.ip_address})`;
ipSpan.href = `http://${browser.ip_address}`;
}
if (activitySpan) {
activitySpan.textContent = ` ${formatTimestamp(browser.last_activity_timestamp)}`;
}
if (iframe) {
iframe.src = `http://${browser.ip_address}`;
}
}
}
} catch (error) {
Expand Down