Skip to content
This repository has been archived by the owner on Mar 31, 2020. It is now read-only.

yreifschneider/background-execution

Repository files navigation

How to achieve background execution in web browsers

I'm trying to find different methods to run code in the background in populer browsers. Each method is described in a seperate file.

  1. Simple

    Interval is throttled to once per second maximum, when the tab is not marked as visible. This is the case when another tab is in focus or the browser windows is minimized.

  2. Web worker

    Web worker implementation1 of setInterval. By using a web worker, we can circumvent the throttling in some browser and can execute our callback more often. When the tab is closed, the worker gets terminated.

  3. Service worker

    Service workers can use setInterval to run concurrently in the background, even when the spawning tab is closed, but there is no guarantee, that the Browser kill the service worker.

Testing results

Tracing

Puppeteer allows tracing of web pages. See https://pptr.dev/#?product=Puppeteer&version=v1.16.0&show=api-class-tracing

The resulting json file can then be analysed in Timeline Viewer or Chrome Dev Tools.

https://chromedevtools.github.io/timeline-viewer/

npm run trace

Links and References

Related research