@@ -23,6 +23,7 @@
|
|||||||
"lerna": "^4.0.0"
|
"lerna": "^4.0.0"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"lerna": "lerna"
|
"lerna": "lerna",
|
||||||
|
"repl": "cd packages/rrweb && npm run repl"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
"test": "npm run bundle:browser && jest",
|
"test": "npm run bundle:browser && jest",
|
||||||
"test:headless": "npm run bundle:browser && PUPPETEER_HEADLESS=true jest",
|
"test:headless": "npm run bundle:browser && PUPPETEER_HEADLESS=true jest",
|
||||||
"test:watch": "PUPPETEER_HEADLESS=true npm run test -- --watch",
|
"test:watch": "PUPPETEER_HEADLESS=true npm run test -- --watch",
|
||||||
"repl": "npm run bundle:browser && cross-env TS_NODE_CACHE=false TS_NODE_FILES=true ts-node scripts/repl.ts",
|
"repl": "npm run bundle:browser && node scripts/repl.js",
|
||||||
"bundle:browser": "cross-env BROWSER_ONLY=true rollup --config",
|
"bundle:browser": "cross-env BROWSER_ONLY=true rollup --config",
|
||||||
"bundle": "rollup --config",
|
"bundle": "rollup --config",
|
||||||
"typings": "tsc -d --declarationDir typings",
|
"typings": "tsc -d --declarationDir typings",
|
||||||
|
|||||||
@@ -1,28 +1,27 @@
|
|||||||
/* tslint:disable: no-console */
|
/* tslint:disable: no-console */
|
||||||
|
|
||||||
import * as fs from 'fs';
|
const fs = require('fs');
|
||||||
import * as path from 'path';
|
const path = require('path');
|
||||||
import * as EventEmitter from 'events';
|
const EventEmitter = require('events');
|
||||||
import * as inquirer from 'inquirer';
|
const inquirer = require('inquirer');
|
||||||
import * as puppeteer from 'puppeteer';
|
const puppeteer = require('puppeteer');
|
||||||
import { eventWithTime } from '../src/types';
|
|
||||||
|
|
||||||
const emitter = new EventEmitter();
|
const emitter = new EventEmitter();
|
||||||
|
|
||||||
function getCode(): string {
|
function getCode() {
|
||||||
const bundlePath = path.resolve(__dirname, '../dist/rrweb.min.js');
|
const bundlePath = path.resolve(__dirname, '../dist/rrweb.min.js');
|
||||||
return fs.readFileSync(bundlePath, 'utf8');
|
return fs.readFileSync(bundlePath, 'utf8');
|
||||||
}
|
}
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
const code = getCode();
|
const code = getCode();
|
||||||
let events: eventWithTime[] = [];
|
let events = [];
|
||||||
|
|
||||||
start();
|
start();
|
||||||
|
|
||||||
async function start() {
|
async function start() {
|
||||||
events = [];
|
events = [];
|
||||||
const { url } = await inquirer.prompt<{ url: string }>([
|
const { url } = await inquirer.prompt([
|
||||||
{
|
{
|
||||||
type: 'input',
|
type: 'input',
|
||||||
name: 'url',
|
name: 'url',
|
||||||
@@ -35,7 +34,7 @@ function getCode(): string {
|
|||||||
await record(url);
|
await record(url);
|
||||||
console.log('Ready to record. You can do any interaction on the page.');
|
console.log('Ready to record. You can do any interaction on the page.');
|
||||||
|
|
||||||
const { shouldReplay } = await inquirer.prompt<{ shouldReplay: boolean }>([
|
const { shouldReplay } = await inquirer.prompt([
|
||||||
{
|
{
|
||||||
type: 'confirm',
|
type: 'confirm',
|
||||||
name: 'shouldReplay',
|
name: 'shouldReplay',
|
||||||
@@ -45,7 +44,7 @@ function getCode(): string {
|
|||||||
|
|
||||||
emitter.emit('done', shouldReplay);
|
emitter.emit('done', shouldReplay);
|
||||||
|
|
||||||
const { shouldStore } = await inquirer.prompt<{ shouldStore: boolean }>([
|
const { shouldStore } = await inquirer.prompt([
|
||||||
{
|
{
|
||||||
type: 'confirm',
|
type: 'confirm',
|
||||||
name: 'shouldStore',
|
name: 'shouldStore',
|
||||||
@@ -57,9 +56,7 @@ function getCode(): string {
|
|||||||
saveEvents();
|
saveEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
const { shouldRecordAnother } = await inquirer.prompt<{
|
const { shouldRecordAnother } = await inquirer.prompt([
|
||||||
shouldRecordAnother: boolean;
|
|
||||||
}>([
|
|
||||||
{
|
{
|
||||||
type: 'confirm',
|
type: 'confirm',
|
||||||
name: 'shouldRecordAnother',
|
name: 'shouldRecordAnother',
|
||||||
@@ -74,7 +71,7 @@ function getCode(): string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function record(url: string) {
|
async function record(url) {
|
||||||
const browser = await puppeteer.launch({
|
const browser = await puppeteer.launch({
|
||||||
headless: false,
|
headless: false,
|
||||||
defaultViewport: {
|
defaultViewport: {
|
||||||
@@ -90,9 +87,10 @@ function getCode(): string {
|
|||||||
const page = await browser.newPage();
|
const page = await browser.newPage();
|
||||||
await page.goto(url, {
|
await page.goto(url, {
|
||||||
waitUntil: 'domcontentloaded',
|
waitUntil: 'domcontentloaded',
|
||||||
|
timeout: 300000,
|
||||||
});
|
});
|
||||||
|
|
||||||
await page.exposeFunction('_replLog', (event: eventWithTime) => {
|
await page.exposeFunction('_replLog', (event) => {
|
||||||
events.push(event);
|
events.push(event);
|
||||||
});
|
});
|
||||||
await page.evaluate(`;${code}
|
await page.evaluate(`;${code}
|
||||||
Reference in New Issue
Block a user