|
|
@@ -43,7 +43,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
}
|
|
|
}
|
|
|
async initialize() {
|
|
|
- this.processor = new PageProcessor(this.options);
|
|
|
+ this.processor = new PageProcessor(this.options, true);
|
|
|
await this.processor.loadPage();
|
|
|
await this.processor.initialize();
|
|
|
}
|
|
|
@@ -73,8 +73,8 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
const STAGE_TASK_ENDED = "stage-task-ended";
|
|
|
|
|
|
class ProgressEvent {
|
|
|
- constructor(type, details) {
|
|
|
- return { type, details, PAGE_LOADING, PAGE_LOADED, RESOURCES_INITIALIZING, RESOURCES_INITIALIZED, RESOURCE_LOADED, PAGE_ENDED };
|
|
|
+ constructor(type, detail) {
|
|
|
+ return { type, detail, PAGE_LOADING, PAGE_LOADED, RESOURCES_INITIALIZING, RESOURCES_INITIALIZED, RESOURCE_LOADED, PAGE_ENDED, STAGE_STARTED, STAGE_ENDED, STAGE_TASK_STARTED, STAGE_TASK_ENDED };
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -141,7 +141,8 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
}];
|
|
|
|
|
|
class PageProcessor {
|
|
|
- constructor(options) {
|
|
|
+ constructor(options, root) {
|
|
|
+ this.root = root;
|
|
|
this.options = options;
|
|
|
this.options.url = this.options.url || this.options.doc.location.href;
|
|
|
this.options.baseURI = this.options.doc && this.options.doc.baseURI;
|
|
|
@@ -162,9 +163,9 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
}
|
|
|
|
|
|
async loadPage() {
|
|
|
- this.onprogress(new ProgressEvent(PAGE_LOADING, { pageURL: this.options.url }));
|
|
|
+ this.onprogress(new ProgressEvent(PAGE_LOADING, { pageURL: this.options.url, frame: !this.root }));
|
|
|
await this.processor.loadPage(this.options.content);
|
|
|
- this.onprogress(new ProgressEvent(PAGE_LOADED, { pageURL: this.options.url }));
|
|
|
+ this.onprogress(new ProgressEvent(PAGE_LOADED, { pageURL: this.options.url, frame: !this.root }));
|
|
|
}
|
|
|
|
|
|
async initialize() {
|
|
|
@@ -179,13 +180,13 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
}
|
|
|
|
|
|
async run() {
|
|
|
- if (!this.options.windowId) {
|
|
|
+ if (this.root) {
|
|
|
this.processor.initialize(this.batchRequest);
|
|
|
this.onprogress(new ProgressEvent(RESOURCES_INITIALIZED, { pageURL: this.options.url, index: 0, max: this.processor.maxResources }));
|
|
|
}
|
|
|
- await this.batchRequest.run(details => {
|
|
|
- details.pageURL = this.options.url;
|
|
|
- this.onprogress(new ProgressEvent(RESOURCE_LOADED, details));
|
|
|
+ await this.batchRequest.run(detail => {
|
|
|
+ detail.pageURL = this.options.url;
|
|
|
+ this.onprogress(new ProgressEvent(RESOURCE_LOADED, detail));
|
|
|
}, this.options);
|
|
|
await this.pendingPromises;
|
|
|
await this.executeStage(REPLACE_DOCS_STAGE);
|
|
|
@@ -194,7 +195,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
}
|
|
|
|
|
|
async getPageData() {
|
|
|
- if (!this.options.windowId) {
|
|
|
+ if (this.root) {
|
|
|
this.onprogress(new ProgressEvent(PAGE_ENDED, { pageURL: this.options.url }));
|
|
|
}
|
|
|
return this.processor.getPageData();
|
|
|
@@ -204,16 +205,17 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
if (DEBUG) {
|
|
|
log("**** STARTED STAGE", step, "****");
|
|
|
}
|
|
|
- this.onprogress(new ProgressEvent(STAGE_STARTED, { pageURL: this.options.url, step }));
|
|
|
+ const frame = !this.root;
|
|
|
+ this.onprogress(new ProgressEvent(STAGE_STARTED, { pageURL: this.options.url, step, frame }));
|
|
|
STAGES[step].sequential.forEach(task => {
|
|
|
let startTime;
|
|
|
if (DEBUG) {
|
|
|
startTime = Date.now();
|
|
|
log(" -- STARTED task =", task.action);
|
|
|
}
|
|
|
- this.onprogress(new ProgressEvent(STAGE_TASK_STARTED, { pageURL: this.options.url, task: task.action }));
|
|
|
+ this.onprogress(new ProgressEvent(STAGE_TASK_STARTED, { pageURL: this.options.url, step, task: task.action, frame }));
|
|
|
this.executeTask(task);
|
|
|
- this.onprogress(new ProgressEvent(STAGE_TASK_ENDED, { pageURL: this.options.url, step, task: task.action }));
|
|
|
+ this.onprogress(new ProgressEvent(STAGE_TASK_ENDED, { pageURL: this.options.url, step, task: task.action, frame }));
|
|
|
if (DEBUG) {
|
|
|
log(" -- ENDED task =", task.action, "delay =", Date.now() - startTime);
|
|
|
}
|
|
|
@@ -225,16 +227,16 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
startTime = Date.now();
|
|
|
log(" // STARTED task =", task.action);
|
|
|
}
|
|
|
- this.onprogress(new ProgressEvent(STAGE_TASK_STARTED, { pageURL: this.options.url, task: task.action }));
|
|
|
+ this.onprogress(new ProgressEvent(STAGE_TASK_STARTED, { pageURL: this.options.url, step, task: task.action, frame }));
|
|
|
const promise = this.executeTask(task);
|
|
|
- promise.then(() => this.onprogress(new ProgressEvent(STAGE_TASK_ENDED, { pageURL: this.options.url, step, task: task.action })));
|
|
|
+ promise.then(() => this.onprogress(new ProgressEvent(STAGE_TASK_ENDED, { pageURL: this.options.url, step, task: task.action, frame })));
|
|
|
if (DEBUG) {
|
|
|
promise.then(() => log(" // ENDED task =", task.action, "delay =", Date.now() - startTime));
|
|
|
}
|
|
|
return promise;
|
|
|
}));
|
|
|
}
|
|
|
- this.onprogress(new ProgressEvent(STAGE_ENDED, { pageURL: this.options.url, step }));
|
|
|
+ this.onprogress(new ProgressEvent(STAGE_ENDED, { pageURL: this.options.url, step, frame }));
|
|
|
if (DEBUG) {
|
|
|
log("**** ENDED STAGE", step, "****");
|
|
|
}
|