Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
446b4c38ea | |||
bc6d3f45f8 | |||
bd381ff23f | |||
7e5bdf8521 | |||
f427141c7c | |||
e8191187a1 | |||
6e1dcccd81 |
2621
package-lock.json
generated
2621
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
16
package.json
16
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartssr",
|
"name": "@pushrocks/smartssr",
|
||||||
"version": "1.0.13",
|
"version": "1.0.17",
|
||||||
"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,20 +13,20 @@
|
|||||||
"format": "(gitzone format)"
|
"format": "(gitzone format)"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.24",
|
"@gitzone/tsbuild": "^2.1.25",
|
||||||
"@gitzone/tstest": "^1.0.43",
|
"@gitzone/tstest": "^1.0.52",
|
||||||
"@pushrocks/smartserve": "^1.1.41",
|
"@pushrocks/smartserve": "^1.1.41",
|
||||||
"@pushrocks/tapbundle": "^3.2.9",
|
"@pushrocks/tapbundle": "^3.2.9",
|
||||||
"@types/node": "^14.0.27",
|
"@types/node": "^14.14.20",
|
||||||
"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": "^7.0.12",
|
"@pushrocks/smartfile": "^8.0.8",
|
||||||
"@pushrocks/smartpromise": "^3.0.6",
|
"@pushrocks/smartpromise": "^3.1.3",
|
||||||
"@pushrocks/smartpuppeteer": "^1.0.15",
|
"@pushrocks/smartpuppeteer": "^1.0.19",
|
||||||
"@pushrocks/smarttime": "^3.0.24"
|
"@pushrocks/smarttime": "^3.0.38"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"ts/**/*",
|
"ts/**/*",
|
||||||
|
@ -13,13 +13,13 @@ tap.test('should start the smartssr instance', async () => {
|
|||||||
await testSSRInstance.start();
|
await testSSRInstance.start();
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should render central.eu', async (tools) => {
|
tap.skip.test('should render central.eu', async (tools) => {
|
||||||
await testSSRInstance.renderPage(
|
await testSSRInstance.renderPage(
|
||||||
'https://central.eu/article/5e76873b9cf69b7bf6bc78bc/Introducing%3A%20central.eu'
|
'https://central.eu/article/5e76873b9cf69b7bf6bc78bc/Introducing%3A%20central.eu'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.skip.test('should render lossless.com', async () => {
|
tap.test('should render lossless.com', async () => {
|
||||||
await testSSRInstance.renderPage('https://lossless.com');
|
await testSSRInstance.renderPage('https://lossless.com');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ export interface ISmartSSROptions {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
export class SmartSSR {
|
export class SmartSSR {
|
||||||
public browser: plugins.smartpuppeteer.puppeteer.Browser;
|
public browser: plugins.smartpuppeteer.IncognitoBrowser;
|
||||||
public options: ISmartSSROptions;
|
public options: ISmartSSROptions;
|
||||||
|
|
||||||
constructor(optionsArg?: ISmartSSROptions) {
|
constructor(optionsArg?: ISmartSSROptions) {
|
||||||
@ -24,12 +24,13 @@ export class SmartSSR {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async start() {
|
public async start() {
|
||||||
this.browser = await plugins.smartpuppeteer.getEnvAwareBrowserInstance();
|
this.browser = new plugins.smartpuppeteer.IncognitoBrowser();
|
||||||
|
await this.browser.start();
|
||||||
}
|
}
|
||||||
public async stop() {
|
public async stop() {
|
||||||
if (this.browser) {
|
if (this.browser) {
|
||||||
await plugins.smartdelay.delayFor(3000);
|
await plugins.smartdelay.delayFor(3000);
|
||||||
await this.browser.close();
|
await this.browser.stop();
|
||||||
this.browser = null;
|
this.browser = null;
|
||||||
} else {
|
} else {
|
||||||
console.log('browser was not in started mode');
|
console.log('browser was not in started mode');
|
||||||
@ -40,40 +41,32 @@ export class SmartSSR {
|
|||||||
const overallTimeMeasurement = new plugins.smarttime.HrtMeasurement();
|
const overallTimeMeasurement = new plugins.smarttime.HrtMeasurement();
|
||||||
overallTimeMeasurement.start();
|
overallTimeMeasurement.start();
|
||||||
const resultDeferred = plugins.smartpromise.defer<string>();
|
const resultDeferred = plugins.smartpromise.defer<string>();
|
||||||
const context = await this.browser.createIncognitoBrowserContext();
|
const context = await this.browser.getNewIncognitoContext();
|
||||||
const page = await context.newPage();
|
const page = await context.newPage();
|
||||||
page.on('console', (msg) => {
|
page.on('console', (msg) => {
|
||||||
console.log(`${urlArg}: ${msg.text()}`);
|
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();
|
const renderTimeMeasurement = new plugins.smarttime.HrtMeasurement();
|
||||||
renderTimeMeasurement.start();
|
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;
|
const result = await resultDeferred.promise;
|
||||||
renderTimeMeasurement.stop();
|
renderTimeMeasurement.stop();
|
||||||
|
|
||||||
@ -87,6 +80,17 @@ export class SmartSSR {
|
|||||||
console.log(
|
console.log(
|
||||||
`The rendering alone took ${renderTimeMeasurement.milliSeconds} milliseconds for ${urlArg}`
|
`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;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,11 +42,18 @@ export function serializeFunction(rootNode) {
|
|||||||
const slots = nodeArg.shadowRoot.querySelectorAll('slot');
|
const slots = nodeArg.shadowRoot.querySelectorAll('slot');
|
||||||
|
|
||||||
// handle slot element
|
// handle slot element
|
||||||
|
const slotsForMove: HTMLSlotElement[] = [];
|
||||||
slots.forEach((slot) => {
|
slots.forEach((slot) => {
|
||||||
nodeArg.childNodes.forEach((lightNode) => slot.parentNode.insertBefore(lightNode, slot));
|
slotsForMove.push(slot);
|
||||||
slot.parentNode.removeChild(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
|
// lets modify the css
|
||||||
const childNodes = nodeArg.shadowRoot.childNodes;
|
const childNodes = nodeArg.shadowRoot.childNodes;
|
||||||
// tslint:disable-next-line: prefer-for-of
|
// tslint:disable-next-line: prefer-for-of
|
||||||
@ -56,9 +63,6 @@ export function serializeFunction(rootNode) {
|
|||||||
if (childNode.tagName === 'STYLE') {
|
if (childNode.tagName === 'STYLE') {
|
||||||
childNode.textContent = prependCss(nodeUUID, childNode.textContent);
|
childNode.textContent = prependCss(nodeUUID, childNode.textContent);
|
||||||
} else {
|
} else {
|
||||||
if (nodeArg.tagName?.includes('ARTICLEGRID')) {
|
|
||||||
console.log('hello ' + childNode.id);
|
|
||||||
}
|
|
||||||
serializeNode(childNode, logThis);
|
serializeNode(childNode, logThis);
|
||||||
}
|
}
|
||||||
noteForAppending.push(childNode);
|
noteForAppending.push(childNode);
|
||||||
|
Reference in New Issue
Block a user