You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current DOM serialization algorithm produces two kinds of attributes on elements:
Real DOM attributes, like foo="bar" in <div foo="bar">.
"Virtual" attributes representing metadata about the element. For example, rr_scrollLeft and rr_scrollTop are used to capture information about the initial scroll position of an element.
Many of these virtual attributes are primarily of interest in full snapshots; later, when the values change incrementally, we represent them using dedicated records. For example, later changes to rr_scrollLeft and rr_scrollTop are represented as BrowserIncrementalSnapshotRecord records with IncrementalSource.Scroll. (Speculating on the reasoning for the different representation in full snapshots, I'd guess this was done because there's no easy way to bundle multiple changes into a single, atomic full snapshot record except to include them in the DOM snapshot itself. Incremental snapshots can bundle together many changes at once, so they don't have the same issue.)
The new DOM serialization algorithm doesn't have a special record type for full snapshots; everything uses a representation comparable to our current incremental snapshots. For that reason, the new algorithm doesn't need these virtual attributes; it makes more sense to encode these values in the same way we do today for incremental snapshots.
To make it easier to share code between the current DOM serialization algorithm and the new one, let's separate the code that serializes real DOM attributes from the code that serializes virtual attributes.
Changes
This PR:
Renames safeAttrs to attrs in serializeAttributes() as a minor opportunistic refactor. I'm not a big fan of the name safeAttrs since it implies that everything in safeAttrs satisfies our privacy rules and is safe to record, but in fact that's not true until the end of the function.
Splits serializeAttributes() into two functions, serializeDOMAttributes() and serializeVirtualAttributes(). (serializeAttributes() survives as a trivial wrapper around these two functions.)
Tweaks the types in a few places to more accurately reflect the kinds of values that serializeDOMAttributes() can now return.
Removes the call to getValidTagName() from both functions since it contains a regular expression which it would be wasteful to invoke in two places. getValidTagName() doesn't really provide any benefit since we are only comparing the tag name with exact known strings in this code; we can just use Element#tagName directly.
Updates the tests for serializeAttributes() to call serializeDOMAttributes() or serializeVirtualAttributes(), as appropriate. (I wrote the tests with this in mind, so making the switch is easy.)
The reason will be displayed to describe this comment to others. Learn more.
What worries me is the removal of getValidTagName. I know it's probably a stretch nowadays, but if one of our customer still serves their application using application/xhtml+xml, wouldn't the tag names be lower case?
What worries me is the removal of getValidTagName. I know it's probably a stretch nowadays, but if one of our customer still serves their application using application/xhtml+xml, wouldn't the tag names be lower case?
Yes, indeed that is still possible. (I double checked the behavior with this site, which I am linking for posterity because it's incredibly hard to find any site that's served using application/xhtml+xml. 😄 )
We are unfortunately already checking only for uppercase tag names in many places in the code, so I don't think the SDK will behave correctly on XHTML sites today, but I think it's worth keeping the things that work today working. We can do that without the full weight of getValidTagName(), though. I'll update the PR.
cookie getCurrentSite returns the eTLD+1 for foo.bar.baz.example.com from Safari 12.1.2 (Mac OS 10.14.6) (Datadog) (Fix with Cursor)
Expected 'foo.bar.baz.example.com' to be 'example.com'.
<Jasmine>
webpack:///packages/core/src/browser/cookie.spec.ts:24:61 <- /tmp/_karma_webpack_596170/commons.js:48598:108
<Jasmine>
This comment will be updated automatically if new data arrives.
* Fix with Cursor requires Datadog plugin ≥v2.17.0
🔗 Commit SHA: 5f2f0df | Docs | Datadog PR Page | Was this helpful? Give us feedback!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
None yet
2 participants
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
The current DOM serialization algorithm produces two kinds of attributes on elements:
foo="bar"in<div foo="bar">.rr_scrollLeftandrr_scrollTopare used to capture information about the initial scroll position of an element.Many of these virtual attributes are primarily of interest in full snapshots; later, when the values change incrementally, we represent them using dedicated records. For example, later changes to
rr_scrollLeftandrr_scrollTopare represented asBrowserIncrementalSnapshotRecordrecords withIncrementalSource.Scroll. (Speculating on the reasoning for the different representation in full snapshots, I'd guess this was done because there's no easy way to bundle multiple changes into a single, atomic full snapshot record except to include them in the DOM snapshot itself. Incremental snapshots can bundle together many changes at once, so they don't have the same issue.)The new DOM serialization algorithm doesn't have a special record type for full snapshots; everything uses a representation comparable to our current incremental snapshots. For that reason, the new algorithm doesn't need these virtual attributes; it makes more sense to encode these values in the same way we do today for incremental snapshots.
To make it easier to share code between the current DOM serialization algorithm and the new one, let's separate the code that serializes real DOM attributes from the code that serializes virtual attributes.
Changes
This PR:
safeAttrstoattrsinserializeAttributes()as a minor opportunistic refactor. I'm not a big fan of the namesafeAttrssince it implies that everything insafeAttrssatisfies our privacy rules and is safe to record, but in fact that's not true until the end of the function.serializeAttributes()into two functions,serializeDOMAttributes()andserializeVirtualAttributes(). (serializeAttributes()survives as a trivial wrapper around these two functions.)serializeDOMAttributes()can now return.getValidTagName()from both functions since it contains a regular expression which it would be wasteful to invoke in two places.getValidTagName()doesn't really provide any benefit since we are only comparing the tag name with exact known strings in this code; we can just useElement#tagNamedirectly.serializeAttributes()to callserializeDOMAttributes()orserializeVirtualAttributes(), as appropriate. (I wrote the tests with this in mind, so making the switch is easy.)Checklist