Compare commits

...

37 Commits

Author SHA1 Message Date
344e213c41 1.0.31 2021-08-16 17:47:21 +02:00
0ae13c970e fix(core): update 2021-08-16 17:47:20 +02:00
0502e7bc99 1.0.30 2021-08-16 16:26:13 +02:00
c0a425e16d fix(core): update 2021-08-16 16:26:13 +02:00
90089357cf 1.0.29 2021-08-16 10:31:39 +02:00
e36aed4b2b fix(core): update 2021-08-16 10:31:38 +02:00
4d2aa7a0ee 1.0.28 2021-08-16 10:30:46 +02:00
759fa1ff43 fix(core): update 2021-08-16 10:30:46 +02:00
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
09c23d04f4 1.0.20 2021-01-12 14:18:17 +00:00
3f359cb58c fix(core): update 2021-01-12 14:18:16 +00:00
a85eb48343 1.0.19 2021-01-09 01:48:37 +00:00
7c851b5ed2 fix(core): update 2021-01-09 01:48:36 +00:00
bcd69059f8 1.0.18 2021-01-08 22:08:02 +00:00
acba539a6f fix(core): update 2021-01-08 22:08:01 +00:00
446b4c38ea 1.0.17 2021-01-08 22:06:26 +00:00
bc6d3f45f8 fix(core): update 2021-01-08 22:06:25 +00:00
bd381ff23f 1.0.16 2020-08-06 17:50:03 +00:00
7e5bdf8521 fix(core): update 2020-08-06 17:50:00 +00:00
f427141c7c 1.0.15 2020-08-06 15:30:54 +00:00
e8191187a1 fix(core): update 2020-08-06 15:30:54 +00:00
6e1dcccd81 1.0.14 2020-08-06 15:18:54 +00:00
f8eee10a40 1.0.13 2020-08-06 15:18:48 +00:00
a6492a5465 1.0.12 2020-08-06 15:18:40 +00:00
6 changed files with 19471 additions and 1695 deletions

View File

@ -26,16 +26,28 @@ mirror:
- docker
- notpriv
audit:
auditProductionDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- npmci command npm install --production --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high --only=prod --production
tags:
- docker
auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- npmci command npm install --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high
- npmci command npm audit --audit-level=high --only=dev
tags:
- docker
allow_failure: true
# ====================
# test stage

20997
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartssr",
"version": "1.0.11",
"version": "1.0.31",
"private": false,
"description": "a smart server side renderer supporting shadow dom",
"main": "dist_ts/index.js",
@ -10,23 +10,23 @@
"scripts": {
"test": "(tstest test/ --web)",
"build": "(tsbuild --web)",
"format": "(gitzone format)"
"serve": "tsrun scripts/serve.ts"
},
"devDependencies": {
"@gitzone/tsbuild": "^2.1.24",
"@gitzone/tstest": "^1.0.43",
"@gitzone/tsbuild": "^2.1.25",
"@gitzone/tstest": "^1.0.54",
"@pushrocks/smartserve": "^1.1.41",
"@pushrocks/tapbundle": "^3.2.9",
"@types/node": "^14.0.27",
"@pushrocks/tapbundle": "^3.2.14",
"@types/node": "^15.3.0",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.15.0"
},
"dependencies": {
"@pushrocks/smartdelay": "^2.0.10",
"@pushrocks/smartfile": "^7.0.12",
"@pushrocks/smartpromise": "^3.0.6",
"@pushrocks/smartpuppeteer": "^1.0.15",
"@pushrocks/smarttime": "^3.0.24"
"@pushrocks/smartfile": "^8.0.10",
"@pushrocks/smartpromise": "^3.1.5",
"@pushrocks/smartpuppeteer": "^1.0.21",
"@pushrocks/smarttime": "^3.0.38"
},
"files": [
"ts/**/*",

View File

@ -9,14 +9,8 @@ tap.test('should create a valid smartssr instance', async () => {
});
});
tap.test('should start the smartssr instance', async () => {
await testSSRInstance.start();
});
tap.test('should render central.eu', async (tools) => {
await testSSRInstance.renderPage(
'https://central.eu/article/5e76873b9cf69b7bf6bc78bc/Introducing%3A%20central.eu'
);
await testSSRInstance.renderPage('https://lossless.com');
});
tap.skip.test('should render lossless.com', async () => {
@ -25,10 +19,7 @@ tap.skip.test('should render lossless.com', async () => {
tap.skip.test('should render https://lossless.gmbh', async () => {
const renderedPage = await testSSRInstance.renderPage('https://lossless.gmbh');
});
tap.test('should stop the smartssr instance', async () => {
await testSSRInstance.stop();
console.log(renderedPage);
});
tap.start();

View File

@ -11,7 +11,6 @@ export interface ISmartSSROptions {
*
*/
export class SmartSSR {
public browser: plugins.smartpuppeteer.puppeteer.Browser;
public options: ISmartSSROptions;
constructor(optionsArg?: ISmartSSROptions) {
@ -23,32 +22,35 @@ export class SmartSSR {
};
}
public async start() {
this.browser = await plugins.smartpuppeteer.getEnvAwareBrowserInstance();
}
public async stop() {
if (this.browser) {
await plugins.smartdelay.delayFor(3000);
await this.browser.close();
this.browser = null;
} else {
console.log('browser was not in started mode');
}
}
public async renderPage(urlArg: string) {
const overallTimeMeasurement = new plugins.smarttime.HrtMeasurement();
overallTimeMeasurement.start();
const resultDeferred = plugins.smartpromise.defer<string>();
const context = await this.browser.createIncognitoBrowserContext();
const page = await context.newPage();
page.on('console', (msg) => {
console.log(`${urlArg}: ${msg.text()}`);
});
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();
page.on('load', async (...args) => {
await plugins.smartdelay.delayFor(5000);
let screenshotBuffer: Buffer;
// lets protect against left open tabs
plugins.smartdelay.delayFor(30000).then(async () => {
try {
await browser.stop();
} catch {}
});
page.on('console', (msg) => {
console.log(`${urlArg}: ${msg.text()}`);
});
renderTimeMeasurement.start();
await page.goto(urlArg, {
waitUntil: 'networkidle2',
timeout: 30000,
});
if (this.options.debug) {
screenshotBuffer = await page.screenshot({
@ -58,27 +60,17 @@ export class SmartSSR {
await page.$eval('body', serializeFunction);
const pageContent = await page.content();
const renderedPageString = pageContent;
renderedPageString = pageContent;
resultDeferred.resolve(renderedPageString);
renderTimeMeasurement.stop();
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);
const result = await resultDeferred.promise;
renderTimeMeasurement.stop();
// lets clean up async
context.close();
// lets clean up async
await page.close();
await context.close();
} catch (e) {
console.log(e);
}
await browser.stop();
overallTimeMeasurement.stop();
console.log(
@ -87,6 +79,17 @@ export class SmartSSR {
console.log(
`The rendering alone took ${renderTimeMeasurement.milliSeconds} milliseconds for ${urlArg}`
);
return result;
// 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 resultDeferred.promise;
}
}

View File

@ -39,31 +39,54 @@ export function serializeFunction(rootNode) {
const nodeUUID = uuidv4();
nodeArg.classList.add(nodeUUID);
// find all slots
const slots = nodeArg.shadowRoot.querySelectorAll('slot');
// handle slot element
const slotsForMove: HTMLSlotElement[] = [];
slots.forEach((slot) => {
nodeArg.childNodes.forEach((lightNode) => slot.parentNode.insertBefore(lightNode, slot));
slot.parentNode.removeChild(slot);
slotsForMove.push(slot);
});
for (const slot of slotsForMove) {
const slottedLightNodesForMove = [];
slot.assignedNodes().forEach((lightNode) => slottedLightNodesForMove.push(lightNode));
slottedLightNodesForMove.forEach((lightNode) =>
slot.parentNode.insertBefore(lightNode, slot)
);
}
// lets modify the css
const childNodes = nodeArg.shadowRoot.childNodes;
// tslint:disable-next-line: prefer-for-of
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) => {
if (childNode instanceof HTMLElement) {
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);
}
});
while (nodeArg.firstChild) {
nodeArg.removeChild(nodeArg.firstChild);
}
noteForAppending.forEach((childNode) => {
nodeArg.append(childNode);
});