From e8191187a1b8954b2b9fc6f1ecc7adb5e53bbba0 Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Thu, 6 Aug 2020 15:30:54 +0000 Subject: [PATCH] fix(core): update --- ts/smartssr.classes.smartssr.ts | 55 ++++++++++++++++--------------- ts/smartssr.function.serialize.ts | 3 -- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/ts/smartssr.classes.smartssr.ts b/ts/smartssr.classes.smartssr.ts index 1976c0a..79314a3 100644 --- a/ts/smartssr.classes.smartssr.ts +++ b/ts/smartssr.classes.smartssr.ts @@ -46,34 +46,26 @@ export class SmartSSR { console.log(`${urlArg}: ${msg.text()}`); }); - page.on('load', async (...args) => { - await plugins.smartdelay.delayFor(5000); - let screenshotBuffer: Buffer; - - if (this.options.debug) { - screenshotBuffer = await page.screenshot({ - encoding: 'binary', - }); - } - - await page.$eval('body', serializeFunction); - const pageContent = await page.content(); - const renderedPageString = pageContent; - resultDeferred.resolve(renderedPageString); - - if (this.options.debug) { - plugins.smartfile.memory.toFsSync( - renderedPageString, - plugins.path.join(paths.noGitDir, 'test.html') - ); - const fs = await import('fs'); - fs.writeFileSync(plugins.path.join(paths.noGitDir, 'test.png'), screenshotBuffer); - } - }); - const renderTimeMeasurement = new plugins.smarttime.HrtMeasurement(); renderTimeMeasurement.start(); - await page.goto(urlArg); + await page.goto(urlArg, { + waitUntil: 'networkidle2', + }); + + let screenshotBuffer: Buffer; + + if (this.options.debug) { + screenshotBuffer = await page.screenshot({ + encoding: 'binary', + }); + } + + await page.$eval('body', serializeFunction); + const pageContent = await page.content(); + const renderedPageString = pageContent; + resultDeferred.resolve(renderedPageString); + + const result = await resultDeferred.promise; renderTimeMeasurement.stop(); @@ -87,6 +79,17 @@ export class SmartSSR { console.log( `The rendering alone took ${renderTimeMeasurement.milliSeconds} milliseconds for ${urlArg}` ); + + // debug + if (this.options.debug) { + plugins.smartfile.memory.toFsSync( + renderedPageString, + plugins.path.join(paths.noGitDir, 'test.html') + ); + const fs = await import('fs'); + fs.writeFileSync(plugins.path.join(paths.noGitDir, 'test.png'), screenshotBuffer); + } + return result; } } diff --git a/ts/smartssr.function.serialize.ts b/ts/smartssr.function.serialize.ts index 0f8cc6b..968bec7 100644 --- a/ts/smartssr.function.serialize.ts +++ b/ts/smartssr.function.serialize.ts @@ -56,9 +56,6 @@ export function serializeFunction(rootNode) { if (childNode.tagName === 'STYLE') { childNode.textContent = prependCss(nodeUUID, childNode.textContent); } else { - if (nodeArg.tagName?.includes('ARTICLEGRID')) { - console.log('hello ' + childNode.id); - } serializeNode(childNode, logThis); } noteForAppending.push(childNode);