dsh-unlag 1.7.6 → 1.7.7

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.
Files changed (2) hide show
  1. package/client.js +21 -0
  2. package/package.json +1 -1
package/client.js CHANGED
@@ -115,6 +115,7 @@ window.__ModuleLoader__.load({
115
115
  for (const id of source.ids) {
116
116
  if (!body.includes(id)) return false;
117
117
  }
118
+ if (!parsesAsClassicScript(body)) return false;
118
119
  } catch {
119
120
  return false;
120
121
  }
@@ -125,6 +126,25 @@ window.__ModuleLoader__.load({
125
126
  // Every row kind a document boot understands; an unknown one ends the document.
126
127
  const STARTUP_ROW_KINDS = new Set(['global', 'script', 'script-src', 'script-preload', 'style', 'html']);
127
128
 
129
+ /**
130
+ * Whether a script body parses the way the document will parse it: as a classic script. A body
131
+ * that needs module syntax never runs, so the document that loads it fails to boot and the
132
+ * desktop shell ends. Compiling runs nothing, so nothing here has a side effect; a page that
133
+ * forbids compiling strings cannot answer, and then the checks already done stand.
134
+ * @param body - the served script.
135
+ * @returns true when the body parses, or when this page cannot compile one at all.
136
+ */
137
+ function parsesAsClassicScript(body) {
138
+ try {
139
+ new Function(body); // eslint-disable-line no-new-func
140
+ return true;
141
+ } catch (error) {
142
+ const text = String(error?.message ?? error);
143
+ if (/unsafe-eval|Content Security Policy/iu.test(text)) return true;
144
+ return false;
145
+ }
146
+ }
147
+
128
148
  /**
129
149
  * The startup list the desktop shell hands the next document, exactly as it hands it. The
130
150
  * shell reads that list once when the app starts and replays the same copy for every document
@@ -195,6 +215,7 @@ window.__ModuleLoader__.load({
195
215
  for (const id of bundledIds(target)) {
196
216
  if (!body.includes(id)) return false;
197
217
  }
218
+ if (!parsesAsClassicScript(body)) return false;
198
219
  } catch {
199
220
  return false;
200
221
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-unlag",
3
- "version": "1.7.6",
3
+ "version": "1.7.7",
4
4
  "type": "module",
5
5
  "description": "One press applies plugin edits right away and brings a laggy interface back; running turns, queued messages and unsent input are untouched, and nothing restarts.",
6
6
  "license": "MIT",