Skip to content

Commit

Permalink
Merge pull request #49 from timonbandit/master
Browse files Browse the repository at this point in the history
Added error handling on timeout while getting css. Updated outdated dependencies.
  • Loading branch information
philipp-winterle committed Jan 24, 2024
2 parents b512d52 + 868518c commit ebddada
Show file tree
Hide file tree
Showing 5 changed files with 1,020 additions and 794 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/node.js.yml
Expand Up @@ -15,7 +15,7 @@ jobs:

strategy:
matrix:
node-version: [14.x, 16.x, 18.x]
node-version: [16.x, 18.x, 20.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
Expand Down
2 changes: 1 addition & 1 deletion lib/Constants.js
Expand Up @@ -9,7 +9,7 @@ module.exports = {

PRINT_BROWSER_CONSOLE: false,
DROP_KEYFRAMES: true,
PUPPETEER_HEADLESS: true,
PUPPETEER_HEADLESS: "new",
BROWSER_USER_AGENT: 'Crittr ' + package_json.version,
BROWSER_CACHE_ENABLED: true,
BROWSER_JS_ENABLED: true,
Expand Down
16 changes: 11 additions & 5 deletions lib/classes/Crittr.class.js
Expand Up @@ -328,20 +328,26 @@ class Crittr {

resolve(cssString);
} else if (!this.options.css) {
let cssString = await this.getCssFromUrl(this.options.urls[0]);
try {
let cssString = await this.getCssFromUrl(this.options.urls[0]);

resolve(cssString);
resolve(cssString);
} catch (e) {
reject(e);
}
}
});
}

async getCssFromUrl(url) {
let cssString = '';
const page = await this.getPage();

debug('getCssFromUrl - Try to get collect CSS from ' + url);
await page.coverage.startCSSCoverage();
await page.goto(url, { waitUntil: 'load' });

await page.goto(url, {
waitUntil: 'load',
timeout: this.options.timeout,
});
cssString = await page.evaluate(() => {
return [...document.styleSheets]
.map(styleSheet => {
Expand Down
30 changes: 15 additions & 15 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "crittr",
"version": "1.5.2",
"version": "1.5.3",
"description": "Crittr is a high performance critical css extraction library with a multiple url support.",
"author": "Philipp Winterle",
"license": "GPL-3.0",
Expand All @@ -26,33 +26,33 @@
"extract"
],
"engines": {
"node": ">=14"
"node": ">=16"
},
"main": "index.js",
"dependencies": {
"@types/jest": "^29.0.0",
"@types/jest": "^29.5.11",
"chalk": "^4.1.2",
"clean-css": "^5.3.1",
"clean-css": "^5.3.3",
"css": "^3.0.0",
"debug": "^4.3.2",
"deepmerge": "^4.2.2",
"fs-extra": "^10.1.0",
"debug": "^4.3.4",
"deepmerge": "^4.3.1",
"fs-extra": "^11.2.0",
"is-plain-object": "^5.0.0",
"lodash": "^4.17.21",
"object-hash": "^3.0.0",
"postcss": "^8.4.16",
"postcss-sort-media-queries": "^4.3.0",
"puppeteer": "^17.1.2",
"postcss": "^8.4.33",
"postcss-sort-media-queries": "^5.2.0",
"puppeteer": "^21.9.0",
"run-queue": "^2.0.1",
"signale": "^1.4.0"
},
"devDependencies": {
"cross-env": "^7.0.3",
"eslint": "^8.23.0",
"eslint-config-prettier": "^8.3.0",
"husky": "^8.0.1",
"jest": "^28.0.2",
"prettier": "^2.7.1"
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"husky": "^8.0.3",
"jest": "^29.7.0",
"prettier": "^3.2.4"
},
"scripts": {
"test": "cross-env NODE_ENV=development jest --bail --verbose",
Expand Down

0 comments on commit ebddada

Please sign in to comment.