/puppeteer-extra-plugin-session

WIP: session persistence plugin for puppeteer-extra

Primary LanguageTypeScript

puppeteer-extra-plugin-session

warning sign

⚠️ This is a WIP: this works but you should probably not use it ⚠️

Introduction

Dump and restore session data from your puppeteer pages.

This plugin supports:

  • cookies
  • localStorage
  • sessionStorage
  • IndexedDB (you'll need to specify the securityOrigin of the databases to dump)

Installation

yarn add puppeteer-extra-plugin-session
# or
npm install puppeteer-extra-plugin-session

Usage

First of all, you have to register the plugin with puppeteer-extra.

JavaScript:

puppeteer.use(require('puppeteer-extra-plugin-session')())

TypeScript:

import SessionPlugin from 'puppeteer-extra-plugin-session';
puppeteer.use(SessionPlugin())

Then, you'll have access to session data helpers:

const securityOrigin = "https://github.com"; // security origin of the target IndexedDB
const sessionData = await page.sessionManager.dump(); // or page.sessionManager.dumpString()

// [...]

await page.sessionManager.restore(sessionData); // or page.sessionManager.restoreString(sessionData)

Testing

Tests are defined in *.spec.ts files.

You can run the tests watcher using yarn test or npm run test

Debugging

You can see the package's logs by setting the DEBUG=puppeteer-extra-plugin:session env variable.

Example: DEBUG=puppeteer-extra-plugin:session npm test

Base Puppeteer-Extra Plugin System

See the core Puppeteer-Extra Plugin docs for additional information: https://github.com/berstend/puppeteer-extra/tree/master/packages/puppeteer-extra-plugin

Contributing

We appreciate all contributions.

See TODO.md

License

MIT

Resources