puppeteer-extra-plugin-session
Version:
A puppeteer plugin to dump and inject session data.
56 lines • 2.55 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const puppeteer_extra_1 = __importDefault(require("puppeteer-extra"));
const puppeteer_extra_plugin_stealth_1 = __importDefault(require("puppeteer-extra-plugin-stealth"));
const constants_1 = require("../constants/constants");
const plugin_1 = require("../plugin/plugin");
const TESTING_URL = 'https://twitter.com';
jest.setTimeout(15000);
let browser;
let page;
puppeteer_extra_1.default.use(new plugin_1.SessionPlugin()).use((0, puppeteer_extra_plugin_stealth_1.default)());
beforeAll(async () => {
browser = await puppeteer_extra_1.default.launch({
headless: true,
executablePath: constants_1.TestBrowserExecutablePath,
args: ['--no-sandbox'],
});
});
beforeEach(async () => {
page = await browser.newPage();
await page.goto(TESTING_URL, { waitUntil: 'networkidle2' });
});
afterAll(async () => {
await (browser === null || browser === void 0 ? void 0 : browser.close());
});
it('can get localdb', async () => {
var _a;
const session = await page.session.dump();
// the db exist and was obtained
// note(clouedoc): long string, just making sure it's the exact same length than the one I get under normal conditions
expect((_a = session.indexedDB) === null || _a === void 0 ? void 0 : _a.length).toBe(335);
expect(JSON.parse(session.indexedDB).some((db) => db.name === 'localforage')).toBe(true);
});
it('can set indexDB', async () => {
const session = await page.session.dump();
expect(JSON.parse(session.indexedDB).some((db) => db.name === 'localforage')).toBe(true);
// Delete the database using CDP
const client = await page.target().createCDPSession();
await client.send('IndexedDB.deleteDatabase', {
databaseName: 'localforage',
securityOrigin: TESTING_URL,
});
await client.detach();
// Dump the session again to make sure there is no localforage
const emptySession = await page.session.dump();
expect(JSON.parse(emptySession.indexedDB).some((db) => db.name === 'localforage')).toBe(false);
// Restore the indexedDB
await page.session.restore(session);
// Check to make sure the db was restored
const finalSession = await page.session.dump();
expect(JSON.parse(finalSession.indexedDB).some((db) => db.name === 'localforage')).toBe(true);
});
//# sourceMappingURL=indexedDb.spec.js.map