Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

capture-website

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

capture-website - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

26

index.js

@@ -5,8 +5,10 @@ 'use strict';

const fileUrl = require('file-url');
const isUrl = require('is-url-superb');
const puppeteer = require('puppeteer');
const devices = require('puppeteer/DeviceDescriptors');
const toughCookie = require('tough-cookie');
const writeFile = promisify(fs.writeFile);
const isUrl = string => /^(https?|file):\/\/|^data:/.test(string);
const hideElements = elements => {

@@ -29,2 +31,21 @@ for (const element of elements) {

const parseCookie = (url, cookie) => {
if (typeof cookie === 'object') {
return cookie;
}
const jar = new toughCookie.CookieJar(undefined, {rejectPublicSuffixes: false});
jar.setCookieSync(cookie, url);
const ret = jar.serializeSync().cookies[0];
// Use this instead of the above when the following issue is fixed:
// https://github.com/salesforce/tough-cookie/issues/149
// const ret = toughCookie.parse(cookie).serializeSync();
ret.name = ret.key;
delete ret.key;
return ret;
};
const captureWebsite = async (url, options) => {

@@ -84,3 +105,4 @@ const finalUrl = isUrl(url) ? url : fileUrl(url);

if (options.cookies) {
await page.setCookie(...options.cookies);
const cookies = options.cookies.map(cookie => parseCookie(finalUrl, cookie));
await page.setCookie(...cookies);
}

@@ -87,0 +109,0 @@

7

package.json
{
"name": "capture-website",
"version": "0.1.0",
"version": "0.1.1",
"description": "Capture screenshots of websites",

@@ -38,4 +38,4 @@ "license": "MIT",

"file-url": "^2.0.2",
"is-url-superb": "^2.0.0",
"puppeteer": "^1.12.2"
"puppeteer": "^1.12.2",
"tough-cookie": "^3.0.1"
},

@@ -52,5 +52,4 @@ "devDependencies": {

"tempy": "^0.2.1",
"tough-cookie": "^3.0.1",
"xo": "^0.24.0"
}
}

@@ -52,3 +52,3 @@ # capture-website [![Build Status](https://travis-ci.com/sindresorhus/capture-website.svg?branch=master)](https://travis-ci.com/sindresorhus/capture-website)

The URL or local file path to the website.
The URL, file URL, data URL, or local file path to the website.

@@ -285,6 +285,28 @@ ```js

Type: `Object[]`
Type: `Array<string | Object>`
Set cookies in the [following format](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#pagesetcookiecookies).
Set cookies in [browser string format](https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies) or [object format](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#pagesetcookiecookies).
Tip: Go to the website you want a cookie for and [copy-paste it from DevTools](https://stackoverflow.com/a/24961735/64949).
```js
const captureWebsite = require('capture-website');
(async () => {
await captureWebsite.file('https://sindresorhus.com', 'screenshot.png', {
cookies: [
// This format is useful for when you copy it from the browser
'id=unicorn; Expires=Wed, 21 Oct 2018 07:28:00 GMT;',
// This format is useful for when you have to manually create a cookie
{
name: 'id',
value: 'unicorn',
expires: Math.round(new Date('2018-10-21').getTime() / 1000)
}
]
});
})();
```
##### authentication

@@ -291,0 +313,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc