Compare commits

..

14 Commits

Author SHA1 Message Date
042caeeeb5 1.0.27 2021-05-19 15:21:48 +00:00
6ddfaffbff fix(core): update 2021-05-19 15:21:47 +00:00
567507c88b 1.0.26 2021-05-19 11:32:13 +00:00
35f7bdd984 fix(core): update 2021-05-19 11:32:12 +00:00
602fa2b7ff 1.0.25 2021-05-19 01:33:59 +00:00
b1aae3e5b9 fix(core): update 2021-05-19 01:33:58 +00:00
6b381d6115 1.0.24 2021-01-15 14:22:50 +00:00
25006901d9 fix(core): update 2021-01-15 14:22:49 +00:00
ee613836d1 1.0.23 2021-01-15 07:17:08 +00:00
4b53173618 fix(core): update 2021-01-15 07:17:08 +00:00
46a0220273 1.0.22 2021-01-12 15:17:31 +00:00
46a6c903e1 fix(core): update 2021-01-12 15:17:31 +00:00
134151eb70 1.0.21 2021-01-12 15:07:45 +00:00
ac1c3ac53d fix(core): update 2021-01-12 15:07:45 +00:00
5 changed files with 2223 additions and 1225 deletions

3394
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/smartssr", "name": "@pushrocks/smartssr",
"version": "1.0.20", "version": "1.0.27",
"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",
@ -10,22 +10,22 @@
"scripts": { "scripts": {
"test": "(tstest test/ --web)", "test": "(tstest test/ --web)",
"build": "(tsbuild --web)", "build": "(tsbuild --web)",
"format": "(gitzone format)" "serve": "tsrun scripts/serve.ts"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.25", "@gitzone/tsbuild": "^2.1.25",
"@gitzone/tstest": "^1.0.52", "@gitzone/tstest": "^1.0.54",
"@pushrocks/smartserve": "^1.1.41", "@pushrocks/smartserve": "^1.1.41",
"@pushrocks/tapbundle": "^3.2.9", "@pushrocks/tapbundle": "^3.2.14",
"@types/node": "^14.14.20", "@types/node": "^15.3.0",
"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.10",
"@pushrocks/smartfile": "^8.0.8", "@pushrocks/smartfile": "^8.0.10",
"@pushrocks/smartpromise": "^3.1.3", "@pushrocks/smartpromise": "^3.1.5",
"@pushrocks/smartpuppeteer": "^1.0.19", "@pushrocks/smartpuppeteer": "^1.0.21",
"@pushrocks/smarttime": "^3.0.38" "@pushrocks/smarttime": "^3.0.38"
}, },
"files": [ "files": [

View File

@ -13,18 +13,17 @@ tap.test('should start the smartssr instance', async () => {
await testSSRInstance.start(); await testSSRInstance.start();
}); });
tap.skip.test('should render central.eu', async (tools) => { tap.test('should render central.eu', async (tools) => {
await testSSRInstance.renderPage( await testSSRInstance.renderPage('https://lossless.com');
'https://central.eu/article/5e76873b9cf69b7bf6bc78bc/Introducing%3A%20central.eu'
);
}); });
tap.test('should render lossless.com', async () => { tap.skip.test('should render lossless.com', async () => {
await testSSRInstance.renderPage('https://lossless.com'); await testSSRInstance.renderPage('https://lossless.com');
}); });
tap.skip.test('should render https://lossless.gmbh', async () => { tap.skip.test('should render https://lossless.gmbh', async () => {
const renderedPage = await testSSRInstance.renderPage('https://lossless.gmbh'); const renderedPage = await testSSRInstance.renderPage('https://lossless.gmbh');
console.log(renderedPage);
}); });
tap.test('should stop the smartssr instance', async () => { tap.test('should stop the smartssr instance', async () => {

View File

@ -43,6 +43,17 @@ export class SmartSSR {
const resultDeferred = plugins.smartpromise.defer<string>(); const resultDeferred = plugins.smartpromise.defer<string>();
const context = await this.browser.getNewIncognitoContext(); const context = await this.browser.getNewIncognitoContext();
const page = await context.newPage(); const page = await context.newPage();
// lets protext against left open tabs
plugins.smartdelay.delayFor(30000).then(() => {
if (!page.isClosed) {
page.close();
context.close();
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()}`);
}); });
@ -51,7 +62,7 @@ export class SmartSSR {
renderTimeMeasurement.start(); renderTimeMeasurement.start();
await page.goto(urlArg, { await page.goto(urlArg, {
waitUntil: 'networkidle2', waitUntil: 'networkidle2',
timeout: 0 timeout: 30000,
}); });
let screenshotBuffer: Buffer; let screenshotBuffer: Buffer;
@ -71,6 +82,7 @@ export class SmartSSR {
renderTimeMeasurement.stop(); renderTimeMeasurement.stop();
// lets clean up async // lets clean up async
await page.close();
await context.close(); await context.close();
overallTimeMeasurement.stop(); overallTimeMeasurement.stop();

View File

@ -39,6 +39,8 @@ export function serializeFunction(rootNode) {
const nodeUUID = uuidv4(); const nodeUUID = uuidv4();
nodeArg.classList.add(nodeUUID); nodeArg.classList.add(nodeUUID);
// find all slots
const slots = nodeArg.shadowRoot.querySelectorAll('slot'); const slots = nodeArg.shadowRoot.querySelectorAll('slot');
// handle slot element // handle slot element
@ -59,6 +61,16 @@ export function serializeFunction(rootNode) {
const childNodes = nodeArg.shadowRoot.childNodes; const childNodes = nodeArg.shadowRoot.childNodes;
// tslint:disable-next-line: prefer-for-of // tslint:disable-next-line: prefer-for-of
const noteForAppending: HTMLElement[] = []; const noteForAppending: HTMLElement[] = [];
// lets care about static css first
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);
noteForAppending.push(styleTag);
}
}
childNodes.forEach((childNode) => { childNodes.forEach((childNode) => {
if (childNode instanceof HTMLElement) { if (childNode instanceof HTMLElement) {
if (childNode.tagName === 'STYLE') { if (childNode.tagName === 'STYLE') {
@ -69,6 +81,9 @@ export function serializeFunction(rootNode) {
noteForAppending.push(childNode); noteForAppending.push(childNode);
} }
}); });
while (nodeArg.firstChild) {
nodeArg.removeChild(nodeArg.firstChild);
}
noteForAppending.forEach((childNode) => { noteForAppending.forEach((childNode) => {
nodeArg.append(childNode); nodeArg.append(childNode);
}); });