-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
Hey,
first of all, great work! Everything works like expected.
What do you think about adding this lines to your plugin?
To inline the Stylesheets and the JavaScript files.
first
const urlModule = require('url');
const URL = urlModule.URL;
underneath
const delayPageLoad,
const puppeteerOptions etc...
const stylesheetContents = {};
const javascriptContents = {};
the first part of your chain() function behind (page) => page.on('pageerror', ...
`stash stylesheet and javascript`,
(page) => page.on('response', async resp => {
const responseUrl = resp.url();
const sameOrigin = new URL(responseUrl).origin === new URL(source).origin;
const isStylesheet = resp.request().resourceType() === 'stylesheet';
const isJavaScript = resp.request().resourceType() === 'script';
if (sameOrigin && isStylesheet) {
stylesheetContents[responseUrl] = await resp.text();
}
if (sameOrigin && isJavaScript) {
javascriptContents[responseUrl] = await resp.text();
}
}),
the second part in .then(([browser, page]) => chain(...
behind () => page.waitFor(delayPageLoad),...
`inline stylesheet`,
() => page.$$eval('link[rel="stylesheet"]', (links, content) => {
links.forEach(link => {
const ctx = content[link.href];
if (ctx) {
const style = document.createElement('style');
style.textContent = ctx;
link.replaceWith(style);
}
});
}, stylesheetContents),
`inline javascript`,
() => page.$$eval('script[type="text/javascript"]', (links, content) => {
links.forEach(link => {
const ctx = content[link.src];
if (ctx) {
const script = document.createElement('script');
script.textContent = ctx;
link.replaceWith(script);
}
});
}, javascriptContents),
Let me know about your thoughts :)
cheers
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels