single-file-core 1.5.22 → 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
|
|
136
|
-
|
|
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.
|
|
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.
|
|
1286
|
+
await initializeProcessor(frameData, frameElement, frameWindowId, this.batchRequest, Object.assign({}, this.options));
|
|
1287
1287
|
}
|
|
1288
1288
|
}
|
|
1289
1289
|
}
|
|
@@ -44,6 +44,7 @@ const SINGLE_FILE_VARIABLE_MAX_SIZE = 512 * 1024;
|
|
|
44
44
|
const EMPTY_URL_SOURCE = /^url\(["']?data:[^,]*,?["']?\)/;
|
|
45
45
|
const LOCAL_SOURCE = "local(";
|
|
46
46
|
const FONT_MAX_LOAD_DELAY = 5000;
|
|
47
|
+
const DUPLICATE_STYLESHEET_ATTRIBUTE_NAME = "data-sf-duplicate-stylesheet-ref";
|
|
47
48
|
|
|
48
49
|
let util;
|
|
49
50
|
|
|
@@ -115,6 +116,16 @@ function getProcessorHelperClass(utilInstance) {
|
|
|
115
116
|
const styleSheetRefIndex = options.inlineStylesheetsRefs.get(styleElement);
|
|
116
117
|
if (styleSheetRefIndex === undefined) {
|
|
117
118
|
styleElement.textContent = this.generateStylesheetContent(stylesheetInfo.stylesheet, options);
|
|
119
|
+
} else if (options.groupDuplicateStylesheets) {
|
|
120
|
+
if (!doc.querySelector("style[" + DUPLICATE_STYLESHEET_ATTRIBUTE_NAME + "=\"" + styleSheetRefIndex + "\"]")) {
|
|
121
|
+
const styleElement = doc.createElement("style");
|
|
122
|
+
styleElement.textContent = options.inlineStylesheets.get(styleSheetRefIndex);
|
|
123
|
+
styleElement.setAttribute("media", "not all");
|
|
124
|
+
styleElement.setAttribute(DUPLICATE_STYLESHEET_ATTRIBUTE_NAME, styleSheetRefIndex);
|
|
125
|
+
doc.head.appendChild(styleElement);
|
|
126
|
+
}
|
|
127
|
+
styleElement.textContent = "/* */";
|
|
128
|
+
styleElement.setAttribute("onload", "this.textContent=document.querySelector('style[" + DUPLICATE_STYLESHEET_ATTRIBUTE_NAME + "=\"" + styleSheetRefIndex + "\"]').textContent;this.removeAttribute(\"onload\")");
|
|
118
129
|
} else {
|
|
119
130
|
styleElement.textContent = options.inlineStylesheets.get(styleSheetRefIndex);
|
|
120
131
|
}
|
|
@@ -125,6 +136,11 @@ function getProcessorHelperClass(utilInstance) {
|
|
|
125
136
|
styleElement.remove();
|
|
126
137
|
}
|
|
127
138
|
});
|
|
139
|
+
if (options.groupDuplicateStylesheets) {
|
|
140
|
+
const scriptElement = doc.createElement("script");
|
|
141
|
+
scriptElement.textContent = "document.currentScript.remove();addEventListener(\"load\",()=>document.querySelectorAll(\"style[" + DUPLICATE_STYLESHEET_ATTRIBUTE_NAME + "]\").forEach(e=>e.remove()))";
|
|
142
|
+
doc.body.appendChild(scriptElement);
|
|
143
|
+
}
|
|
128
144
|
doc.querySelectorAll("link[rel*=stylesheet]").forEach(linkElement => {
|
|
129
145
|
const stylesheetInfo = stylesheets.get(linkElement);
|
|
130
146
|
if (stylesheetInfo) {
|
package/package.json
CHANGED
|
@@ -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
|
}
|