Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
49db495bb9 | |||
d0ee536301 | |||
344e213c41 | |||
0ae13c970e | |||
0502e7bc99 | |||
c0a425e16d |
@ -36,7 +36,6 @@ auditProductionDependencies:
|
|||||||
- npmci command npm audit --audit-level=high --only=prod --production
|
- npmci command npm audit --audit-level=high --only=prod --production
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
allow_failure: true
|
|
||||||
|
|
||||||
auditDevDependencies:
|
auditDevDependencies:
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
14813
package-lock.json
generated
14813
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
12
package.json
12
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartssr",
|
"name": "@pushrocks/smartssr",
|
||||||
"version": "1.0.29",
|
"version": "1.0.32",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "a smart server side renderer supporting shadow dom",
|
"description": "a smart server side renderer supporting shadow dom",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
@ -13,19 +13,19 @@
|
|||||||
"serve": "tsrun scripts/serve.ts"
|
"serve": "tsrun scripts/serve.ts"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.25",
|
"@gitzone/tsbuild": "^2.1.26",
|
||||||
"@gitzone/tstest": "^1.0.54",
|
"@gitzone/tstest": "^1.0.54",
|
||||||
"@pushrocks/smartserve": "^1.1.41",
|
"@pushrocks/smartserve": "^1.1.41",
|
||||||
"@pushrocks/tapbundle": "^3.2.14",
|
"@pushrocks/tapbundle": "^3.2.14",
|
||||||
"@types/node": "^15.3.0",
|
"@types/node": "^16.6.1",
|
||||||
"tslint": "^6.1.3",
|
"tslint": "^6.1.3",
|
||||||
"tslint-config-prettier": "^1.15.0"
|
"tslint-config-prettier": "^1.15.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartdelay": "^2.0.10",
|
"@pushrocks/smartdelay": "^2.0.13",
|
||||||
"@pushrocks/smartfile": "^8.0.10",
|
"@pushrocks/smartfile": "^8.0.10",
|
||||||
"@pushrocks/smartpromise": "^3.1.5",
|
"@pushrocks/smartpromise": "^3.1.6",
|
||||||
"@pushrocks/smartpuppeteer": "^1.0.21",
|
"@pushrocks/smartpuppeteer": "^1.0.25",
|
||||||
"@pushrocks/smarttime": "^3.0.38"
|
"@pushrocks/smarttime": "^3.0.38"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
|
@ -27,50 +27,49 @@ export class SmartSSR {
|
|||||||
overallTimeMeasurement.start();
|
overallTimeMeasurement.start();
|
||||||
const resultDeferred = plugins.smartpromise.defer<string>();
|
const resultDeferred = plugins.smartpromise.defer<string>();
|
||||||
const browser = new plugins.smartpuppeteer.IncognitoBrowser();
|
const browser = new plugins.smartpuppeteer.IncognitoBrowser();
|
||||||
|
const renderTimeMeasurement = new plugins.smarttime.HrtMeasurement();
|
||||||
|
let renderedPageString: string;
|
||||||
|
let screenshotBuffer: Buffer;
|
||||||
await browser.start();
|
await browser.start();
|
||||||
|
try {
|
||||||
const context = await browser.getNewIncognitoContext();
|
const context = await browser.getNewIncognitoContext();
|
||||||
const page = await context.newPage();
|
const page = await context.newPage();
|
||||||
|
|
||||||
// lets protext against left open tabs
|
// lets protect against left open tabs
|
||||||
plugins.smartdelay.delayFor(30000).then(() => {
|
plugins.smartdelay.delayFor(30000).then(async () => {
|
||||||
if (!page.isClosed) {
|
try {
|
||||||
page.close();
|
await browser.stop();
|
||||||
context.close();
|
} catch {}
|
||||||
throw new Error(`failed to render ${urlArg}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
page.on('console', (msg) => {
|
page.on('console', (msg) => {
|
||||||
console.log(`${urlArg}: ${msg.text()}`);
|
console.log(`${urlArg}: ${msg.text()}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
const renderTimeMeasurement = new plugins.smarttime.HrtMeasurement();
|
|
||||||
renderTimeMeasurement.start();
|
renderTimeMeasurement.start();
|
||||||
await page.goto(urlArg, {
|
await page.goto(urlArg, {
|
||||||
waitUntil: 'networkidle2',
|
waitUntil: 'networkidle2',
|
||||||
timeout: 30000,
|
timeout: 30000,
|
||||||
});
|
});
|
||||||
|
|
||||||
let screenshotBuffer: Buffer;
|
|
||||||
|
|
||||||
if (this.options.debug) {
|
if (this.options.debug) {
|
||||||
screenshotBuffer = await page.screenshot({
|
screenshotBuffer = await page.screenshot({
|
||||||
encoding: 'binary',
|
encoding: 'binary',
|
||||||
});
|
}) as Buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
await page.$eval('body', serializeFunction);
|
await page.$eval('body', serializeFunction);
|
||||||
const pageContent = await page.content();
|
const pageContent = await page.content();
|
||||||
const renderedPageString = pageContent;
|
renderedPageString = pageContent;
|
||||||
resultDeferred.resolve(renderedPageString);
|
resultDeferred.resolve(renderedPageString);
|
||||||
|
|
||||||
const result = await resultDeferred.promise;
|
|
||||||
renderTimeMeasurement.stop();
|
renderTimeMeasurement.stop();
|
||||||
|
|
||||||
// lets clean up async
|
// lets clean up async
|
||||||
await page.close();
|
await page.close();
|
||||||
await context.close();
|
await context.close();
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e);
|
||||||
|
}
|
||||||
await browser.stop();
|
await browser.stop();
|
||||||
|
|
||||||
overallTimeMeasurement.stop();
|
overallTimeMeasurement.stop();
|
||||||
@ -91,6 +90,6 @@ export class SmartSSR {
|
|||||||
fs.writeFileSync(plugins.path.join(paths.noGitDir, 'test.png'), screenshotBuffer);
|
fs.writeFileSync(plugins.path.join(paths.noGitDir, 'test.png'), screenshotBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return resultDeferred.promise;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
declare var document: Document;
|
declare var document: Document;
|
||||||
export function serializeFunction(rootNode) {
|
export function serializeFunction(rootNode: Node) {
|
||||||
const uuidv4 = () => {
|
const uuidv4 = () => {
|
||||||
return 'unixxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
return 'unixxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
||||||
const r = (Math.random() * 16) | 0;
|
const r = (Math.random() * 16) | 0;
|
||||||
@ -26,7 +26,7 @@ export function serializeFunction(rootNode) {
|
|||||||
};
|
};
|
||||||
const loopProtection: any[] = [];
|
const loopProtection: any[] = [];
|
||||||
|
|
||||||
function serializeNode(nodeArg: HTMLElement, logThis = false) {
|
function serializeNode(nodeArg: HTMLElement | any, logThis = false) {
|
||||||
if (loopProtection.includes(nodeArg)) {
|
if (loopProtection.includes(nodeArg)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -45,12 +45,12 @@ export function serializeFunction(rootNode) {
|
|||||||
|
|
||||||
// handle slot element
|
// handle slot element
|
||||||
const slotsForMove: HTMLSlotElement[] = [];
|
const slotsForMove: HTMLSlotElement[] = [];
|
||||||
slots.forEach((slot) => {
|
slots.forEach((slot: any) => {
|
||||||
slotsForMove.push(slot);
|
slotsForMove.push(slot);
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const slot of slotsForMove) {
|
for (const slot of slotsForMove) {
|
||||||
const slottedLightNodesForMove = [];
|
const slottedLightNodesForMove: any[] = [];
|
||||||
slot.assignedNodes().forEach((lightNode) => slottedLightNodesForMove.push(lightNode));
|
slot.assignedNodes().forEach((lightNode) => slottedLightNodesForMove.push(lightNode));
|
||||||
slottedLightNodesForMove.forEach((lightNode) =>
|
slottedLightNodesForMove.forEach((lightNode) =>
|
||||||
slot.parentNode.insertBefore(lightNode, slot)
|
slot.parentNode.insertBefore(lightNode, slot)
|
||||||
@ -63,7 +63,10 @@ export function serializeFunction(rootNode) {
|
|||||||
const noteForAppending: HTMLElement[] = [];
|
const noteForAppending: HTMLElement[] = [];
|
||||||
|
|
||||||
// lets care about static css first
|
// 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) {
|
for (const objectArg of (nodeArg.constructor as any).styles) {
|
||||||
const styleTag = document.createElement('style');
|
const styleTag = document.createElement('style');
|
||||||
styleTag.textContent = prependCss(nodeUUID, objectArg.cssText);
|
styleTag.textContent = prependCss(nodeUUID, objectArg.cssText);
|
||||||
@ -71,7 +74,7 @@ export function serializeFunction(rootNode) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
childNodes.forEach((childNode) => {
|
childNodes.forEach((childNode: ChildNode) => {
|
||||||
if (childNode instanceof HTMLElement) {
|
if (childNode instanceof HTMLElement) {
|
||||||
if (childNode.tagName === 'STYLE') {
|
if (childNode.tagName === 'STYLE') {
|
||||||
childNode.textContent = prependCss(nodeUUID, childNode.textContent);
|
childNode.textContent = prependCss(nodeUUID, childNode.textContent);
|
||||||
|
Reference in New Issue
Block a user