Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added scripts for saving and viewing snapshots #863

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

croqaz
Copy link
Contributor

@croqaz croqaz commented Mar 23, 2022

Hi. I wanted to share these 2 useful scripts that I actually use.
They can showcase how to use rrWeb, and the script for viewing snapshots is really useful in debug.
The scripts are kind of rough. I didn't want to use any special CLI flag parsing libraries, but maybe they are useful? Any suggestions are welcome.

args: [
'--disable-breakpad',
'--disable-default-apps',
'--disable-features=IsolateOrigins,site-per-process',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These flags are pretty important to allow loading of CORS resouces like images and CSS. A lot of capturing of styles and inline images depends on these args.

}

// hack all images with img.crossOrigin="anonymous" before calling snapshot
// this is MANDATORY to capture images from websites that host images on CDNs
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't hack all the images with crossOrigin = 'anonymous', a LOT of websites with images won't work, the images will not be saved inline.

await page.evaluate(`(function(){
console.log('Restoring the snaphot...');
${rrCode};
rrwebSnapshot.rebuild(${snap}, {doc: document});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively I'm thinking it makes sense to process the snapshot and generate HTML in a local /tmp folder and point Pupeteer at the local file.
The advantage is you can click on some links in the temp page and then return back to the snapshot. Currently the page is restored in a blank tab, so if you click on anything, you just can't go back to the snapshot, it's just a blank page.

@Juice10
Copy link
Contributor

Juice10 commented Mar 29, 2022

Hi @croqaz, thanks for sharing your scripts, very interesting to see how you are using rrweb-snapshots. And I agree that it might help people use rrweb-snapshots themselves.

For consistency with packages/rrweb and yarn repl, it would be nice if we could rename the script folder to scripts and remove rrweb_ from the filenames of your scripts. It would also be perfect if the output files of these scripts would be saved to packages/rrweb-snapshot/temp/.

The last thing missing to really makes it consistent with yarn repl would be to also add these scripts as a package.json script. Example:

"repl": "npm run bundle:browser && node scripts/repl.js",

@croqaz
Copy link
Contributor Author

croqaz commented Mar 30, 2022

Thank you for the comment @Juice10 , it sounds great and I implemented everything.
I also added a shortcut command for generating the dist/rrweb-snapshot.js file, I hope that's OK.
I think I only need to use the /temp/ file that you mentioned.

@Yuyz0112
Copy link
Member

Yuyz0112 commented Apr 9, 2022

@croqaz Thanks for the PR! Do you mind updating the script usage from yarn snapshot and yarn rebuild to yarn repl snapshot and yarn repl rebuild? This will help us keep the script's entry minimal.

If so, I can help with this change.

@croqaz
Copy link
Contributor Author

croqaz commented Apr 11, 2022

@croqaz Thanks for the PR! Do you mind updating the script usage from yarn snapshot and yarn rebuild to yarn repl snapshot and yarn repl rebuild? This will help us keep the script's entry minimal.

I don't think I mind if that helps, but from I could look at the rest of the repl commands, they are located in packages/rrweb.
Doesn't that make running these scripts much more complicated? Or we should move them in that folder as well?

@Yuyz0112
Copy link
Member

@croqaz IMO, I think npm scripts are a set of scripts to maintain the package, like dev/test/build/etc. And in this use case, I think the snapshot/rebuild commands are good for doing some quick tests with the code, so I propose to move these kinds of commands to the category of repl, which means a simple interactive env to play the code.

If we create a tool called rrweb-snapshot-cli, then two top-level commands, snapshot and rebuild, make great sense.

Copy link
Contributor Author

@croqaz croqaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I cannot comment for some reason.
I will work on this next week.

@Juice10
Copy link
Contributor

Juice10 commented Apr 18, 2024

FYI: #1033 will get merged soon which will change the build command to yarn build and the location of the rrweb-snapshot.js to dist/rrweb-snapshot.umd.cjs. That will impact this PR a little bit

@croqaz
Copy link
Contributor Author

croqaz commented Apr 18, 2024

Hi folks! I don't use rrweb for a very long time and I won't be working on this PR anymore.
Not sure if I should close the PR... maybe somebody else can pickup the scripts and continue building? They personally helped me a lot, but maybe other people have a different way of working with this.
Anyway, feel free to close this! Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants