Shared
Workers
extendedLifetime
demo
With extendedLifetime
Multiply number 1:
Multiply number 2:
You will see the previous result after reload.
Result: 0
Without extendedLifetime
Multiply number 3:
Multiply number 4:
You may not see the previous result after reload if no other windows open.
Result: 0
This demo is based on
https://github.com/mdn/dom-examples/tree/main/web-workers/simple-shared-worker
, and modified for supporting the extendedLifetime option.
Please close the page, and reopen to see if the SharedWorker instance continues.