Chrome extension to monitor a kiosk and reload if needed
Have a content script in the kiosk page send a message every X seconds back to the background page
In the content script:
var port = chrome.extension.connect({ name: "keep-alive" });port.postMessage('is-alive', { alive: true });setInterval(function () { port.postMessage('is-alive', { alive: true });}, 1000 * 15);
If the background page detects the message hasn't come back after a certain time then reload the tab
In the background page:
var last = Date.now();var interval = 1000 * 15;chrome.extension.onConnect.addListener(function (port) { if (port.name === 'keep-alive') { port.onMessage.addListener(function (data) { if (data.type === 'is-alive' && data.payload.alive === true) { last = Date.now(); } }); }});setInterval(function () { if (Date.now() - last > interval) { // Reload the tab... }}, interval);
For information about reloading the tab, see the chrome.tabs
documentation. You will need to add tabs
to your permission list in the manifest.
If you'd like to know more about message passing, see the Messaging docs.