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

fix: incorrect localhost handling #930

Merged
merged 2 commits into from
Dec 9, 2023
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
46 changes: 26 additions & 20 deletions src/extensions/replay/sessionrecording.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from './sessionrecording-utils'
import { PostHog } from '../../posthog-core'
import { DecideResponse, NetworkRecordOptions, NetworkRequest, Properties } from '../../types'
import { EventType, type eventWithTime, type listenerHandler } from '@rrweb/types'
import { EventType, type eventWithTime, type listenerHandler, RecordPlugin } from '@rrweb/types'
import Config from '../../config'
import { _timestamp, loadScript } from '../../utils'

Expand Down Expand Up @@ -511,29 +511,11 @@ export class SessionRecording {
},
})

const plugins = []

if (assignableWindow.rrwebConsoleRecord && this.isConsoleLogCaptureEnabled) {
plugins.push(assignableWindow.rrwebConsoleRecord.getRecordConsolePlugin())
}
if (this.networkPayloadCapture && _isFunction(assignableWindow.getRecordNetworkPlugin)) {
if (isLocalhost() && !this._forceAllowLocalhostNetworkCapture) {
logger.info('[SessionReplay-NetworkCapture] not started because we are on localhost.')
return
}

plugins.push(
assignableWindow.getRecordNetworkPlugin(
buildNetworkRequestOptions(this.instance.config, this.networkPayloadCapture)
)
)
}

this.stopRrweb = this.rrwebRecord({
emit: (event) => {
this.onRRwebEmit(event)
},
plugins,
plugins: this._gatherRRWebPlugins(),
...sessionRecordingOptions,
})

Expand All @@ -560,6 +542,30 @@ export class SessionRecording {
this.isIdle = false
}

private _gatherRRWebPlugins() {
const plugins: RecordPlugin<unknown>[] = []

if (assignableWindow.rrwebConsoleRecord && this.isConsoleLogCaptureEnabled) {
plugins.push(assignableWindow.rrwebConsoleRecord.getRecordConsolePlugin())
}

if (this.networkPayloadCapture && _isFunction(assignableWindow.getRecordNetworkPlugin)) {
const canRecordNetwork = !isLocalhost() || this._forceAllowLocalhostNetworkCapture

if (canRecordNetwork) {
plugins.push(
assignableWindow.getRecordNetworkPlugin(
buildNetworkRequestOptions(this.instance.config, this.networkPayloadCapture)
)
)
} else {
logger.info('[SessionReplay-NetworkCapture] not started because we are on localhost.')
}
}

return plugins
}

onRRwebEmit(rawEvent: eventWithTime) {
if (!rawEvent || !_isObject(rawEvent)) {
return
Expand Down
4 changes: 3 additions & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@ export const _safewrap = function <F extends (...args: any[]) => any = (...args:
// @ts-ignore
return f.apply(this, args)
} catch (e) {
logger.critical('Implementation error. Please turn on debug mode and open a ticket on https://app.posthog.com/home#panel=support%3Asupport%3A.')
logger.critical(
'Implementation error. Please turn on debug mode and open a ticket on https://app.posthog.com/home#panel=support%3Asupport%3A.'
)
logger.critical(e)
}
} as F
Expand Down
Loading