single-file-core 1.5.23 → 1.5.24

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/core/helper.js CHANGED
@@ -131,12 +131,31 @@ export {
131
131
  };
132
132
 
133
133
  function initUserScriptHandler() {
134
- addEventListener(ON_INIT_USERSCRIPT_EVENT, () => globalThis[WAIT_FOR_USERSCRIPT_PROPERTY_NAME] = async eventPrefixName => {
135
- const event = new CustomEvent(eventPrefixName + "-request", { cancelable: true });
136
- const promiseResponse = new Promise(resolve => addEventListener(eventPrefixName + "-response", resolve));
134
+ addEventListener(ON_INIT_USERSCRIPT_EVENT, () => globalThis[WAIT_FOR_USERSCRIPT_PROPERTY_NAME] = async (eventPrefixName, options) => {
135
+ const userScriptOptions = Object.assign({}, options);
136
+ delete userScriptOptions.win;
137
+ delete userScriptOptions.doc;
138
+ delete userScriptOptions.onprogress;
139
+ delete userScriptOptions.frames;
140
+ delete userScriptOptions.taskId;
141
+ delete userScriptOptions._migratedTemplateFormat;
142
+ delete userScriptOptions.woleetKey;
143
+ const event = new CustomEvent(eventPrefixName + "-request", { cancelable: true, detail: { options: userScriptOptions } });
144
+ let resolvePromiseResponse;
145
+ const promiseResponse = new Promise(resolve => {
146
+ resolvePromiseResponse = resolve;
147
+ addEventListener(eventPrefixName + "-response", event => {
148
+ if (event.detail && event.detail.options) {
149
+ Object.assign(options, event.detail.options);
150
+ }
151
+ resolve();
152
+ });
153
+ });
137
154
  dispatchEvent(event);
138
155
  if (event.defaultPrevented) {
139
156
  await promiseResponse;
157
+ } else {
158
+ resolvePromiseResponse();
140
159
  }
141
160
  });
142
161
  new MutationObserver(initUserScriptHandler).observe(globalThis.document, { childList: true });
package/core/index.js CHANGED
@@ -54,13 +54,13 @@ class SingleFileClass {
54
54
  async run() {
55
55
  const waitForUserScript = globalThis[util.WAIT_FOR_USERSCRIPT_PROPERTY_NAME];
56
56
  if (this.options.userScriptEnabled && waitForUserScript) {
57
- await waitForUserScript(util.ON_BEFORE_CAPTURE_EVENT_NAME);
57
+ await waitForUserScript(util.ON_BEFORE_CAPTURE_EVENT_NAME, this.options);
58
58
  }
59
59
  this.runner = new Runner(this.options, this.processorHelper, true);
60
60
  await this.runner.loadPage();
61
61
  await this.runner.initialize();
62
62
  if (this.options.userScriptEnabled && waitForUserScript) {
63
- await waitForUserScript(util.ON_AFTER_CAPTURE_EVENT_NAME);
63
+ await waitForUserScript(util.ON_AFTER_CAPTURE_EVENT_NAME, this.options);
64
64
  }
65
65
  await this.runner.run();
66
66
  }
@@ -1277,13 +1277,13 @@ class Processor {
1277
1277
  this.options.frames.push(frameData);
1278
1278
  frameData.windowId = (this.options.windowId || "0") + "." + this.options.frames.length;
1279
1279
  frameElement.setAttribute(util.WIN_ID_ATTRIBUTE_NAME, frameData.windowId);
1280
- await initializeProcessor(frameData, frameElement, null, this.batchRequest, Object.create(this.options));
1280
+ await initializeProcessor(frameData, frameElement, null, this.batchRequest, Object.assign({}, this.options));
1281
1281
  } else {
1282
1282
  const frameWindowId = frameElement.getAttribute(util.WIN_ID_ATTRIBUTE_NAME);
1283
1283
  if (this.options.frames && frameWindowId) {
1284
1284
  const frameData = this.options.frames.find(frame => frame.windowId == frameWindowId);
1285
1285
  if (frameData && frameData.content) {
1286
- await initializeProcessor(frameData, frameElement, frameWindowId, this.batchRequest, Object.create(this.options));
1286
+ await initializeProcessor(frameData, frameElement, frameWindowId, this.batchRequest, Object.assign({}, this.options));
1287
1287
  }
1288
1288
  }
1289
1289
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "single-file-core",
3
- "version": "1.5.23",
3
+ "version": "1.5.24",
4
4
  "description": "SingleFile Core",
5
5
  "author": "Gildas Lormeau",
6
6
  "license": "AGPL-3.0-or-later",
@@ -179,11 +179,11 @@ function initRequestSync(message) {
179
179
  processFrames(document, message.options, windowId, sessionId);
180
180
  if (!TOP_WINDOW) {
181
181
  if (message.options.userScriptEnabled && waitForUserScript) {
182
- waitForUserScript(helper.ON_BEFORE_CAPTURE_EVENT_NAME);
182
+ waitForUserScript(helper.ON_BEFORE_CAPTURE_EVENT_NAME, message.options);
183
183
  }
184
184
  sendInitResponse({ frames: [getFrameData(document, globalThis, windowId, message.options, message.scrolling)], sessionId, requestedFrameId: document.documentElement.dataset.requestedFrameId && windowId });
185
185
  if (message.options.userScriptEnabled && waitForUserScript) {
186
- waitForUserScript(helper.ON_AFTER_CAPTURE_EVENT_NAME);
186
+ waitForUserScript(helper.ON_AFTER_CAPTURE_EVENT_NAME, message.options);
187
187
  }
188
188
  delete document.documentElement.dataset.requestedFrameId;
189
189
  }
@@ -199,11 +199,11 @@ async function initRequestAsync(message) {
199
199
  processFrames(document, message.options, windowId, sessionId);
200
200
  if (!TOP_WINDOW) {
201
201
  if (message.options.userScriptEnabled && waitForUserScript) {
202
- await waitForUserScript(helper.ON_BEFORE_CAPTURE_EVENT_NAME);
202
+ await waitForUserScript(helper.ON_BEFORE_CAPTURE_EVENT_NAME, message.options);
203
203
  }
204
204
  sendInitResponse({ frames: [getFrameData(document, globalThis, windowId, message.options, message.scrolling)], sessionId, requestedFrameId: document.documentElement.dataset.requestedFrameId && windowId });
205
205
  if (message.options.userScriptEnabled && waitForUserScript) {
206
- await waitForUserScript(helper.ON_AFTER_CAPTURE_EVENT_NAME);
206
+ await waitForUserScript(helper.ON_AFTER_CAPTURE_EVENT_NAME, message.options);
207
207
  }
208
208
  delete document.documentElement.dataset.requestedFrameId;
209
209
  }