@jupyterlite/xeus 5.0.0 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/service-worker.d.ts +15 -0
- package/lib/service-worker.js +53 -0
- package/package.json +2 -2
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { IServiceWorkerManager } from '@jupyterlite/apputils';
|
|
2
|
+
/**
|
|
3
|
+
* Wait for the service worker to take control of this page.
|
|
4
|
+
*
|
|
5
|
+
* A page which is not cross-origin isolated has no SharedArrayBuffer, so the kernel
|
|
6
|
+
* worker performs its synchronous filesystem and stdin calls as synchronous requests
|
|
7
|
+
* answered by the service worker. A dedicated worker inherits the controller of the
|
|
8
|
+
* document which created it, as it was at the time of creation, and never gets one
|
|
9
|
+
* later. A kernel worker created before the service worker controls the page
|
|
10
|
+
* therefore has none of its requests intercepted, for its whole lifetime: the kernel
|
|
11
|
+
* hangs on its first filesystem call and the notebook stays at "Connecting" forever.
|
|
12
|
+
*
|
|
13
|
+
* @returns whether the service worker is now controlling the page.
|
|
14
|
+
*/
|
|
15
|
+
export declare function waitForServiceWorkerControl(serviceWorkerManager?: IServiceWorkerManager, serviceWorkerControlTimeout?: number): Promise<boolean>;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wait for the service worker to take control of this page.
|
|
3
|
+
*
|
|
4
|
+
* A page which is not cross-origin isolated has no SharedArrayBuffer, so the kernel
|
|
5
|
+
* worker performs its synchronous filesystem and stdin calls as synchronous requests
|
|
6
|
+
* answered by the service worker. A dedicated worker inherits the controller of the
|
|
7
|
+
* document which created it, as it was at the time of creation, and never gets one
|
|
8
|
+
* later. A kernel worker created before the service worker controls the page
|
|
9
|
+
* therefore has none of its requests intercepted, for its whole lifetime: the kernel
|
|
10
|
+
* hangs on its first filesystem call and the notebook stays at "Connecting" forever.
|
|
11
|
+
*
|
|
12
|
+
* @returns whether the service worker is now controlling the page.
|
|
13
|
+
*/
|
|
14
|
+
export async function waitForServiceWorkerControl(serviceWorkerManager, serviceWorkerControlTimeout = 10000) {
|
|
15
|
+
const { serviceWorker } = navigator;
|
|
16
|
+
// People can disable the service worker in their JupyterLite deployment.
|
|
17
|
+
if (!serviceWorkerManager || !serviceWorker) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
// registration is usually still in flight when the first kernel is requested,
|
|
21
|
+
// and rejects when there is no service worker to be had at all
|
|
22
|
+
try {
|
|
23
|
+
await serviceWorkerManager.ready;
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
if (!serviceWorkerManager.enabled) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
if (serviceWorker.controller) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
// the service worker claims its clients when it activates, so no reload is needed,
|
|
35
|
+
// but that can happen after the kernel is requested
|
|
36
|
+
const controlled = await new Promise(resolve => {
|
|
37
|
+
function done() {
|
|
38
|
+
clearTimeout(timeout);
|
|
39
|
+
serviceWorker.removeEventListener('controllerchange', done);
|
|
40
|
+
resolve(serviceWorker.controller !== null);
|
|
41
|
+
}
|
|
42
|
+
const timeout = setTimeout(done, serviceWorkerControlTimeout);
|
|
43
|
+
serviceWorker.addEventListener('controllerchange', done);
|
|
44
|
+
// controllerchange may have fired between the check above and the listener
|
|
45
|
+
if (serviceWorker.controller) {
|
|
46
|
+
done();
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
if (!controlled) {
|
|
50
|
+
console.warn(`The service worker did not take control of this page within ${serviceWorkerControlTimeout / 1000}s`);
|
|
51
|
+
}
|
|
52
|
+
return controlled;
|
|
53
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jupyterlite/xeus",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.1.0",
|
|
4
4
|
"description": "JupyterLite Xeus kernels",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"jupyter",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"@jupyterlab/coreutils": "^6.5.0",
|
|
41
41
|
"@jupyterlab/services": "^7.5.0",
|
|
42
42
|
"@jupyterlite/services": "^0.7.0 || ^0.8.0",
|
|
43
|
-
"@jupyterlite/xeus-core": "^5.
|
|
43
|
+
"@jupyterlite/xeus-core": "^5.1.0",
|
|
44
44
|
"@lumino/coreutils": "^2",
|
|
45
45
|
"@lumino/signaling": "^2",
|
|
46
46
|
"coincident": "^1.2.3",
|