fix(core): update

This commit is contained in:
Philipp Kunz 2021-08-16 16:26:13 +02:00
parent 90089357cf
commit c0a425e16d
4 changed files with 52 additions and 43 deletions

View File

@ -36,7 +36,6 @@ auditProductionDependencies:
- npmci command npm audit --audit-level=high --only=prod --production
tags:
- docker
allow_failure: true
auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci

View File

@ -27,33 +27,39 @@ export class SmartSSR {
overallTimeMeasurement.start();
const resultDeferred = plugins.smartpromise.defer<string>();
const browser = new plugins.smartpuppeteer.IncognitoBrowser();
const renderTimeMeasurement = new plugins.smarttime.HrtMeasurement();
let renderedPageString: string;
let screenshotBuffer: Buffer;
await browser.start();
try {
const context = await browser.getNewIncognitoContext();
const page = await context.newPage();
// lets protext against left open tabs
plugins.smartdelay.delayFor(30000).then(() => {
// lets protect against left open tabs
plugins.smartdelay.delayFor(30000).then(async () => {
if (!page.isClosed) {
page.close();
context.close();
try {
await page.close();
await context.close();
} catch (e) {
console.log(e);
} finally {
await browser.stop();
}
throw new Error(`failed to render ${urlArg}`);
}
});
page.on('console', (msg) => {
console.log(`${urlArg}: ${msg.text()}`);
});
const renderTimeMeasurement = new plugins.smarttime.HrtMeasurement();
renderTimeMeasurement.start();
await page.goto(urlArg, {
waitUntil: 'networkidle2',
timeout: 30000,
});
let screenshotBuffer: Buffer;
if (this.options.debug) {
screenshotBuffer = await page.screenshot({
encoding: 'binary',
@ -62,15 +68,16 @@ export class SmartSSR {
await page.$eval('body', serializeFunction);
const pageContent = await page.content();
const renderedPageString = pageContent;
renderedPageString = pageContent;
resultDeferred.resolve(renderedPageString);
const result = await resultDeferred.promise;
renderTimeMeasurement.stop();
// lets clean up async
await page.close();
await context.close();
} catch (e) {
console.log(e);
}
await browser.stop();
overallTimeMeasurement.stop();
@ -91,6 +98,6 @@ export class SmartSSR {
fs.writeFileSync(plugins.path.join(paths.noGitDir, 'test.png'), screenshotBuffer);
}
return result;
return resultDeferred.promise;
}
}

View File

@ -63,7 +63,10 @@ export function serializeFunction(rootNode) {
const noteForAppending: HTMLElement[] = [];
// lets care about static css first
if ((nodeArg.constructor as any).styles && (nodeArg.constructor as any).styles instanceof Array) {
if (
(nodeArg.constructor as any).styles &&
(nodeArg.constructor as any).styles instanceof Array
) {
for (const objectArg of (nodeArg.constructor as any).styles) {
const styleTag = document.createElement('style');
styleTag.textContent = prependCss(nodeUUID, objectArg.cssText);