roxxie-proxy-u-prod 0.2.2 → 0.2.3

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.
@@ -0,0 +1,26 @@
1
+ import {
2
+ defaultConfig,
3
+ type ScramjetConfig,
4
+ } from "@mercuryworkshop/scramjet/bundled-wasm";
5
+
6
+ /**
7
+ * Configuration shared by the service-worker rewriter and every injected
8
+ * page/worker runtime. Keep this on the production defaults: the development
9
+ * preset deliberately turns parser recovery off and enables debug work that
10
+ * is both noisy and expensive on large production bundles.
11
+ */
12
+ export function makeScramjetConfig(): ScramjetConfig {
13
+ return {
14
+ ...defaultConfig,
15
+ flags: {
16
+ ...defaultConfig.flags,
17
+ allowInvalidJs: true,
18
+ captureErrors: false,
19
+ debugSourceURL: false,
20
+ debugTrampolines: false,
21
+ rewriterLogs: false,
22
+ sourcemaps: false,
23
+ },
24
+ maskedfiles: ["inject.js", "scramjet.wasm.js"],
25
+ };
26
+ }
@@ -1,8 +1,5 @@
1
1
  import {
2
- defaultConfig,
3
- defaultConfigDev,
4
2
  ScramjetFetchHandler,
5
- type ScramjetConfig,
6
3
  type ScramjetFetchRequest,
7
4
  type ScramjetInterface,
8
5
  unrewriteUrl,
@@ -17,21 +14,11 @@ import { RpcHelper } from "@mercuryworkshop/rpc";
17
14
  import scramjetWASM from "../../../scramjet/packages/core/dist/scramjet.wasm?url";
18
15
  import injectScript from "../../../inject/dist/inject.js?url";
19
16
  import { isIsolated } from ".";
17
+ import { makeScramjetConfig } from "./scramjet-config";
20
18
 
21
19
  export const virtualWasmPath = "scramjet.wasm.js";
22
20
  export const virtualInjectPath = "inject.js";
23
21
 
24
- function makeConfig(): ScramjetConfig {
25
- return {
26
- ...defaultConfig,
27
- flags: {
28
- ...defaultConfigDev.flags,
29
- captureErrors: false,
30
- },
31
- maskedfiles: ["inject.js", "scramjet.wasm.js"],
32
- };
33
- }
34
-
35
22
  function base64Encode(str: string): string {
36
23
  return btoa(
37
24
  new Uint8Array(new TextEncoder().encode(str))
@@ -327,7 +314,7 @@ export function renderErrorPage(controller: Controller, error: Error): string {
327
314
  $injectLoadError({
328
315
  id: "${contextId}",
329
316
  sequence: ${JSON.stringify(findSequence(top!, self)!)},
330
- config: ${JSON.stringify(makeConfig())},
317
+ config: ${JSON.stringify(makeScramjetConfig())},
331
318
  cookies: ${JSON.stringify(profileService.cookieJar.dump())},
332
319
  codecEncode: ${codecEncode.toString()},
333
320
  codecDecode: ${codecDecode.toString()},
@@ -361,7 +348,7 @@ export function createFetchHandler(controller: Controller) {
361
348
  $injectLoad({
362
349
  id: "${contextId}",
363
350
  sequence: ${JSON.stringify(findSequence(top!, self)!)},
364
- config: ${JSON.stringify(makeConfig())},
351
+ config: ${JSON.stringify(makeScramjetConfig())},
365
352
  cookies: ${JSON.stringify(profileService.cookieJar.dump())},
366
353
  codecEncode: ${codecEncode.toString()},
367
354
  codecDecode: ${codecDecode.toString()},
@@ -391,7 +378,7 @@ export function createFetchHandler(controller: Controller) {
391
378
  // workers don't have a document, so initHeaders/history are empty.
392
379
  const injectLoad = `
393
380
  $injectLoad({
394
- config: ${JSON.stringify(makeConfig())},
381
+ config: ${JSON.stringify(makeScramjetConfig())},
395
382
  cookies: null,
396
383
  codecEncode: ${codecEncode.toString()},
397
384
  codecDecode: ${codecDecode.toString()},
@@ -419,7 +406,7 @@ export function createFetchHandler(controller: Controller) {
419
406
  codecDecode,
420
407
  },
421
408
  cookieJar: profileService.cookieJar,
422
- config: makeConfig(),
409
+ config: makeScramjetConfig(),
423
410
  prefix: controller.prefix,
424
411
  },
425
412
  async fetchDataUrl(dataUrl: string) {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "roxxie-transports",
3
- "version": "6.0.1",
3
+ "version": "6.0.2",
4
4
  "description": "Tracker-discovered WebRTC transport for Roxxie Proxy U",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -534,7 +534,10 @@ export class RoxxieConnection {
534
534
  else if (this.sockets.has(frame.sequence)) {
535
535
  this.handleSocketFrame(frame.sequence, frame.operation, frame.payload);
536
536
  } else if (this.ignoredHTTP.has(frame.sequence)) {
537
- if (frame.operation === S2CRequestTypes.HTTPResponseEnd) {
537
+ if (
538
+ frame.operation === S2CRequestTypes.HTTPResponseEnd ||
539
+ frame.operation === S2CRequestTypes.HTTPResponseError
540
+ ) {
538
541
  this.ignoredHTTP.delete(frame.sequence);
539
542
  } else if (
540
543
  frame.operation !== S2CRequestTypes.HTTPResponseStart &&
@@ -618,6 +621,20 @@ export class RoxxieConnection {
618
621
  pending.removeAbort?.();
619
622
  this.http.delete(sequence);
620
623
  break;
624
+ case S2CRequestTypes.HTTPResponseError:
625
+ if (!pending.responseStarted || pending.controller === undefined) {
626
+ throw new Error("Node failed HTTP response before response headers");
627
+ }
628
+ // The node could not deliver the whole body. Erroring the stream
629
+ // keeps the partial bytes from being parsed or cached as if they
630
+ // were a complete response. Only this request is affected, so the
631
+ // session stays up.
632
+ pending.controller.error(
633
+ new Error("Proxy node could not deliver the complete response body")
634
+ );
635
+ pending.removeAbort?.();
636
+ this.http.delete(sequence);
637
+ break;
621
638
  default:
622
639
  throw new Error(`Node sent invalid HTTP operation ${operation}`);
623
640
  }
@@ -151,6 +151,13 @@ export async function doHandleFetch(
151
151
  if (response.body && !isRedirect(response)) {
152
152
  responseBody = await rewriteBody(handler, request, parsed, response);
153
153
 
154
+ // The service worker constructs a new Response around this body. HTML,
155
+ // JavaScript, CSS, and worker rewrites change its byte length, while even
156
+ // pass-through streams are no longer the native network response that
157
+ // supplied Content-Length. Firefox treats a mismatched retained length as
158
+ // corrupted content and can truncate modules/documents at that boundary.
159
+ responseHeaders.delete("content-length");
160
+
154
161
  // After rewriting HTML, the body is a JS string which will be encoded as
155
162
  // UTF-8 by the Response constructor. Normalize the Content-Type charset so
156
163
  // the browser doesn't try to decode UTF-8 bytes with the original encoding.
@@ -146,8 +146,7 @@ export function rewriteJs(
146
146
  dbg.warn(
147
147
  "failed rewriting js for",
148
148
  url || "(unknown)",
149
- err.message,
150
- typeof js !== "string" ? TextDecoder_decode(js) : js
149
+ err.message
151
150
  );
152
151
  if (flagEnabled("allowInvalidJs", context, meta.base)) {
153
152
  return js;
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "roxxie-transports-tracker-protocol",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "Browser-safe control-plane contracts for the Roxxie tracker, nodes, and browsers",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -18,7 +18,7 @@
18
18
  "test": "npm run build && node --test dist/test/*.test.js"
19
19
  },
20
20
  "engines": {
21
- "node": ">=20"
21
+ "node": ">=18"
22
22
  },
23
23
  "publishConfig": {
24
24
  "access": "public"
@@ -338,10 +338,10 @@ importers:
338
338
  specifier: 2.4.0
339
339
  version: 2.4.0
340
340
  roxxie-transports-adrift-protocol:
341
- specifier: 6.0.0
341
+ specifier: 6.0.1
342
342
  version: link:../adrift-protocol
343
343
  roxxie-transports-tracker-protocol:
344
- specifier: 1.2.0
344
+ specifier: 1.2.1
345
345
  version: link:../tracker-protocol
346
346
  ws:
347
347
  specifier: 8.21.1
package/standalone.html CHANGED
@@ -18,8 +18,8 @@
18
18
  <div id="roxxie-browser"></div>
19
19
  <script
20
20
  defer
21
- src="https://cdn.jsdelivr.net/npm/roxxie-proxy-u-prod@0.2.2/embed.js"
22
- integrity="sha384-3QVF5CQiWk0SKqCDSEAoupN0KXK0bxo9qaZeS5Tj8/8mO8J719dv+fvmrqmdthH2"
21
+ src="https://cdn.jsdelivr.net/npm/roxxie-proxy-u-prod@0.2.3/embed.js"
22
+ integrity="sha384-yu0TlvCJ9LcKoOG66anQWT/iHEz3uC7rUGLmaDZV9otcFcWsQ6EvX8y2GPuxFsOH"
23
23
  crossorigin="anonymous"
24
24
  data-roxxie-target="#roxxie-browser"
25
25
  ></script>