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

rum-recorder: import rrweb-snapshot code #700

Merged
merged 8 commits into from
Feb 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LICENSE-3rdparty.csv
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ Component,Origin,License,Copyright
require,tslib,Apache-2.0,Copyright Microsoft Corporation
file,pako,MIT,(C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
file,rrweb,MIT,Copyright (c) 2018 Contributors (https://github.com/rrweb-io/rrweb/graphs/contributors) and SmartX Inc.
file,rrweb-snapshot,MIT,Copyright (c) 2018 Contributors (https://github.com/rrweb-io/rrweb-snapshot/graphs/contributors) and SmartX Inc.
vlad-mh marked this conversation as resolved.
Show resolved Hide resolved
file,tracekit,MIT,Copyright 2013 Onur Can Cakmak and all TraceKit contributors
prod,rrweb-snapshot,MIT,Copyright (c) 2018 Contributors (https://github.com/rrweb-io/rrweb-snapshot/graphs/contributors) and SmartX Inc.
dev,@types/connect-busboy,MIT,Copyright Microsoft Corporation
dev,@types/cors,MIT,Copyright Microsoft Corporation
dev,@types/express,MIT,Copyright Microsoft Corporation
Expand Down
1 change: 0 additions & 1 deletion packages/rum-recorder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"dependencies": {
"@datadog/browser-core": "2.4.0",
"@datadog/browser-rum-core": "2.4.0",
"rrweb-snapshot": "1.0.1",
"tslib": "^1.10.0"
},
"repository": {
Expand Down
4 changes: 4 additions & 0 deletions packages/rum-recorder/src/domain/rrweb-snapshot/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { serializeNodeWithId, transformAttribute, IGNORED_NODE, snapshot } from './snapshot'
export * from './types'

export { snapshot, serializeNodeWithId, transformAttribute, IGNORED_NODE }
75 changes: 75 additions & 0 deletions packages/rum-recorder/src/domain/rrweb-snapshot/snapshot.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/* eslint-disable max-len */
import { absoluteToStylesheet } from './snapshot'

describe('absolute url to stylesheet', () => {
const href = 'http://localhost/css/style.css'

it('can handle relative path', () => {
expect(absoluteToStylesheet('url(a.jpg)', href)).toEqual(`url(http://localhost/css/a.jpg)`)
})

it('can handle same level path', () => {
expect(absoluteToStylesheet('url("./a.jpg")', href)).toEqual(`url("http://localhost/css/a.jpg")`)
})

it('can handle parent level path', () => {
expect(absoluteToStylesheet('url("../a.jpg")', href)).toEqual(`url("http://localhost/a.jpg")`)
})

it('can handle absolute path', () => {
expect(absoluteToStylesheet('url("/a.jpg")', href)).toEqual(`url("http://localhost/a.jpg")`)
})

it('can handle external path', () => {
expect(absoluteToStylesheet('url("http://localhost/a.jpg")', href)).toEqual(`url("http://localhost/a.jpg")`)
})

it('can handle single quote path', () => {
expect(absoluteToStylesheet(`url('./a.jpg')`, href)).toEqual(`url('http://localhost/css/a.jpg')`)
})

it('can handle no quote path', () => {
expect(absoluteToStylesheet('url(./a.jpg)', href)).toEqual(`url(http://localhost/css/a.jpg)`)
})

it('can handle multiple no quote paths', () => {
expect(
absoluteToStylesheet(
'background-image: url(images/b.jpg);background: #aabbcc url(images/a.jpg) 50% 50% repeat;',
href
)
).toEqual(
`background-image: url(http://localhost/css/images/b.jpg);` +
`background: #aabbcc url(http://localhost/css/images/a.jpg) 50% 50% repeat;`
)
})

it('can handle data url image', () => {
expect(absoluteToStylesheet('url(data:image/gif;base64,ABC)', href)).toEqual('url(data:image/gif;base64,ABC)')
expect(absoluteToStylesheet('url(data:application/font-woff;base64,d09GMgABAAAAAAm)', href)).toEqual(
'url(data:application/font-woff;base64,d09GMgABAAAAAAm)'
)
})

it('preserves quotes around inline svgs with spaces', () => {
expect(
absoluteToStylesheet(
"url(\"data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3E%3Cpath fill='%2328a745' d='M3'/%3E%3C/svg%3E\")",
href
)
).toEqual(
"url(\"data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3E%3Cpath fill='%2328a745' d='M3'/%3E%3C/svg%3E\")"
)
expect(
absoluteToStylesheet(
'url(\'data:image/svg+xml;utf8,<svg width="28" height="32" viewBox="0 0 28 32" xmlns="http://www.w3.org/2000/svg"><path d="M27 14C28" fill="white"/></svg>\')',
href
)
).toEqual(
'url(\'data:image/svg+xml;utf8,<svg width="28" height="32" viewBox="0 0 28 32" xmlns="http://www.w3.org/2000/svg"><path d="M27 14C28" fill="white"/></svg>\')'
)
})
it('can handle empty path', () => {
expect(absoluteToStylesheet(`url('')`, href)).toEqual(`url('')`)
})
})
Loading