Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// This worker is designed to showcase worker error rate handling.
import BackgroundClient from "iframe-coordinator/BackgroundClient";
const client = new BackgroundClient();
let currTimeout = setTimeout(triggerError, getTimeout());
function triggerError() {
// Setup the next error call, since the error will stop this function execution
currTimeout = setTimeout(triggerError, getTimeout());
console.error('Triggering an intentional error from a background worker. Will not pop rate limit');
foo.bar.baz();
}
// TODO - better listener from client api - with auto cleanup
addEventListener('message', evt => {
if (evt.data.msgType === 'before_unload') {
// Shutdown requested from host. Clean-up and acknowledge
if (currTimeout) {
import BackgroundClient from "iframe-coordinator/BackgroundClient";
// TODO Need a better demo that makes more sense?
const client = new BackgroundClient();
// Routing example
// client.requestNavigation('/wikipedia');
let currTimeout = setTimeout(sendToastMessage, getTimeout(5000, 10000));
function sendToastMessage() {
client.requestToast('from a Headless Worker', {
custom: {
level: 'info'
},
title: 'Hello worker World'
});
currTimeout = setTimeout(sendToastMessage, getTimeout());
}