@mentra/jspolyfill 3.3.0 → 3.4.0-beta.1241
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/assets/startup.js +16 -0
- package/dist/startup.js +16 -0
- package/package.json +1 -1
- package/src/startup.ts +22 -0
package/assets/startup.js
CHANGED
|
@@ -668,10 +668,20 @@
|
|
|
668
668
|
return out;
|
|
669
669
|
};
|
|
670
670
|
}
|
|
671
|
+
const urlScheme = (url) => {
|
|
672
|
+
const match = /^[\u0000- ]*([A-Za-z][A-Za-z0-9+.-]*):/.exec(url);
|
|
673
|
+
return match ? match[1].toLowerCase() : null;
|
|
674
|
+
};
|
|
671
675
|
if (typeof g.fetch !== "function") {
|
|
672
676
|
;
|
|
673
677
|
g.fetch = async (input, init) => {
|
|
674
678
|
const url = typeof input === "string" ? input : input.toString();
|
|
679
|
+
const scheme = urlScheme(url);
|
|
680
|
+
if (scheme !== "http" && scheme !== "https") {
|
|
681
|
+
throw new TypeError(
|
|
682
|
+
`fetch: only http: and https: URLs can be fetched, not ${scheme ? `${scheme}:` : "a relative URL"}`
|
|
683
|
+
);
|
|
684
|
+
}
|
|
675
685
|
const method = (init?.method ?? "GET").toUpperCase();
|
|
676
686
|
let bodyString = null;
|
|
677
687
|
let bodyBase64;
|
|
@@ -782,6 +792,12 @@
|
|
|
782
792
|
close: /* @__PURE__ */ new Set()
|
|
783
793
|
};
|
|
784
794
|
this.url = String(url);
|
|
795
|
+
const scheme = urlScheme(this.url);
|
|
796
|
+
if (scheme !== "ws" && scheme !== "wss" && scheme !== "http" && scheme !== "https") {
|
|
797
|
+
throw new SyntaxError(
|
|
798
|
+
`WebSocket: the URL's scheme must be ws:, wss:, http: or https:, not ${scheme ? `${scheme}:` : "none"}`
|
|
799
|
+
);
|
|
800
|
+
}
|
|
785
801
|
const protoList = Array.isArray(protocols) ? protocols : protocols ? [protocols] : [];
|
|
786
802
|
this.sid = `ws-${Date.now()}-${Math.floor(Math.random() * 1e9)}`;
|
|
787
803
|
sockets.set(this.sid, this);
|
package/dist/startup.js
CHANGED
|
@@ -668,10 +668,20 @@
|
|
|
668
668
|
return out;
|
|
669
669
|
};
|
|
670
670
|
}
|
|
671
|
+
const urlScheme = (url) => {
|
|
672
|
+
const match = /^[\u0000- ]*([A-Za-z][A-Za-z0-9+.-]*):/.exec(url);
|
|
673
|
+
return match ? match[1].toLowerCase() : null;
|
|
674
|
+
};
|
|
671
675
|
if (typeof g.fetch !== "function") {
|
|
672
676
|
;
|
|
673
677
|
g.fetch = async (input, init) => {
|
|
674
678
|
const url = typeof input === "string" ? input : input.toString();
|
|
679
|
+
const scheme = urlScheme(url);
|
|
680
|
+
if (scheme !== "http" && scheme !== "https") {
|
|
681
|
+
throw new TypeError(
|
|
682
|
+
`fetch: only http: and https: URLs can be fetched, not ${scheme ? `${scheme}:` : "a relative URL"}`
|
|
683
|
+
);
|
|
684
|
+
}
|
|
675
685
|
const method = (init?.method ?? "GET").toUpperCase();
|
|
676
686
|
let bodyString = null;
|
|
677
687
|
let bodyBase64;
|
|
@@ -782,6 +792,12 @@
|
|
|
782
792
|
close: /* @__PURE__ */ new Set()
|
|
783
793
|
};
|
|
784
794
|
this.url = String(url);
|
|
795
|
+
const scheme = urlScheme(this.url);
|
|
796
|
+
if (scheme !== "ws" && scheme !== "wss" && scheme !== "http" && scheme !== "https") {
|
|
797
|
+
throw new SyntaxError(
|
|
798
|
+
`WebSocket: the URL's scheme must be ws:, wss:, http: or https:, not ${scheme ? `${scheme}:` : "none"}`
|
|
799
|
+
);
|
|
800
|
+
}
|
|
785
801
|
const protoList = Array.isArray(protocols) ? protocols : protocols ? [protocols] : [];
|
|
786
802
|
this.sid = `ws-${Date.now()}-${Math.floor(Math.random() * 1e9)}`;
|
|
787
803
|
sockets.set(this.sid, this);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mentra/jspolyfill",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0-beta.1241",
|
|
4
4
|
"description": "MentraJS polyfill bundle — installed into each per-miniapp JSContext (iOS-JSC, Android-QuickJS) at spawn time. Provides browser-like globals (console, timers, fetch, WebSocket, localStorage, crypto.subtle) over a single __dispatch native bridge, plus the __deliver / signalReady plumbing the host runtime relies on.",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"types": "src/index.ts",
|
package/src/startup.ts
CHANGED
|
@@ -877,9 +877,24 @@ declare const __nativeClearTimer: (token: number) => void
|
|
|
877
877
|
// responds with bodyBase64 whenever the bytes are not exactly UTF-8 text.
|
|
878
878
|
// Either way arrayBuffer() is exact and text() follows the Fetch
|
|
879
879
|
// Standard's UTF-8 decode.
|
|
880
|
+
//
|
|
881
|
+
// Only http: and https: URLs are fetched. Miniapp code is untrusted, and a
|
|
882
|
+
// file: URL would read the Mentra App's own files. Native refuses them too;
|
|
883
|
+
// this check gives the browser's TypeError instead of a bridge error.
|
|
884
|
+
// Leading C0 controls and spaces are skipped, as a URL parser does.
|
|
885
|
+
const urlScheme = (url: string): string | null => {
|
|
886
|
+
const match = /^[\u0000- ]*([A-Za-z][A-Za-z0-9+.-]*):/.exec(url)
|
|
887
|
+
return match ? match[1].toLowerCase() : null
|
|
888
|
+
}
|
|
880
889
|
if (typeof (g as Record<string, unknown>).fetch !== "function") {
|
|
881
890
|
;(g as Record<string, unknown>).fetch = async (input: string | URL, init?: RequestInit) => {
|
|
882
891
|
const url = typeof input === "string" ? input : input.toString()
|
|
892
|
+
const scheme = urlScheme(url)
|
|
893
|
+
if (scheme !== "http" && scheme !== "https") {
|
|
894
|
+
throw new TypeError(
|
|
895
|
+
`fetch: only http: and https: URLs can be fetched, not ${scheme ? `${scheme}:` : "a relative URL"}`,
|
|
896
|
+
)
|
|
897
|
+
}
|
|
883
898
|
const method = (init?.method ?? "GET").toUpperCase()
|
|
884
899
|
let bodyString: string | null = null
|
|
885
900
|
let bodyBase64: string | undefined
|
|
@@ -1032,6 +1047,13 @@ declare const __nativeClearTimer: (token: number) => void
|
|
|
1032
1047
|
|
|
1033
1048
|
constructor(url: string, protocols?: string | string[]) {
|
|
1034
1049
|
this.url = String(url)
|
|
1050
|
+
// As in a browser, a URL that is not a network address throws here.
|
|
1051
|
+
const scheme = urlScheme(this.url)
|
|
1052
|
+
if (scheme !== "ws" && scheme !== "wss" && scheme !== "http" && scheme !== "https") {
|
|
1053
|
+
throw new SyntaxError(
|
|
1054
|
+
`WebSocket: the URL's scheme must be ws:, wss:, http: or https:, not ${scheme ? `${scheme}:` : "none"}`,
|
|
1055
|
+
)
|
|
1056
|
+
}
|
|
1035
1057
|
const protoList = Array.isArray(protocols) ? protocols : protocols ? [protocols] : []
|
|
1036
1058
|
// Allocate a session id JS-side so the dispatcher's response is a
|
|
1037
1059
|
// simple ack rather than carrying the sid we then have to wait for.
|