aboutsummaryrefslogtreecommitdiffhomepage
path: root/public/~partytown/debug
diff options
context:
space:
mode:
Diffstat (limited to 'public/~partytown/debug')
-rw-r--r--public/~partytown/debug/partytown-atomics.js122
-rw-r--r--public/~partytown/debug/partytown-media.js2
-rw-r--r--public/~partytown/debug/partytown-sandbox-sw.js122
-rw-r--r--public/~partytown/debug/partytown-sw.js4
-rw-r--r--public/~partytown/debug/partytown-ww-atomics.js251
-rw-r--r--public/~partytown/debug/partytown-ww-sw.js251
-rw-r--r--public/~partytown/debug/partytown.js7
7 files changed, 584 insertions, 175 deletions
diff --git a/public/~partytown/debug/partytown-atomics.js b/public/~partytown/debug/partytown-atomics.js
index 404e664..307e3b9 100644
--- a/public/~partytown/debug/partytown-atomics.js
+++ b/public/~partytown/debug/partytown-atomics.js
@@ -1,4 +1,4 @@
-/* Partytown 0.5.4 - MIT builder.io */
+/* Partytown 0.7.5 - MIT builder.io */
(window => {
const isPromise = v => "object" == typeof v && v && v.then;
const noop = () => {};
@@ -119,14 +119,18 @@
Cstr.observedAttributes = ceData[1];
return Cstr;
};
- const serializeForWorker = ($winId$, value, added, type, cstrName) => void 0 !== value && (type = typeof value) ? "string" === type || "number" === type || "boolean" === type || null == value ? [ 0, value ] : "function" === type ? [ 6 ] : (added = added || new Set) && Array.isArray(value) ? added.has(value) ? [ 1, [] ] : added.add(value) && [ 1, value.map((v => serializeForWorker($winId$, v, added))) ] : "object" === type ? "" === (cstrName = getConstructorName(value)) ? [ 2, {} ] : "Window" === cstrName ? [ 3, [ $winId$, $winId$ ] ] : "HTMLCollection" === cstrName || "NodeList" === cstrName ? [ 7, Array.from(value).map((v => serializeForWorker($winId$, v, added)[1])) ] : cstrName.endsWith("Event") ? [ 5, serializeObjectForWorker($winId$, value, added) ] : "CSSRuleList" === cstrName ? [ 12, Array.from(value).map(serializeCssRuleForWorker) ] : startsWith(cstrName, "CSS") && cstrName.endsWith("Rule") ? [ 11, serializeCssRuleForWorker(value) ] : "CSSStyleDeclaration" === cstrName ? [ 13, serializeObjectForWorker($winId$, value, added) ] : "Attr" === cstrName ? [ 10, [ value.name, value.value ] ] : value.nodeType ? [ 3, [ $winId$, getAndSetInstanceId(value), getNodeName(value) ] ] : [ 2, serializeObjectForWorker($winId$, value, added, true, true) ] : void 0 : value;
+ const serializeForWorker = ($winId$, value, added, type, cstrName) => void 0 !== value && (type = typeof value) ? "string" === type || "number" === type || "boolean" === type || null == value ? [ 0, value ] : "function" === type ? [ 6 ] : (added = added || new Set) && Array.isArray(value) ? added.has(value) ? [ 1, [] ] : added.add(value) && [ 1, value.map((v => serializeForWorker($winId$, v, added))) ] : "object" === type ? serializedValueIsError(value) ? [ 14, {
+ name: value.name,
+ message: value.message,
+ stack: value.stack
+ } ] : "" === (cstrName = getConstructorName(value)) ? [ 2, {} ] : "Window" === cstrName ? [ 3, [ $winId$, $winId$ ] ] : "HTMLCollection" === cstrName || "NodeList" === cstrName ? [ 7, Array.from(value).map((v => serializeForWorker($winId$, v, added)[1])) ] : cstrName.endsWith("Event") ? [ 5, serializeObjectForWorker($winId$, value, added) ] : "CSSRuleList" === cstrName ? [ 12, Array.from(value).map(serializeCssRuleForWorker) ] : startsWith(cstrName, "CSS") && cstrName.endsWith("Rule") ? [ 11, serializeCssRuleForWorker(value) ] : "CSSStyleDeclaration" === cstrName ? [ 13, serializeObjectForWorker($winId$, value, added) ] : "Attr" === cstrName ? [ 10, [ value.name, value.value ] ] : value.nodeType ? [ 3, [ $winId$, getAndSetInstanceId(value), getNodeName(value) ] ] : [ 2, serializeObjectForWorker($winId$, value, added, true, true) ] : void 0 : value;
const serializeObjectForWorker = (winId, obj, added, includeFunctions, includeEmptyStrings, serializedObj, propName, propValue) => {
serializedObj = {};
if (!added.has(obj)) {
added.add(obj);
for (propName in obj) {
if (isValidMemberName(propName)) {
- propValue = obj[propName];
+ propValue = "path" === propName && getConstructorName(obj).endsWith("Event") ? obj.composedPath() : obj[propName];
(includeFunctions || "function" != typeof propValue) && (includeEmptyStrings || "" !== propValue) && (serializedObj[propName] = serializeForWorker(winId, propValue, added));
}
}
@@ -141,6 +145,7 @@
}
return obj;
};
+ const serializedValueIsError = value => value instanceof window.top.Error;
const deserializeFromWorker = (worker, serializedTransfer, serializedType, serializedValue) => {
if (serializedTransfer) {
serializedType = serializedTransfer[0];
@@ -272,44 +277,6 @@
}
return instance;
};
- const registerWindow = (worker, $winId$, $window$) => {
- if (!windowIds.has($window$)) {
- windowIds.set($window$, $winId$);
- const doc = $window$.document;
- const history = $window$.history;
- const $parentWinId$ = windowIds.get($window$.parent);
- const sendInitEnvData = () => worker.postMessage([ 5, {
- $winId$: $winId$,
- $parentWinId$: $parentWinId$,
- $url$: doc.baseURI,
- $visibilityState$: doc.visibilityState
- } ]);
- const pushState = history.pushState.bind(history);
- const replaceState = history.replaceState.bind(history);
- const onLocationChange = () => setTimeout((() => worker.postMessage([ 13, $winId$, doc.baseURI ])));
- history.pushState = (data, _, url) => {
- pushState(data, _, url);
- onLocationChange();
- };
- history.replaceState = (data, _, url) => {
- replaceState(data, _, url);
- onLocationChange();
- };
- $window$.addEventListener("popstate", onLocationChange);
- $window$.addEventListener("hashchange", onLocationChange);
- doc.addEventListener("visibilitychange", (() => worker.postMessage([ 14, $winId$, doc.visibilityState ])));
- winCtxs[$winId$] = {
- $winId$: $winId$,
- $window$: $window$
- };
- winCtxs[$winId$].$startTime$ = performance.now();
- {
- const winType = $winId$ === $parentWinId$ ? "top" : "iframe";
- logMain(`Registered ${winType} window ${normalizedWinId($winId$)}`);
- }
- "complete" === doc.readyState ? sendInitEnvData() : $window$.addEventListener("load", sendInitEnvData);
- }
- };
const readNextScript = (worker, winCtx) => {
let $winId$ = winCtx.$winId$;
let win = winCtx.$window$;
@@ -372,6 +339,75 @@
requestAnimationFrame((() => readNextScript(worker, winCtx)));
}
};
+ const registerWindow = (worker, $winId$, $window$) => {
+ if (!windowIds.has($window$)) {
+ windowIds.set($window$, $winId$);
+ const doc = $window$.document;
+ const history = $window$.history;
+ const $parentWinId$ = windowIds.get($window$.parent);
+ let initialised = false;
+ const onInitialisedQueue = [];
+ const onInitialised = callback => {
+ initialised ? callback() : onInitialisedQueue.push(callback);
+ };
+ const sendInitEnvData = () => {
+ worker.postMessage([ 5, {
+ $winId$: $winId$,
+ $parentWinId$: $parentWinId$,
+ $url$: doc.baseURI,
+ $visibilityState$: doc.visibilityState
+ } ]);
+ setTimeout((() => {
+ initialised = true;
+ onInitialisedQueue.forEach((callback => {
+ callback();
+ }));
+ }));
+ };
+ const pushState = history.pushState.bind(history);
+ const replaceState = history.replaceState.bind(history);
+ const onLocationChange = (type, state, newUrl, oldUrl) => () => {
+ setTimeout((() => {
+ worker.postMessage([ 13, {
+ $winId$: $winId$,
+ type: type,
+ state: state,
+ url: doc.baseURI,
+ newUrl: newUrl,
+ oldUrl: oldUrl
+ } ]);
+ }));
+ };
+ history.pushState = (state, _, newUrl) => {
+ pushState(state, _, newUrl);
+ onInitialised(onLocationChange(0, state, null == newUrl ? void 0 : newUrl.toString()));
+ };
+ history.replaceState = (state, _, newUrl) => {
+ replaceState(state, _, newUrl);
+ onInitialised(onLocationChange(1, state, null == newUrl ? void 0 : newUrl.toString()));
+ };
+ $window$.addEventListener("popstate", (event => {
+ onInitialised(onLocationChange(2, event.state));
+ }));
+ $window$.addEventListener("hashchange", (event => {
+ onInitialised(onLocationChange(3, {}, event.newURL, event.oldURL));
+ }));
+ $window$.addEventListener("ptupdate", (() => {
+ readNextScript(worker, winCtxs[$winId$]);
+ }));
+ doc.addEventListener("visibilitychange", (() => worker.postMessage([ 14, $winId$, doc.visibilityState ])));
+ winCtxs[$winId$] = {
+ $winId$: $winId$,
+ $window$: $window$
+ };
+ winCtxs[$winId$].$startTime$ = performance.now();
+ {
+ const winType = $winId$ === $parentWinId$ ? "top" : "iframe";
+ logMain(`Registered ${winType} window ${normalizedWinId($winId$)}`);
+ }
+ "complete" === doc.readyState ? sendInitEnvData() : $window$.addEventListener("load", sendInitEnvData);
+ }
+ };
const onMessageFromWebWorker = (worker, msg, winCtx) => {
if (4 === msg[0]) {
registerWindow(worker, randomId(), mainWindow);
@@ -521,14 +557,14 @@
};
})(((accessReq, responseCallback) => mainAccessHandler(worker, accessReq).then(responseCallback))).then((onMessageHandler => {
if (onMessageHandler) {
- worker = new Worker(libPath + "partytown-ww-atomics.js?v=0.5.4", {
+ worker = new Worker(libPath + "partytown-ww-atomics.js?v=0.7.5", {
name: "Partytown 🎉"
});
worker.onmessage = ev => {
const msg = ev.data;
12 === msg[0] ? mainAccessHandler(worker, msg[1]) : onMessageHandler(worker, msg);
};
- logMain("Created Partytown web worker (0.5.4)");
+ logMain("Created Partytown web worker (0.7.5)");
worker.onerror = ev => console.error("Web Worker Error", ev);
mainWindow.addEventListener("pt1", (ev => registerWindow(worker, getAndSetInstanceId(ev.detail.frameElement), ev.detail)));
}
diff --git a/public/~partytown/debug/partytown-media.js b/public/~partytown/debug/partytown-media.js
index bff2dd9..5c43065 100644
--- a/public/~partytown/debug/partytown-media.js
+++ b/public/~partytown/debug/partytown-media.js
@@ -1,4 +1,4 @@
-/* Partytown 0.5.4 - MIT builder.io */
+/* Partytown 0.7.5 - MIT builder.io */
(self => {
const [getter, setter, callMethod, constructGlobal, definePrototypePropertyDescriptor, randomId, WinIdKey, InstanceIdKey, ApplyPathKey] = self.$bridgeToMedia$;
delete self.$bridgeToMedia$;
diff --git a/public/~partytown/debug/partytown-sandbox-sw.js b/public/~partytown/debug/partytown-sandbox-sw.js
index 9ca9e5f..9cd875c 100644
--- a/public/~partytown/debug/partytown-sandbox-sw.js
+++ b/public/~partytown/debug/partytown-sandbox-sw.js
@@ -1,4 +1,4 @@
-/* Partytown 0.5.4 - MIT builder.io */
+/* Partytown 0.7.5 - MIT builder.io */
(window => {
const isPromise = v => "object" == typeof v && v && v.then;
const noop = () => {};
@@ -119,14 +119,18 @@
Cstr.observedAttributes = ceData[1];
return Cstr;
};
- const serializeForWorker = ($winId$, value, added, type, cstrName) => void 0 !== value && (type = typeof value) ? "string" === type || "number" === type || "boolean" === type || null == value ? [ 0, value ] : "function" === type ? [ 6 ] : (added = added || new Set) && Array.isArray(value) ? added.has(value) ? [ 1, [] ] : added.add(value) && [ 1, value.map((v => serializeForWorker($winId$, v, added))) ] : "object" === type ? "" === (cstrName = getConstructorName(value)) ? [ 2, {} ] : "Window" === cstrName ? [ 3, [ $winId$, $winId$ ] ] : "HTMLCollection" === cstrName || "NodeList" === cstrName ? [ 7, Array.from(value).map((v => serializeForWorker($winId$, v, added)[1])) ] : cstrName.endsWith("Event") ? [ 5, serializeObjectForWorker($winId$, value, added) ] : "CSSRuleList" === cstrName ? [ 12, Array.from(value).map(serializeCssRuleForWorker) ] : startsWith(cstrName, "CSS") && cstrName.endsWith("Rule") ? [ 11, serializeCssRuleForWorker(value) ] : "CSSStyleDeclaration" === cstrName ? [ 13, serializeObjectForWorker($winId$, value, added) ] : "Attr" === cstrName ? [ 10, [ value.name, value.value ] ] : value.nodeType ? [ 3, [ $winId$, getAndSetInstanceId(value), getNodeName(value) ] ] : [ 2, serializeObjectForWorker($winId$, value, added, true, true) ] : void 0 : value;
+ const serializeForWorker = ($winId$, value, added, type, cstrName) => void 0 !== value && (type = typeof value) ? "string" === type || "number" === type || "boolean" === type || null == value ? [ 0, value ] : "function" === type ? [ 6 ] : (added = added || new Set) && Array.isArray(value) ? added.has(value) ? [ 1, [] ] : added.add(value) && [ 1, value.map((v => serializeForWorker($winId$, v, added))) ] : "object" === type ? serializedValueIsError(value) ? [ 14, {
+ name: value.name,
+ message: value.message,
+ stack: value.stack
+ } ] : "" === (cstrName = getConstructorName(value)) ? [ 2, {} ] : "Window" === cstrName ? [ 3, [ $winId$, $winId$ ] ] : "HTMLCollection" === cstrName || "NodeList" === cstrName ? [ 7, Array.from(value).map((v => serializeForWorker($winId$, v, added)[1])) ] : cstrName.endsWith("Event") ? [ 5, serializeObjectForWorker($winId$, value, added) ] : "CSSRuleList" === cstrName ? [ 12, Array.from(value).map(serializeCssRuleForWorker) ] : startsWith(cstrName, "CSS") && cstrName.endsWith("Rule") ? [ 11, serializeCssRuleForWorker(value) ] : "CSSStyleDeclaration" === cstrName ? [ 13, serializeObjectForWorker($winId$, value, added) ] : "Attr" === cstrName ? [ 10, [ value.name, value.value ] ] : value.nodeType ? [ 3, [ $winId$, getAndSetInstanceId(value), getNodeName(value) ] ] : [ 2, serializeObjectForWorker($winId$, value, added, true, true) ] : void 0 : value;
const serializeObjectForWorker = (winId, obj, added, includeFunctions, includeEmptyStrings, serializedObj, propName, propValue) => {
serializedObj = {};
if (!added.has(obj)) {
added.add(obj);
for (propName in obj) {
if (isValidMemberName(propName)) {
- propValue = obj[propName];
+ propValue = "path" === propName && getConstructorName(obj).endsWith("Event") ? obj.composedPath() : obj[propName];
(includeFunctions || "function" != typeof propValue) && (includeEmptyStrings || "" !== propValue) && (serializedObj[propName] = serializeForWorker(winId, propValue, added));
}
}
@@ -141,6 +145,7 @@
}
return obj;
};
+ const serializedValueIsError = value => value instanceof window.top.Error;
const deserializeFromWorker = (worker, serializedTransfer, serializedType, serializedValue) => {
if (serializedTransfer) {
serializedType = serializedTransfer[0];
@@ -272,44 +277,6 @@
}
return instance;
};
- const registerWindow = (worker, $winId$, $window$) => {
- if (!windowIds.has($window$)) {
- windowIds.set($window$, $winId$);
- const doc = $window$.document;
- const history = $window$.history;
- const $parentWinId$ = windowIds.get($window$.parent);
- const sendInitEnvData = () => worker.postMessage([ 5, {
- $winId$: $winId$,
- $parentWinId$: $parentWinId$,
- $url$: doc.baseURI,
- $visibilityState$: doc.visibilityState
- } ]);
- const pushState = history.pushState.bind(history);
- const replaceState = history.replaceState.bind(history);
- const onLocationChange = () => setTimeout((() => worker.postMessage([ 13, $winId$, doc.baseURI ])));
- history.pushState = (data, _, url) => {
- pushState(data, _, url);
- onLocationChange();
- };
- history.replaceState = (data, _, url) => {
- replaceState(data, _, url);
- onLocationChange();
- };
- $window$.addEventListener("popstate", onLocationChange);
- $window$.addEventListener("hashchange", onLocationChange);
- doc.addEventListener("visibilitychange", (() => worker.postMessage([ 14, $winId$, doc.visibilityState ])));
- winCtxs[$winId$] = {
- $winId$: $winId$,
- $window$: $window$
- };
- winCtxs[$winId$].$startTime$ = performance.now();
- {
- const winType = $winId$ === $parentWinId$ ? "top" : "iframe";
- logMain(`Registered ${winType} window ${normalizedWinId($winId$)}`);
- }
- "complete" === doc.readyState ? sendInitEnvData() : $window$.addEventListener("load", sendInitEnvData);
- }
- };
const readNextScript = (worker, winCtx) => {
let $winId$ = winCtx.$winId$;
let win = winCtx.$window$;
@@ -372,6 +339,75 @@
requestAnimationFrame((() => readNextScript(worker, winCtx)));
}
};
+ const registerWindow = (worker, $winId$, $window$) => {
+ if (!windowIds.has($window$)) {
+ windowIds.set($window$, $winId$);
+ const doc = $window$.document;
+ const history = $window$.history;
+ const $parentWinId$ = windowIds.get($window$.parent);
+ let initialised = false;
+ const onInitialisedQueue = [];
+ const onInitialised = callback => {
+ initialised ? callback() : onInitialisedQueue.push(callback);
+ };
+ const sendInitEnvData = () => {
+ worker.postMessage([ 5, {
+ $winId$: $winId$,
+ $parentWinId$: $parentWinId$,
+ $url$: doc.baseURI,
+ $visibilityState$: doc.visibilityState
+ } ]);
+ setTimeout((() => {
+ initialised = true;
+ onInitialisedQueue.forEach((callback => {
+ callback();
+ }));
+ }));
+ };
+ const pushState = history.pushState.bind(history);
+ const replaceState = history.replaceState.bind(history);
+ const onLocationChange = (type, state, newUrl, oldUrl) => () => {
+ setTimeout((() => {
+ worker.postMessage([ 13, {
+ $winId$: $winId$,
+ type: type,
+ state: state,
+ url: doc.baseURI,
+ newUrl: newUrl,
+ oldUrl: oldUrl
+ } ]);
+ }));
+ };
+ history.pushState = (state, _, newUrl) => {
+ pushState(state, _, newUrl);
+ onInitialised(onLocationChange(0, state, null == newUrl ? void 0 : newUrl.toString()));
+ };
+ history.replaceState = (state, _, newUrl) => {
+ replaceState(state, _, newUrl);
+ onInitialised(onLocationChange(1, state, null == newUrl ? void 0 : newUrl.toString()));
+ };
+ $window$.addEventListener("popstate", (event => {
+ onInitialised(onLocationChange(2, event.state));
+ }));
+ $window$.addEventListener("hashchange", (event => {
+ onInitialised(onLocationChange(3, {}, event.newURL, event.oldURL));
+ }));
+ $window$.addEventListener("ptupdate", (() => {
+ readNextScript(worker, winCtxs[$winId$]);
+ }));
+ doc.addEventListener("visibilitychange", (() => worker.postMessage([ 14, $winId$, doc.visibilityState ])));
+ winCtxs[$winId$] = {
+ $winId$: $winId$,
+ $window$: $window$
+ };
+ winCtxs[$winId$].$startTime$ = performance.now();
+ {
+ const winType = $winId$ === $parentWinId$ ? "top" : "iframe";
+ logMain(`Registered ${winType} window ${normalizedWinId($winId$)}`);
+ }
+ "complete" === doc.readyState ? sendInitEnvData() : $window$.addEventListener("load", sendInitEnvData);
+ }
+ };
const onMessageFromWebWorker = (worker, msg, winCtx) => {
if (4 === msg[0]) {
registerWindow(worker, randomId(), mainWindow);
@@ -508,14 +544,14 @@
}));
})(((accessReq, responseCallback) => mainAccessHandler(worker, accessReq).then(responseCallback))).then((onMessageHandler => {
if (onMessageHandler) {
- worker = new Worker(libPath + "partytown-ww-sw.js?v=0.5.4", {
+ worker = new Worker(libPath + "partytown-ww-sw.js?v=0.7.5", {
name: "Partytown 🎉"
});
worker.onmessage = ev => {
const msg = ev.data;
12 === msg[0] ? mainAccessHandler(worker, msg[1]) : onMessageHandler(worker, msg);
};
- logMain("Created Partytown web worker (0.5.4)");
+ logMain("Created Partytown web worker (0.7.5)");
worker.onerror = ev => console.error("Web Worker Error", ev);
mainWindow.addEventListener("pt1", (ev => registerWindow(worker, getAndSetInstanceId(ev.detail.frameElement), ev.detail)));
}
diff --git a/public/~partytown/debug/partytown-sw.js b/public/~partytown/debug/partytown-sw.js
index 14b09e1..f6fdfb3 100644
--- a/public/~partytown/debug/partytown-sw.js
+++ b/public/~partytown/debug/partytown-sw.js
@@ -1,4 +1,4 @@
-/* Partytown 0.5.4 - MIT builder.io */
+/* Partytown 0.7.5 - MIT builder.io */
const resolves = new Map;
const swMessageError = (accessReq, $error$) => ({
@@ -52,7 +52,7 @@ self.onfetch = ev => {
const url = new URL(req.url);
const pathname = url.pathname;
if (pathname.endsWith("sw.html")) {
- ev.respondWith(response('<!DOCTYPE html><html><head><meta charset="utf-8"><script src="./partytown-sandbox-sw.js?v=0.5.4"><\/script></head></html>'));
+ ev.respondWith(response('<!DOCTYPE html><html><head><meta charset="utf-8"><script src="./partytown-sandbox-sw.js?v=0.7.5"><\/script></head></html>'));
} else {
pathname.endsWith("proxytown") && ev.respondWith(httpRequestFromWebWorker(req));
}
diff --git a/public/~partytown/debug/partytown-ww-atomics.js b/public/~partytown/debug/partytown-ww-atomics.js
index 42e6844..8745785 100644
--- a/public/~partytown/debug/partytown-ww-atomics.js
+++ b/public/~partytown/debug/partytown-ww-atomics.js
@@ -1,4 +1,4 @@
-/* Partytown 0.5.4 - MIT builder.io */
+/* Partytown 0.7.5 - MIT builder.io */
(self => {
const WinIdKey = Symbol();
const InstanceIdKey = Symbol();
@@ -54,6 +54,7 @@
};
const EMPTY_ARRAY = [];
const randomId = () => Math.round(Math.random() * Number.MAX_SAFE_INTEGER).toString(36);
+ const SCRIPT_TYPE = "text/partytown";
const defineProperty = (obj, memberName, descriptor) => Object.defineProperty(obj, memberName, {
...descriptor,
configurable: true
@@ -162,7 +163,7 @@
return deserializeRefFromMain(applyPath, serializedValue);
}
if (6 === serializedType) {
- return noop;
+ return winId && applyPath.length > 0 ? (...args) => callMethod(environments[winId].$window$, applyPath, args, 1) : noop;
}
if (3 === serializedType) {
return getOrCreateSerializedInstance(serializedValue);
@@ -176,6 +177,9 @@
if (1 === serializedType) {
return serializedValue.map((v => deserializeFromMain(winId, instanceId, applyPath, v)));
}
+ if (14 === serializedType) {
+ return new CustomError(serializedValue);
+ }
obj = {};
for (key in serializedValue) {
obj[key] = deserializeFromMain(winId, instanceId, [ ...applyPath, key ], serializedValue[key]);
@@ -213,7 +217,15 @@
}, $refId$);
return webWorkerRefsByRefId[$refId$];
};
- const NodeList = class {
+ class CustomError extends Error {
+ constructor(errorObject) {
+ super(errorObject.message);
+ this.name = errorObject.name;
+ this.message = errorObject.message;
+ this.stack = errorObject.stack;
+ }
+ }
+ class NodeList {
constructor(nodes) {
(this._ = nodes).map(((node, index) => this[index] = node));
}
@@ -238,7 +250,7 @@
[Symbol.iterator]() {
return this._[Symbol.iterator]();
}
- };
+ }
const Attr = class {
constructor(serializedAttr) {
this.name = serializedAttr[0];
@@ -288,7 +300,6 @@
const getTargetProp = (target, applyPath) => {
let n = "";
if (target) {
- target[InstanceIdKey];
const cstrName = getConstructorName(target);
if ("Window" === cstrName) {
n = "";
@@ -528,7 +539,9 @@
name: applyPath.join("."),
continue: HookContinue,
nodeName: instance[InstanceDataKey],
- constructor: getConstructorName(instance)
+ constructor: getConstructorName(instance),
+ instance: instance,
+ window: environments[instance[WinIdKey]].$window$
});
const addStorageApi = (win, storageName, storages, isSameOrigin, env) => {
let getItems = items => {
@@ -566,7 +579,18 @@
return getItems().length;
}
};
- win[storageName] = storage;
+ win[storageName] = new Proxy(storage, {
+ get: (target, key) => Reflect.has(target, key) ? Reflect.get(target, key) : target.getItem(key),
+ set(target, key, value) {
+ target.setItem(key, value);
+ return true;
+ },
+ has: (target, key) => !!Reflect.has(target, key) || "string" == typeof key && null !== target.getItem(key),
+ deleteProperty(target, key) {
+ target.removeItem(key);
+ return true;
+ }
+ });
};
const STORAGE_KEY = 0;
const STORAGE_VALUE = 1;
@@ -681,7 +705,7 @@
};
const run = (env, scriptContent, scriptUrl) => {
env.$runWindowLoadEvent$ = 1;
- scriptContent = `with(this){${(webWorkerCtx.$config$.globalFns || []).filter((globalFnName => /[a-zA-Z_$][0-9a-zA-Z_$]*/.test(globalFnName))).map((g => `(typeof ${g}=='function'&&(window.${g}=${g}))`)).join(";") + scriptContent.replace(/\bthis\b/g, "(thi$(this)?window:this)").replace(/\/\/# so/g, "//Xso")}\n;function thi$(t){return t===this}}` + (scriptUrl ? "\n//# sourceURL=" + scriptUrl : "");
+ scriptContent = `with(this){${scriptContent.replace(/\bthis\b/g, "(thi$(this)?window:this)").replace(/\/\/# so/g, "//Xso")}\n;function thi$(t){return t===this}};${(webWorkerCtx.$config$.globalFns || []).filter((globalFnName => /[a-zA-Z_$][0-9a-zA-Z_$]*/.test(globalFnName))).map((g => `(typeof ${g}=='function'&&(this.${g}=${g}))`)).join(";")};` + (scriptUrl ? "\n//# sourceURL=" + scriptUrl : "");
env.$isSameOrigin$ || (scriptContent = scriptContent.replace(/.postMessage\(/g, `.postMessage('${env.$winId$}',`));
new Function(scriptContent).call(env.$window$);
env.$runWindowLoadEvent$ = 0;
@@ -692,7 +716,7 @@
type: type
})))));
};
- const resolveToUrl = (env, url, noUserHook, baseLocation, resolvedUrl, configResolvedUrl) => {
+ const resolveToUrl = (env, url, type, baseLocation, resolvedUrl, configResolvedUrl) => {
baseLocation = env.$location$;
while (!baseLocation.host) {
env = environments[env.$parentWinId$];
@@ -702,29 +726,32 @@
}
}
resolvedUrl = new URL(url || "", baseLocation);
- if (!noUserHook && webWorkerCtx.$config$.resolveUrl) {
- configResolvedUrl = webWorkerCtx.$config$.resolveUrl(resolvedUrl, baseLocation);
+ if (type && webWorkerCtx.$config$.resolveUrl) {
+ configResolvedUrl = webWorkerCtx.$config$.resolveUrl(resolvedUrl, baseLocation, type);
if (configResolvedUrl) {
return configResolvedUrl;
}
}
return resolvedUrl;
};
- const resolveUrl = (env, url, noUserHook) => resolveToUrl(env, url, noUserHook) + "";
- const getPartytownScript = () => `<script src="${partytownLibUrl("partytown.js?v=0.5.4")}"><\/script>`;
+ const resolveUrl = (env, url, type) => resolveToUrl(env, url, type) + "";
+ const getPartytownScript = () => `<script src="${partytownLibUrl("partytown.js?v=0.7.5")}"><\/script>`;
const createImageConstructor = env => class HTMLImageElement {
constructor() {
this.s = "";
this.l = [];
this.e = [];
+ this.style = {};
}
get src() {
return this.s;
}
set src(src) {
- webWorkerCtx.$config$.logImageRequests && logWorker(`Image() request: ${resolveUrl(env, src)}`, env.$winId$);
- fetch(resolveUrl(env, src, true), {
+ webWorkerCtx.$config$.logImageRequests && logWorker(`Image() request: ${resolveUrl(env, src, "image")}`, env.$winId$);
+ this.s = src;
+ fetch(resolveUrl(env, src, "image"), {
mode: "no-cors",
+ credentials: "include",
keepalive: true
}).then((rsp => {
rsp.ok || 0 === rsp.status ? this.l.map((cb => cb({
@@ -809,11 +836,16 @@
return getInstanceStateValue(this, 4) || "";
},
set(url) {
- const orgUrl = resolveUrl(env, url, true);
- url = resolveUrl(env, url);
+ const orgUrl = resolveUrl(env, url, null);
+ const config = webWorkerCtx.$config$;
+ url = resolveUrl(env, url, "script");
setInstanceStateValue(this, 4, url);
setter(this, [ "src" ], url);
orgUrl !== url && setter(this, [ "dataset", "ptsrc" ], orgUrl);
+ if (this.type && config.loadScriptsOnMainThread) {
+ const shouldExecuteScriptViaMainThread = config.loadScriptsOnMainThread.some((scriptUrl => scriptUrl === url));
+ shouldExecuteScriptViaMainThread && setter(this, [ "type" ], "text/javascript");
+ }
}
},
textContent: innerHTMLDescriptor,
@@ -834,7 +866,8 @@
};
const innerHTMLDescriptor = {
get() {
- return getInstanceStateValue(this, 3) || "";
+ const type = getter(this, [ "type" ]);
+ return isScriptJsType(type) ? getInstanceStateValue(this, 3) || "" : getter(this, [ "innerHTML" ]);
},
set(scriptContent) {
setInstanceStateValue(this, 3, scriptContent);
@@ -842,6 +875,7 @@
};
const isScriptJsType = scriptType => !scriptType || "text/javascript" === scriptType;
const createNodeCstr = (win, env, WorkerBase) => {
+ const config = webWorkerCtx.$config$;
const WorkerNode = defineConstructorName(class extends WorkerBase {
appendChild(node) {
return this.insertBefore(node, null);
@@ -849,6 +883,7 @@
get href() {}
set href(_) {}
insertBefore(newNode, referenceNode) {
+ var _a, _b;
const winId = newNode[WinIdKey] = this[WinIdKey];
const instanceId = newNode[InstanceIdKey];
const nodeName = newNode[InstanceDataKey];
@@ -859,11 +894,17 @@
const scriptType = getInstanceStateValue(newNode, 5);
if (scriptContent) {
if (isScriptJsType(scriptType)) {
- const errorMsg = runScriptContent(env, instanceId, scriptContent, winId, "");
- const datasetType = errorMsg ? "pterror" : "ptid";
- const datasetValue = errorMsg || instanceId;
- setter(newNode, [ "type" ], "text/partytown-x");
- setter(newNode, [ "dataset", datasetType ], datasetValue);
+ const scriptId = newNode.id;
+ const loadOnMainThread = scriptId && (null === (_b = null === (_a = config.loadScriptsOnMainThread) || void 0 === _a ? void 0 : _a.includes) || void 0 === _b ? void 0 : _b.call(_a, scriptId));
+ if (loadOnMainThread) {
+ setter(newNode, [ "type" ], "text/javascript");
+ } else {
+ const errorMsg = runScriptContent(env, instanceId, scriptContent, winId, "");
+ const datasetType = errorMsg ? "pterror" : "ptid";
+ const datasetValue = errorMsg || instanceId;
+ setter(newNode, [ "type" ], "text/partytown-x");
+ setter(newNode, [ "dataset", datasetType ], datasetValue);
+ }
}
setter(newNode, [ "innerHTML" ], scriptContent);
}
@@ -1006,6 +1047,11 @@
head: {
get: () => env.$head$
},
+ images: {
+ get() {
+ return getter(this, [ "images" ]);
+ }
+ },
implementation: {
get() {
return {
@@ -1015,7 +1061,12 @@
callMethod(this, [ "implementation", "createHTMLDocument" ], [ title ], 1, {
$winId$: $winId$
});
- const docEnv = createWindow($winId$, $winId$, env.$location$ + "", "hidden", true, true);
+ const docEnv = createEnvironment({
+ $winId$: $winId$,
+ $parentWinId$: $winId$,
+ $url$: env.$location$ + "",
+ $visibilityState$: "hidden"
+ }, true, true);
return docEnv.$document$;
}
};
@@ -1098,12 +1149,29 @@
setInstanceStateValue(this, 4, href);
value = new URL(href)[anchorProp];
}
- return resolveToUrl(env, value)[anchorProp];
+ return resolveToUrl(env, value, null)[anchorProp];
},
set(value) {
- let href = getInstanceStateValue(this, 4);
- let url = resolveToUrl(env, href);
- url[anchorProp] = new URL(value + "", url.href);
+ let url;
+ if ("href" === anchorProp) {
+ if ((url => {
+ try {
+ new URL(url);
+ return true;
+ } catch (_) {
+ return false;
+ }
+ })(value)) {
+ url = new URL(value);
+ } else {
+ const baseHref = env.$location$.href;
+ url = resolveToUrl(env, baseHref, null);
+ url.href = new URL(value + "", url.href);
+ }
+ } else {
+ url = resolveToUrl(env, this.href, null);
+ url[anchorProp] = value;
+ }
setInstanceStateValue(this, 4, url.href);
setter(this, [ "href" ], url.href);
}
@@ -1140,14 +1208,30 @@
let xhr = new XMLHttpRequest;
let xhrStatus;
let env = getIframeEnv(this);
- env.$location$.href = src = resolveUrl(env, src);
+ env.$location$.href = src = resolveUrl(env, src, "iframe");
env.$isLoading$ = 1;
setInstanceStateValue(this, 1, void 0);
xhr.open("GET", src, false);
xhr.send();
xhrStatus = xhr.status;
if (xhrStatus > 199 && xhrStatus < 300) {
- setter(this, [ "srcdoc" ], `<base href="${src}">` + xhr.responseText.replace(/<script>/g, '<script type="text/partytown">').replace(/<script /g, '<script type="text/partytown" ').replace(/text\/javascript/g, "text/partytown") + getPartytownScript());
+ setter(this, [ "srcdoc" ], `<base href="${src}">` + function(text) {
+ return text.replace(SCRIPT_TAG_REGEXP, ((_, attrs) => {
+ const parts = [];
+ let hasType = false;
+ let match;
+ while (match = ATTR_REGEXP.exec(attrs)) {
+ let [keyValue] = match;
+ if (keyValue.startsWith("type=")) {
+ hasType = true;
+ keyValue = keyValue.replace(/(application|text)\/javascript/, SCRIPT_TYPE);
+ }
+ parts.push(keyValue);
+ }
+ hasType || parts.push('type="text/partytown"');
+ return `<script ${parts.join(" ")}>`;
+ }));
+ }(xhr.responseText) + getPartytownScript());
sendToMain(true);
webWorkerCtx.$postMessage$([ 7, env.$winId$ ]);
} else {
@@ -1162,6 +1246,9 @@
};
definePrototypePropertyDescriptor(WorkerHTMLIFrameElement, HTMLIFrameDescriptorMap);
};
+ const ATTR_REGEXP_STR = "((?:\\w|-)+(?:=(?:(?:\\w|-)+|'[^']*'|\"[^\"]*\")?)?)";
+ const SCRIPT_TAG_REGEXP = new RegExp(`<script\\s*((${ATTR_REGEXP_STR}\\s*)*)>`, "mg");
+ const ATTR_REGEXP = new RegExp(ATTR_REGEXP_STR, "mg");
const