├── .npmrc ├── .gitattributes ├── .gitignore ├── .editorconfig ├── test.js ├── .github └── workflows │ └── main.yml ├── gruntfile.js ├── tasks └── pageres.js ├── license ├── package.json └── readme.md /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false 2 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | yarn.lock 3 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | end_of_line = lf 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [*.yml] 11 | indent_style = space 12 | indent_size = 2 13 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | import test from 'ava'; 2 | import pathExists from 'path-exists'; 3 | 4 | test('pageres', t => { 5 | t.true(pathExists.sync('temp/sindresorhus.com-1000x1000.png')); 6 | t.true(pathExists.sync('temp/sindresorhus.com-100x100.png')); 7 | }); 8 | 9 | test('multiple URLs', t => { 10 | t.true(pathExists.sync('temp/github.com-1000x1000.png')); 11 | t.true(pathExists.sync('temp/google.com-1000x1000.png')); 12 | }); 13 | 14 | test('`filename` option', t => { 15 | t.true(pathExists.sync('temp/filename-option-sindresorhus.com.png')); 16 | }); 17 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | - push 4 | - pull_request 5 | jobs: 6 | test: 7 | name: Node.js ${{ matrix.node-version }} 8 | runs-on: macos-latest 9 | strategy: 10 | fail-fast: false 11 | matrix: 12 | node-version: 13 | - 14 14 | - 12 15 | - 10 16 | - 8 17 | steps: 18 | - uses: actions/checkout@v2 19 | - uses: actions/setup-node@v1 20 | with: 21 | node-version: ${{ matrix.node-version }} 22 | - run: npm install 23 | - run: npm test 24 | -------------------------------------------------------------------------------- /gruntfile.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | module.exports = grunt => { 3 | grunt.initConfig({ 4 | pageres: { 5 | screenshot: { 6 | options: { 7 | urls: 'https://sindresorhus.com', 8 | sizes: [ 9 | '1000x1000', 10 | '100x100' 11 | ], 12 | dest: 'temp' 13 | } 14 | }, 15 | multipleUrls: { 16 | options: { 17 | urls: [ 18 | 'https://github.com', 19 | 'https://google.com' 20 | ], 21 | sizes: [ 22 | '1000x1000' 23 | ], 24 | dest: 'temp' 25 | } 26 | }, 27 | filenameOption: { 28 | options: { 29 | urls: [ 30 | 'https://sindresorhus.com' 31 | ], 32 | sizes: [ 33 | '1000x1000' 34 | ], 35 | filename: 'filename-option-{{url}}', 36 | dest: 'temp' 37 | } 38 | } 39 | } 40 | }); 41 | 42 | grunt.loadTasks('tasks'); 43 | grunt.registerTask('default', ['pageres']); 44 | }; 45 | -------------------------------------------------------------------------------- /tasks/pageres.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const Pageres = require('pageres'); 3 | const arrify = require('arrify'); 4 | 5 | module.exports = grunt => { 6 | grunt.registerMultiTask('pageres', 'Capture website screenshots', function () { 7 | const done = this.async(); 8 | const options = this.options(); 9 | 10 | if (!options.urls || !options.sizes || !options.dest) { 11 | grunt.warn('The `url`, `sizes`, and `dest` options are required'); 12 | done(); 13 | return; 14 | } 15 | 16 | // Grunt uses the standard lodash template syntax already 17 | if (options.filename) { 18 | options.filename = options.filename.replace(/\{\{([^{]+)\}\}/g, '<%= $1 %>'); 19 | } 20 | 21 | const pageres = new Pageres(options); 22 | 23 | for (const url of arrify(options.urls)) { 24 | pageres.src(url, options.sizes); 25 | } 26 | 27 | pageres.dest(options.dest); 28 | 29 | (async () => { 30 | try { 31 | await pageres.run(); 32 | pageres.successMessage(); 33 | done(); 34 | } catch (error) { 35 | grunt.warn(error); 36 | } 37 | })(); 38 | }); 39 | }; 40 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Sindre Sorhus (sindresorhus.com) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "grunt-pageres", 3 | "version": "4.0.1", 4 | "description": "Capture website screenshots", 5 | "license": "MIT", 6 | "repository": "sindresorhus/grunt-pageres", 7 | "author": { 8 | "name": "Sindre Sorhus", 9 | "email": "sindresorhus@gmail.com", 10 | "url": "sindresorhus.com" 11 | }, 12 | "engines": { 13 | "node": ">=8" 14 | }, 15 | "scripts": { 16 | "test": "xo && grunt && ava && del-cli temp" 17 | }, 18 | "files": [ 19 | "tasks" 20 | ], 21 | "keywords": [ 22 | "gruntplugin", 23 | "pageres", 24 | "page", 25 | "website", 26 | "site", 27 | "web", 28 | "url", 29 | "resolution", 30 | "size", 31 | "screenshot", 32 | "screenshots", 33 | "screengrab", 34 | "screen", 35 | "snapshot", 36 | "shot", 37 | "responsive", 38 | "gulpfriendly", 39 | "puppeteer", 40 | "chrome", 41 | "image", 42 | "svg", 43 | "render", 44 | "html", 45 | "headless", 46 | "capture", 47 | "pic", 48 | "picture", 49 | "png", 50 | "jpg", 51 | "jpeg" 52 | ], 53 | "dependencies": { 54 | "arrify": "^1.0.0", 55 | "pageres": "^5.0.1" 56 | }, 57 | "devDependencies": { 58 | "ava": "^1.2.0", 59 | "del-cli": "^1.1.0", 60 | "grunt": "^1.0.1", 61 | "grunt-cli": "^1.2.0", 62 | "path-exists": "^3.0.0", 63 | "xo": "^0.24.0" 64 | }, 65 | "peerDependencies": { 66 | "grunt": ">=1" 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # grunt-pageres 2 | 3 | [](https://github.com/sindresorhus/pageres) 4 | 5 | > Capture website screenshots using [`pageres`](https://github.com/sindresorhus/pageres) 6 | 7 | *Issues should be opened on the pageres [issue tracker](https://github.com/sindresorhus/pageres/issues).* 8 | 9 | [Using another task runner?](https://github.com/sindresorhus/pageres#task-runners) 10 | 11 | ## Install 12 | 13 | ``` 14 | $ npm install --save-dev grunt-pageres 15 | ``` 16 | 17 | Note to Linux users: If you get a "No usable sandbox!" error, you need to enable [system sandboxing](https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md#setting-up-chrome-linux-sandbox). 18 | 19 | ## Usage 20 | 21 | ```js 22 | require('load-grunt-tasks')(grunt); 23 | 24 | grunt.initConfig({ 25 | pageres: { 26 | screenshot: { 27 | options: { 28 | urls: 'https://sindresorhus.com', 29 | sizes: [ 30 | '1200x800', 31 | '800x600' 32 | ], 33 | dest: 'dist' 34 | } 35 | }, 36 | multipleUrls: { 37 | options: { 38 | urls: [ 39 | 'https://sindresorhus.com', 40 | 'https://google.com' 41 | ], 42 | sizes: [ 43 | '800x1000', 44 | '400x1000' 45 | ], 46 | dest: 'dist', 47 | crop: true 48 | } 49 | } 50 | } 51 | }); 52 | 53 | grunt.registerTask('default', ['pageres']); 54 | ``` 55 | 56 | ## Options 57 | 58 | ### urls 59 | 60 | *Required*\ 61 | Type: `string | string[]` 62 | 63 | One or more URLs or local paths to the websites you want to screenshot. 64 | 65 | ### sizes 66 | 67 | *Required*\ 68 | Type: `string[]` 69 | 70 | Use a `x` notation or a keyword. 71 | 72 | A keyword is a version of a device. You can also pass in the `w3counter` keyword to use the ten most popular resolutions from [w3counter](https://www.w3counter.com/globalstats.php). 73 | 74 | ### dest 75 | 76 | *Required*\ 77 | Type: `string` 78 | 79 | Destination directory. 80 | 81 | ### delay 82 | 83 | Type: `number` *(seconds)*\ 84 | Default: `0` 85 | 86 | Delay capturing the screenshot. 87 | 88 | Useful when the site does things after load that you want to capture. 89 | 90 | ### timeout 91 | 92 | Type: `number` *(seconds)*\ 93 | Default: `60` 94 | 95 | Number of seconds after which the request is aborted. 96 | 97 | ### crop 98 | 99 | Type: `boolean`\ 100 | Default: `false` 101 | 102 | Crop to the set height. 103 | 104 | ### css 105 | 106 | Type: `string` 107 | 108 | Apply custom CSS to the webpage. Specify some CSS or the path to a CSS file. 109 | 110 | ### script 111 | 112 | Type: `string` 113 | 114 | Apply custom JavaScript to the webpage. Specify some JavaScript or the path to a file. 115 | 116 | ### cookies 117 | 118 | Type: `Array` 119 | 120 | A string with the same format as a [browser cookie](https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies) or [an object](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#pagesetcookiecookies). 121 | 122 | Tip: Go to the website you want a cookie for and [copy-paste it from DevTools](https://stackoverflow.com/a/24961735/64949). 123 | 124 | ### filename 125 | 126 | Type: `string` 127 | 128 | Define a customized filename using templating.\ 129 | For example `{{date}} - {{url}}-{{size}}{{crop}}`. 130 | 131 | Available variables: 132 | 133 | - `url`: The URL in [slugified](https://github.com/sindresorhus/filenamify-url) form, eg. `https://yeoman.io/blog/` becomes `yeoman.io!blog` 134 | - `size`: Specified size, eg. `1024x1000` 135 | - `width`: Width of the specified size, eg. `1024` 136 | - `height`: Height of the specified size, eg. `1000` 137 | - `crop`: Outputs `-cropped` when the crop option is true 138 | - `date`: The current date (Y-M-d), eg. 2015-05-18 139 | - `time`: The current time (h-m-s), eg. 21-15-11 140 | 141 | ### incrementalName 142 | 143 | Type: `boolean`\ 144 | Default: `false` 145 | 146 | When a file exists, append an incremental number. 147 | 148 | ### selector 149 | 150 | Type: `string` 151 | 152 | Capture a specific DOM element matching a CSS selector. 153 | 154 | ### hide 155 | 156 | Type: `string[]` 157 | 158 | Hide an array of DOM elements matching CSS selectors. 159 | 160 | ### username 161 | 162 | Type: `string` 163 | 164 | Username for authenticating with HTTP auth. 165 | 166 | ### password 167 | 168 | Type: `string` 169 | 170 | Password for authenticating with HTTP auth. 171 | 172 | ### scale 173 | 174 | Type: `number`\ 175 | Default: `1` 176 | 177 | Scale webpage `n` times. 178 | 179 | ### format 180 | 181 | Type: `string`\ 182 | Default: `png`\ 183 | Values: `'png' | 'jpg'` 184 | 185 | Image format. 186 | 187 | ### userAgent 188 | 189 | Type: `string` 190 | 191 | Custom user agent. 192 | 193 | ### headers 194 | 195 | Type: `object` 196 | 197 | Custom HTTP request headers. 198 | 199 | ### transparent 200 | 201 | Type: `boolean`\ 202 | Default: `false` 203 | 204 | Set background color to `transparent` instead of `white` if no background is set. 205 | --------------------------------------------------------------------------------