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

feat: no recording blob urls #1768

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
26 changes: 25 additions & 1 deletion src/entrypoints/recorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,43 @@ function shouldRecordBody({
type,
recordBody,
headers,
url,
}: {
type: 'request' | 'response'
recordBody: NetworkRecordOptions['recordBody']
headers: Headers
url: string | URL | RequestInfo
recordBody: NetworkRecordOptions['recordBody']
}) {
function matchesContentType(contentTypes: string[]) {
const contentTypeHeader = Object.keys(headers).find((key) => key.toLowerCase() === 'content-type')
const contentType = contentTypeHeader && headers[contentTypeHeader]
return contentTypes.some((ct) => contentType?.includes(ct))
}

/**
* particularly in canvas applications we see many requests to blob URLs
* e.g. blob:https://video_url
* these blob/object URLs are local to the browser, we can never capture that body
* so we can just return false here
*/
function isBlobURL(url: string | URL | RequestInfo) {
try {

Choose a reason for hiding this comment

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

Not sure why do you need try catch here though

Copy link
Member Author

@pauldambra pauldambra Feb 28, 2025

Choose a reason for hiding this comment

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

i am very extra super careful in this file
if we break things in here we can break fetch/xhr in customer sites

if (typeof url === 'string') {
return url.startsWith('blob:')
}
if (url instanceof URL) {
return url.protocol === 'blob:'
}
if (url instanceof Request) {
return isBlobURL(url.url)
}
return false
} catch {
return false
}
}
if (!recordBody) return false
if (isBlobURL(url)) return false
if (isBoolean(recordBody)) return true
if (isArray(recordBody)) return matchesContentType(recordBody)
const recordBodyType = recordBody[type]
Expand Down
Loading