puppeteer/test/assets/worker/worker.js
Joel Einbinder 93fe2b57d6 feat(Page): introduce workers (#2560)
This adds `page.workers()`, and two events `workercreated` and `workerdestroyed`. It also forwards logs from a worker into the page `console` event.

Only dedicated workers are supported for now, ServiceWorkers will probably work differently because they aren't necessarily associated with a single page.

Fixes #2350.
2018-05-21 14:31:11 -07:00

16 lines
344 B
JavaScript

console.log('hello from the worker');
function workerFunction() {
return 'worker function result';
}
self.addEventListener('message', event => {
console.log('got this data: ' + event.data);
});
(async function() {
while (true) {
self.postMessage(workerFunction.toString());
await new Promise(x => setTimeout(x, 100));
}
})();