try to inline linked stylesheet when in same origin

This commit is contained in:
Yanzhen Yu
2018-10-05 23:06:51 +08:00
parent c24e0c6a2f
commit 8b82981b62
6 changed files with 110 additions and 33 deletions

View File

@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>with style sheet</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/pure@2.85.0/index.css">
</head>
<body>
</body>
</html>

View File

@@ -13,4 +13,23 @@
</body>
</html>
<!-- TEST_DIVIDER -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>with style sheet</title>
<style>body { margin: 0px; }p { color: red; }</style>
</head>
<body>
</body>
</html>

View File

@@ -64,7 +64,7 @@ describe('integration tests', () => {
before(async () => {
this.server = await server();
this.browser = await puppeteer.launch({
headless: false,
// headless: false,
executablePath: '/home/yanzhen/Desktop/chrome-linux/chrome',
});
@@ -79,33 +79,35 @@ describe('integration tests', () => {
this.code = code;
});
after(() => {
this.browser.close();
this.server.close();
after(async () => {
await this.browser.close();
await this.server.close();
});
for (const html of htmls) {
for (const html of htmls.slice(0, 10)) {
it('[html file]: ' + html.filePath, async () => {
const page: puppeteer.Page = await this.browser.newPage();
await page.goto(`http://localhost:3030/html/${html.filePath}`);
// console for debug
// tslint:disable-next-line: no-console
page.on('console', msg => console.log(msg.text()));
await page.goto(`http://localhost:3030/html`);
await page.setContent(html.src);
page.once('load', async () => {
await page.evaluate(() => {
const x = new XMLSerializer();
return x.serializeToString(document);
});
const rebuildHtml = (await page.evaluate(`${this.code}
const x = new XMLSerializer();
const snap = rrweb.snapshot(document);
x.serializeToString(rrweb.rebuild(snap));
`)).replace(/\n\n/g, '');
await page.goto(`data:text/html,${html.dest}`);
const destHtml = (await page.evaluate(() => {
const x = new XMLSerializer();
return x.serializeToString(document);
})).replace(/\n\n/g, '');
expect(rebuildHtml).to.equal(destHtml);
await page.evaluate(() => {
const x = new XMLSerializer();
return x.serializeToString(document);
});
const rebuildHtml = (await page.evaluate(`${this.code}
const x = new XMLSerializer();
const snap = rrweb.snapshot(document);
x.serializeToString(rrweb.rebuild(snap));
`)).replace(/\n\n/g, '');
await page.goto(`http://localhost:3030/html`);
await page.setContent(html.dest);
const destHtml = (await page.evaluate(() => {
const x = new XMLSerializer();
return x.serializeToString(document);
})).replace(/\n\n/g, '');
expect(rebuildHtml).to.equal(destHtml);
}).timeout(5000);
}
});