sandboxedjs 0.1.43 → 0.1.44
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/dist/index.cjs +16 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +16 -4
- package/dist/index.js.map +1 -1
- package/dist/service-worker.js +55 -2
- package/dist/service-worker.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -28811,9 +28811,19 @@ async function createPreview(box, options = {}) {
|
|
|
28811
28811
|
});
|
|
28812
28812
|
if (!activated) return null;
|
|
28813
28813
|
}
|
|
28814
|
-
|
|
28815
|
-
|
|
28816
|
-
|
|
28814
|
+
let channel = null;
|
|
28815
|
+
const connect = () => {
|
|
28816
|
+
channel?.port1.close();
|
|
28817
|
+
channel = new MessageChannel();
|
|
28818
|
+
serveContainerOn(channel.port1, box);
|
|
28819
|
+
const target = registration.active ?? worker;
|
|
28820
|
+
target.postMessage({ type: "sandboxedjs:connect" }, [channel.port2]);
|
|
28821
|
+
};
|
|
28822
|
+
const onWorkerMessage = (event) => {
|
|
28823
|
+
if (event.data?.type === "sandboxedjs:host-needed") connect();
|
|
28824
|
+
};
|
|
28825
|
+
navigator.serviceWorker.addEventListener("message", onWorkerMessage);
|
|
28826
|
+
connect();
|
|
28817
28827
|
const base2 = registration.scope.replace(/\/$/, "");
|
|
28818
28828
|
const urlFor = (port) => `${base2}/__sbx__/${port}/`;
|
|
28819
28829
|
return {
|
|
@@ -28826,7 +28836,9 @@ async function createPreview(box, options = {}) {
|
|
|
28826
28836
|
return `${urlFor(target.port).replace(/\/$/, "")}${path}`;
|
|
28827
28837
|
},
|
|
28828
28838
|
dispose: async () => {
|
|
28829
|
-
|
|
28839
|
+
navigator.serviceWorker.removeEventListener("message", onWorkerMessage);
|
|
28840
|
+
channel?.port1.close();
|
|
28841
|
+
channel = null;
|
|
28830
28842
|
await registration.unregister();
|
|
28831
28843
|
}
|
|
28832
28844
|
};
|