Skip to content

Commit

Permalink
feat: Upgrade to rrweb2 (#107)
Browse files Browse the repository at this point in the history
Brings this library up to date w/ upstream. Includes additional commits for enhanced privacy and Sentry release workflows.

Cherry picks include the following upstream PRs:

* rrweb-io#1096
* rrweb-io#1155
* rrweb-io#1257
* rrweb-io#1262


Cherry picks from getsentry fork:
* #70
* #103
*
064d8c4
*
e274f88
*
cffefa2
* #20

---------

Co-authored-by: Michael Dellanoce <mdellanoce@pendo.io>
Co-authored-by: mdellanoce <mdellanoce@users.noreply.github.com>
Co-authored-by: Yun Feng <yun.feng0817@gmail.com>
Co-authored-by: Francesco Novy <francesco.novy@sentry.io>
Co-authored-by: Lukas Stracke <lukas.stracke@sentry.io>
  • Loading branch information
6 people authored Sep 21, 2023
1 parent 58c9104 commit 5f5c00d
Show file tree
Hide file tree
Showing 141 changed files with 14,631 additions and 4,163 deletions.
5 changes: 5 additions & 0 deletions .changeset/fluffy-planes-retire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'rrweb': patch
---

Feat: Add support for replaying :defined pseudo-class of custom elements
6 changes: 6 additions & 0 deletions .changeset/little-moons-camp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'rrweb-snapshot': minor
'rrweb': minor
---

feat: Better masking of option/radio/checkbox values
7 changes: 7 additions & 0 deletions .changeset/smart-ears-refuse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'rrweb-snapshot': patch
---

Feat: Add 'isCustom' flag to serialized elements.

This flag is used to indicate whether the element is a custom element or not. This is useful for replaying the :defined pseudo-class of custom elements.
6 changes: 6 additions & 0 deletions .changeset/twenty-tables-call.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'rrweb-snapshot': patch
'rrweb': patch
---

Add `maskAttributesFn` to be called when transforming an attribute. This is typically used to determine if an attribute should be masked or not.
15 changes: 15 additions & 0 deletions .craft.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
github:
owner: getsentry
repo: rrweb
changelogPolicy: none
preReleaseCommand: bash scripts/craft-pre-release.sh
requireNames:
- /^sentry-internal-rrweb-snapshot-.*\.tgz$/
- /^sentry-internal-rrweb-player-.*\.tgz$/
- /^sentry-internal-rrweb-.*\.tgz$/
- /^sentry-internal-rrdom-.*\.tgz$/
targets:
- name: github
includeNames: /^sentry-.*.tgz$/
- name: npm
includeNames: /^sentry-.*.tgz$/
43 changes: 40 additions & 3 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
name: Tests
name: Build & Tests

on: [push, pull_request]
on:
push:
branches:
- master
- release/**
pull_request:

concurrency: ${{ github.workflow }}-${{ github.ref }}

jobs:
release:
job_test:
name: Tests
runs-on: ubuntu-latest
steps:
Expand All @@ -19,6 +24,7 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: lts/*
cache: 'yarn'

- name: Install Dependencies
run: yarn install --frozen-lockfile
Expand All @@ -39,3 +45,34 @@ jobs:
name: image-diff
path: packages/rrweb/test/*/__image_snapshots__/__diff_output__/*.png
if-no-files-found: ignore

job_artifacts:
needs: job_test
name: Upload Artifacts
runs-on: ubuntu-latest
# Build artifacts are only needed for releasing workflow.
if: startsWith(github.ref, 'refs/heads/release/')
steps:
- name: Checkout Repo
uses: actions/checkout@v3

- name: Setup Node.js lts/*
uses: actions/setup-node@v3
with:
node-version: lts/*
cache: 'yarn'

- name: Install Dependencies
run: yarn install --frozen-lockfile

- name: Build Tarballs
env:
NODE_OPTIONS: "--max_old_space_size=4096"
run: yarn build:tarball

- name: Upload Artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ github.sha }}
path: |
${{ github.workspace }}/packages/**/*.tgz
55 changes: 23 additions & 32 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,30 @@
name: Release

name: Prepare Release
on:
push:
branches:
- master

concurrency: ${{ github.workflow }}-${{ github.ref }}

workflow_dispatch:
inputs:
version:
description: Version to release
required: true
force:
description: Force a release even when there are release-blockers (optional)
required: false
merge_target:
description: Target branch to merge into. Uses the default branch, sentry-v1, as a fallback (optional)
required: false
jobs:
release:
name: Release
runs-on: ubuntu-latest
name: 'Release a new version'
steps:
- name: Checkout Repo
uses: actions/checkout@v3

- name: Setup Node.js lts/*
uses: actions/setup-node@v3
- uses: actions/checkout@v3
with:
node-version: lts/*

- name: Install Dependencies
run: yarn install --frozen-lockfile

- name: Create Release Pull Request or Publish to npm
id: changesets
uses: changesets/action@v1
with:
publish: yarn run release
token: ${{ secrets.GH_RELEASE_PAT }}
fetch-depth: 0
- name: Prepare release
uses: getsentry/action-prepare-release@v1
env:
NODE_OPTIONS: '--max-old-space-size=4096'
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

# - name: Send a Slack notification if a publish happens
# if: steps.changesets.outputs.published == 'true'
# # You can do something when a publish happens.
# run: my-slack-bot send-notification --message "A new version of ${GITHUB_REPOSITORY} was published!"
GITHUB_TOKEN: ${{ secrets.GH_RELEASE_PAT }}
with:
version: ${{ github.event.inputs.version }}
force: ${{ github.event.inputs.force }}
merge_target: ${{ github.event.inputs.merge_target }}
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# Changelog

## 2.0.0-beta11.0

- Sentry fork of rrweb@2.0.0-alpha.11 with additional masking features

## v1.0.0

### Featrues & Improvements
### Features & Improvements

- Support record same-origin non-sandboxed iframe.
- Support record open-mode shadow DOM.
Expand Down
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
This project is forked from rrweb-io/rrweb (https://github.com/rrweb-io/rrweb) under the MIT license:

MIT License

Copyright (c) 2018 Contributors (https://github.com/rrweb-io/rrweb/graphs/contributors) and SmartX Inc.
Expand All @@ -19,3 +21,22 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Our modifications to this project are also released under the MIT license:

Copyright (c) 2023 Functional Software, Inc. dba Sentry

Permission is hereby granted, free of charge, to any person obtaining a copy of this software
and associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial
portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,30 @@
<p align="center">
<a href="https://sentry.io/?utm_source=github&utm_medium=logo" target="_blank">
<img src="https://sentry-brand.storage.googleapis.com/sentry-wordmark-dark-280x84.png" alt="Sentry" width="280" height="84">
</a>
</p>

# Sentry rrweb Fork

This repo is a fork of [rrweb](https://github.com/rrweb-io/rrweb). The purpose is to apply patches and bugfixes to rrweb and release Sentry-internal packages with our patches included. All credits and attribution for rrweb go to the original creators of the library and all its contributors.

From this monorepo, Sentry maintains and publishes the following NPM packages:

- `@sentry-internal/rrweb` (corresponds to the [original `rrweb` package](https://www.npmjs.com/package/rrweb))
- `@sentry-internal/rrdom` (corresponds to the [original `rrdom` package](https://www.npmjs.com/package/rrdom))
- `@sentry-internal/rrweb-player` (corresponds to the [original `rrweb-player` package](https://www.npmjs.com/package/rrweb-player))
- `@sentry-internal/rrweb-snapshot` (corresponds to the [original `rrweb-snapshot` package](https://www.npmjs.com/package/rrweb-snapshot))

# rrweb

<p align="center">
<img width="100px" height="100px" src="https://www.rrweb.io/favicon.png">
</p>
<p align="center">
<a href="https://www.rrweb.io/" style="font-weight: bold">Try rrweb</a>
<a href="https://github.com/rrweb-io/rrweb" style="font-weight: bold">Check out the original rrweb Repo</a>
</p>
<p align="center">
<a href="https://rrweb.io" style="font-weight: bold">rrweb.io</a>
</p>

# rrweb
Expand Down
6 changes: 6 additions & 0 deletions guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,18 @@ The parameter of `rrweb.record` accepts the following options.
| checkoutEveryNms | - | take a full snapshot after every N ms<br />refer to the [checkout](#checkout) chapter |
| blockClass | 'rr-block' | Use a string or RegExp to configure which elements should be blocked, refer to the [privacy](#privacy) chapter |
| blockSelector | null | Use a string to configure which selector should be blocked, refer to the [privacy](#privacy) chapter |
| unblockSelector | null | Use a string to configure which selector should not be blocked, refer to the [privacy](#privacy) chapter |
| ignoreClass | 'rr-ignore' | Use a string or RegExp to configure which elements should be ignored, refer to the [privacy](#privacy) chapter |
| ignoreSelector | null | Use a string to configure which selector should be ignored, refer to the [privacy](#privacy) chapter |
| ignoreCSSAttributes | null | array of CSS attributes that should be ignored |
| maskAllText | false | mask all text content as \* |
| maskTextClass | 'rr-mask' | Use a string or RegExp to configure which elements should be masked, refer to the [privacy](#privacy) chapter |
| unmaskTextClass | null | Use a string or RegExp to configure which elements should be unmasked, refer to the [privacy](#privacy) chapter |
| maskTextSelector | null | Use a string to configure which selector should be masked, refer to the [privacy](#privacy) chapter |
| unmaskTextSelector | null | Use a string to configure which selector should be unmasked, refer to the [privacy](#privacy) chapter |
| maskAllInputs | false | mask all input content as \* |
| maskInputOptions | { password: true } | mask some kinds of input \*<br />refer to the [list](https://github.com/rrweb-io/rrweb/blob/588164aa12f1d94576f89ae0210b98f6e971c895/packages/rrweb-snapshot/src/types.ts#L77-L95) |
| maskAttributeFn | - | callback before transforming attribute. can be used to mask specific attributes |
| maskInputFn | - | customize mask input content recording logic |
| maskTextFn | - | customize mask text content recording logic |
| slimDOMOptions | {} | remove unnecessary parts of the DOM <br />refer to the [list](https://github.com/rrweb-io/rrweb/blob/588164aa12f1d94576f89ae0210b98f6e971c895/packages/rrweb-snapshot/src/types.ts#L97-L108) |
Expand All @@ -173,6 +178,7 @@ You may find some contents on the webpage which are not willing to be recorded,
- An element with the class name `.rr-block` will not be recorded. Instead, it will replay as a placeholder with the same dimension.
- An element with the class name `.rr-ignore` will not record its input events.
- All text of elements with the class name `.rr-mask` and their children will be masked.
- All text of elements with the optional unmasking class name `unmaskTextClass` and their children will be unmasked, unless any child is marked with `.rr-mask`.
- `input[type="password"]` will be masked by default.
- Mask options to mask the content in input elements.

Expand Down
1 change: 0 additions & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"version": "independent",
"npmClient": "yarn",
"useWorkspaces": true,
"command": {
"publish": {
"message": "chore(release): publish new version"
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"devDependencies": {
"@changesets/changelog-github": "^0.4.8",
"@changesets/cli": "^2.26.0",
"@monorepo-utils/workspaces-to-typescript-project-references": "^2.8.2",
"@monorepo-utils/workspaces-to-typescript-project-references": "^2.10.2",
"@typescript-eslint/eslint-plugin": "^5.25.0",
"@typescript-eslint/parser": "^5.25.0",
"browserslist": "^4.21.4",
Expand All @@ -29,14 +29,16 @@
"eslint-plugin-compat": "^4.0.2",
"eslint-plugin-jest": "^27.1.3",
"eslint-plugin-tsdoc": "^0.2.16",
"lerna": "^7.1.4",
"markdownlint": "^0.25.1",
"markdownlint-cli": "^0.31.1",
"prettier": "2.8.4",
"turbo": "^1.2.4",
"typescript": "^4.9.5"
},
"scripts": {
"build:all": "NODE_OPTIONS='--max-old-space-size=4096' yarn run concurrently --success=all -r -m=1 'yarn workspaces-to-typescript-project-references' 'yarn turbo run prepublish'",
"build:all": "NODE_OPTIONS='--max-old-space-size=4096' yarn run concurrently --success=all -r -m=1 'yarn workspaces-to-typescript-project-references' 'yarn turbo run prepare'",
"build:tarball": "yarn lerna run build:tarball",
"test": "yarn run concurrently --success=all -r -m=1 'yarn workspaces-to-typescript-project-references --check' 'yarn turbo run test'",
"test:watch": "yarn turbo run test:watch",
"test:update": "yarn turbo run test:update",
Expand Down
8 changes: 4 additions & 4 deletions packages/rrdom-nodejs/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "rrdom-nodejs",
"name": "@sentry-internal/rrdom-nodejs",
"version": "2.0.0-alpha.11",
"scripts": {
"dev": "rollup -c -w",
"bundle": "rollup --config",
"bundle:es-only": "cross-env ES_ONLY=true rollup --config",
"check-types": "tsc -noEmit",
"test": "jest",
"prepublish": "npm run bundle",
"prepare": "npm run bundle",
"lint": "yarn eslint src/**/*.ts"
},
"keywords": [
Expand Down Expand Up @@ -48,8 +48,8 @@
"cssom": "^0.5.0",
"cssstyle": "^2.3.0",
"nwsapi": "^2.2.0",
"rrdom": "^2.0.0-alpha.11",
"rrweb-snapshot": "^2.0.0-alpha.11"
"@sentry-internal/rrdom": "^2.0.0-alpha.11",
"@sentry-internal/rrweb-snapshot": "^2.0.0-alpha.11"
},
"browserslist": [
"supports es6-class"
Expand Down
4 changes: 2 additions & 2 deletions packages/rrdom-nodejs/src/document-nodejs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import { NodeType as RRNodeType } from 'rrweb-snapshot';
import { NodeType as RRNodeType } from '@sentry-internal/rrweb-snapshot';
import type { NWSAPI } from 'nwsapi';
import type { CSSStyleDeclaration as CSSStyleDeclarationType } from 'cssstyle';
import {
Expand All @@ -14,7 +14,7 @@ import {
ClassList,
IRRDocument,
CSSStyleDeclaration,
} from 'rrdom';
} from '@sentry-internal/rrdom';
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-var-requires
const nwsapi = require('nwsapi');
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-var-requires
Expand Down
4 changes: 2 additions & 2 deletions packages/rrdom-nodejs/test/document-nodejs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import * as fs from 'fs';
import * as path from 'path';
import { NodeType as RRNodeType } from 'rrweb-snapshot';
import { NodeType as RRNodeType } from '@sentry-internal/rrweb-snapshot';
import {
RRCanvasElement,
RRCDATASection,
Expand All @@ -16,7 +16,7 @@ import {
RRStyleElement,
RRText,
} from '../src/document-nodejs';
import { buildFromDom } from 'rrdom';
import { buildFromDom } from '@sentry-internal/rrdom';

describe('RRDocument for nodejs environment', () => {
describe('RRDocument API', () => {
Expand Down
9 changes: 7 additions & 2 deletions packages/rrdom-nodejs/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@
"sourceMap": true,
"rootDir": "src",
"outDir": "build",
"lib": ["es6", "dom"],
"lib": [
"es6",
"dom"
],
"skipLibCheck": true,
"declaration": true,
"importsNotUsedAsValues": "error"
},
"compileOnSave": true,
"exclude": ["test"],
"exclude": [
"test"
],
"include": [
"src",
"test.d.ts",
Expand Down
Loading

0 comments on commit 5f5c00d

Please sign in to comment.