{"id":20767029,"url":"https://github.com/binded/webcap","last_synced_at":"2025-03-11T18:51:31.437Z","repository":{"id":97906444,"uuid":"69636326","full_name":"binded/webcap","owner":"binded","description":"DEPRECATED","archived":false,"fork":false,"pushed_at":"2018-04-28T04:09:25.000Z","size":17,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-01-18T06:28:14.938Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/binded.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-09-30T05:23:19.000Z","updated_at":"2017-04-19T23:09:12.000Z","dependencies_parsed_at":null,"dependency_job_id":"d2954c4f-d4aa-412c-a61c-10438da58263","html_url":"https://github.com/binded/webcap","commit_stats":null,"previous_names":["blockai/webcap"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binded%2Fwebcap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binded%2Fwebcap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binded%2Fwebcap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binded%2Fwebcap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/binded","download_url":"https://codeload.github.com/binded/webcap/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243094622,"owners_count":20235531,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-17T11:27:21.835Z","updated_at":"2025-03-11T18:51:31.411Z","avatar_url":"https://github.com/binded.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/blockai/webcap.svg?branch=master)](https://travis-ci.org/blockai/webcap)\n\n# Webcap\n\nWebcap (for **web** screen **cap**ture) is a fork of [node-webshot](https://github.com/brenden/node-webshot) which\nappears to be dead unfortunately. This forks adds:\n\n- Streams now emits errors instead of ending silently\n\nWebcap provides a simple API for taking webpage screenshots. The module is a\nlight wrapper around PhantomJS, which utilizes WebKit to perform the page\nrendering.\n\n## Examples\n\nA simple url example:\n\n```javascript\nvar webcap = require('webcap');\n\nwebcap('google.com', 'google.png', function(err) {\n  // screenshot now saved to google.png\n});\n```\n\nAn html example:\n\n```javascript\nvar webcap = require('webcap');\n\nwebcap('\u003chtml\u003e\u003cbody\u003eHello World\u003c/body\u003e\u003c/html\u003e', 'hello_world.png', {siteType:'html'}, function(err) {\n  // screenshot now saved to hello_world.png\n});\n```\n\nAlternately, the screenshot can be streamed back to the caller:\n\n```javascript\nvar webcap = require('webcap');\nvar fs      = require('fs');\n\nvar renderStream = webcap('google.com');\nvar file = fs.createWriteStream('google.png', {encoding: 'binary'});\n\nrenderStream.on('data', function(data) {\n  file.write(data.toString('binary'), 'binary');\n});\n```\n\nAn example showing how to take a screenshot of a site's mobile version:\n\n```javascript\nvar webcap = require('webcap');\n\nvar options = {\n  screenSize: {\n    width: 320\n  , height: 480\n  }\n, shotSize: {\n    width: 320\n  , height: 'all'\n  }\n, userAgent: 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_2 like Mac OS X; en-us)'\n    + ' AppleWebKit/531.21.20 (KHTML, like Gecko) Mobile/7B298g'\n};\n\nwebcap('flickr.com', 'flickr.jpeg', options, function(err) {\n  // screenshot now saved to flickr.jpeg\n});\n```\n\n## Options\nAn optional `options` object can be passed as the parameter directly preceding\nthe callback in a call to webcap.\n\n\u003ctable\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth\u003eOption\u003c/th\u003e\n      \u003cth\u003eDefault Value\u003c/th\u003e\n      \u003cth\u003eDescription\u003c/th\u003e\n    \u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003cth\u003ewindowSize\u003c/th\u003e\n      \u003ctd\u003e\n\u003cpre\u003e{ width: 1024\n, height: 768 }\u003c/pre\u003e\n      \u003c/td\u003e\n      \u003ctd\u003eThe dimensions of the browser window. \u003cem\u003escreenSize\u003c/em\u003e is an alias\n      for this property.\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003cth\u003eshotSize\u003c/th\u003e\n      \u003ctd\u003e\n\u003cpre\u003e{ width: 'window'\n, height: 'window' }\u003c/pre\u003e\n      \u003c/td\u003e\n      \u003ctd\u003eThe area of the page document, starting at the upper left corner, to\n      render. Possible values are 'screen', 'all', and a number defining a\n      pixel length.\n      \u003cbr /\u003e \u003cbr /\u003e\n      \u003cstrong\u003e'window'\u003c/strong\u003e causes the length to be set to the length of\n      the window (i.e. the shot displays what is initially visible within the\n      browser window).\n      \u003cbr /\u003e \u003cbr /\u003e\n      \u003cstrong\u003e'all'\u003c/strong\u003e causes the length to be set to the length of the\n      document along the given dimension. \u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003cth\u003eshotOffset\u003c/th\u003e\n      \u003ctd\u003e\u003cpre\u003e{ left: 0\n, right: 0\n, top: 0\n, bottom: 0 }\u003c/pre\u003e\u003c/td\u003e\n      \u003ctd\u003eThe left and top offsets define the upper left corner of the\n      screenshot rectangle. The right and bottom offsets allow pixels to be\n      removed from the shotSize dimensions (e.g. a shotSize height of 'all' with\n      a bottom offset of 30 would cause all but the last 30 rows of pixels on\n      the site to be rendered).\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003cth\u003ephantomPath\u003c/th\u003e\n      \u003ctd\u003e'phantomjs'\u003c/td\u003e\n      \u003ctd\u003eThe location of phantomjs. Webcap tries to use the binary provided by\n      the phantomjs NPM module, and falls back to 'phantomjs' if the module\n      isn't available.\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003cth\u003ephantomConfig\u003c/th\u003e\n      \u003ctd\u003e{}\u003c/td\u003e\n      \u003ctd\u003eObject with key value pairs corresponding to phantomjs \u003ca\n      href=\"http://phantomjs.org/api/command-line.html\"\u003ecommand\n      line options\u003c/a\u003e. Don't include `--`. For example:\n      `phantomConfig: {'ignore-ssl-errors': 'true'}`\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003cth\u003ecookies\u003c/th\u003e\n      \u003ctd\u003e[]\u003c/td\u003e\n      \u003ctd\u003eList of cookie objects to use, or null to disable cookies.\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003cth\u003ecustomHeaders\u003c/th\u003e\n      \u003ctd\u003enull\u003c/td\u003e\n      \u003ctd\u003eAny additional headers to be sent in the HTTP request.\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003cth\u003edefaultWhiteBackground\u003c/th\u003e\n      \u003ctd\u003efalse\u003c/td\u003e\n      \u003ctd\u003eWhen taking the screenshot, adds a white background if not defined\n      elsewhere.\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003cth\u003ecustomCSS\u003c/th\u003e\n      \u003ctd\u003e''\u003c/td\u003e\n      \u003ctd\u003eWhen taking the screenshot, adds custom CSS rules if defined.\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003cth\u003equality\u003c/th\u003e\n      \u003ctd\u003e75\u003c/td\u003e\n      \u003ctd\u003eJPEG compression quality. A higher number will look better, but creates\n        a larger file. Quality setting has no effect when streaming.\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003cth\u003estreamType\u003c/th\u003e\n      \u003ctd\u003e'png'\u003c/td\u003e\n      \u003ctd\u003eIf streaming is used, this designates the file format of the streamed\n      rendering. Possible values are 'png', 'jpg', and 'jpeg'.  \u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003cth\u003esiteType\u003c/th\u003e\n      \u003ctd\u003e'url'\u003c/td\u003e\n      \u003ctd\u003esiteType indicates whether the content needs to be requested ('url'),\n      loaded locally ('file'), or is being provided directly as a string\n      ('html').\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003cth\u003erenderDelay\u003c/th\u003e\n      \u003ctd\u003e0\u003c/td\u003e\n      \u003ctd\u003eNumber of milliseconds to wait after a page loads before taking the\n      screenshot.\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003cth\u003etimeout\u003c/th\u003e\n      \u003ctd\u003e0\u003c/td\u003e\n      \u003ctd\u003eNumber of milliseconds to wait before killing the phantomjs process\n      and assuming web shotting has failed.  (0 is no timeout.)\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003cth\u003etakeShotOnCallback\u003c/th\u003e\n      \u003ctd\u003efalse\u003c/td\u003e\n      \u003ctd\u003eWait for the web page to signal to webcap when to take the photo\n      using \u003ccode\u003ewindow.callPhantom('takeShot');\u003c/code\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003cth\u003eerrorIfStatusIsNot200\u003c/th\u003e\n      \u003ctd\u003efalse\u003c/td\u003e\n      \u003ctd\u003eIf the loaded page has a non-200 status code, don't take a screenshot, cause an error instead.\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003cth\u003eerrorIfJSException\u003c/th\u003e\n      \u003ctd\u003efalse\u003c/td\u003e\n      \u003ctd\u003eIf a script on the page throws an exception, don't take a screenshot, cause an error instead.\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003cth\u003ecaptureSelector\u003c/th\u003e\n      \u003ctd\u003efalse\u003c/td\u003e\n      \u003ctd\u003eCaptures the page area containing the provided selector and saves it to file.\u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\n### PhantomJS version\n\nBy default this package installs PhantomJS 1.9.x. Several issues exist\nin this version that are fixed in v2, but v2 is not yet stable across\nall platforms. The `phantomPath` option can be used to get around this\nif you want to try a more recent PhantomJS version. See this issue:\nhttps://github.com/brenden/node-webshot/issues/100\n\n### Phantom page properties\nIn addition to these options, the following options can be specified and will be\npassed to the [Phantom page\nobject](https://github.com/ariya/phantomjs/wiki/API-Reference-WebPage):\n`paperSize`, `zoomFactor`, `cookies`, `customHeaders`, and `settings`.\n\n### Phantom callbacks\nArbitrary scripts can be run on the page before it gets rendered by using any of\nPhantom's [page callbacks](https://github.com/ariya/phantomjs/wiki/API-Reference-WebPage#callbacks-list),\nsuch as `onLoadFinished` or `onResourceRequested`. For example, the script below\nchanges the text of every link on the page:\n\n```javascript\nvar options = {\n  onLoadFinished: function() {\n    var links = document.getElementsByTagName('a');\n\n    for (var i=0; i\u003clinks.length; i++) {\n      var link = links[i];\n      link.innerHTML = 'My custom text';\n    }\n  }\n};\n```\n\nNote that the script will be serialized and then passed to Phantom as text, so all\nvariable scope information will be lost. However, variables from the caller can be\npassed into the script as follows:\n\n```javascript\nvar options = {\n  onLoadFinished: {\n    fn: function() {\n      var links = document.getElementsByTagName('a');\n\n      for (var i=0; i\u003clinks.length; i++) {\n        var link = links[i];\n        link.innerHTML = this.foo;\n      }\n    }\n  , context: {foo: 'My custom text'}\n  }\n};\n```\n\n## Tests\n\nTests are written with [Mocha](http://visionmedia.github.com/mocha/) and can be\nrun with `npm test`. The tests use [node-imagemagick](http://github.com/rsms/node-imagemagick) and thus require\nthat the [imagemagick CLI tools](http://www.imagemagick.org) be installed.\n\n## Running on Heroku\n\n[See this comment.](https://github.com/brenden/node-webshot/issues/25#issuecomment-23019665)\n\n## License\n\n```\n(The MIT License)\n\nCopyright (c) 2012 Brenden Kokoszka \u0026 contributors\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the 'Software'), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbinded%2Fwebcap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbinded%2Fwebcap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbinded%2Fwebcap/lists"}