Skip to content

Fix browser boltAgent in web workers context #1094

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

Merged
merged 1 commit into from
Jun 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
6 changes: 5 additions & 1 deletion packages/core/src/internal/bolt-agent/browser/bolt-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@ export function fromVersion (
version: string,
getSystemInfo: () => SystemInfo = () => ({
get userAgent() {
// this should be defined as an `var` since we need to get information
// came from the global scope which not always will be defined
// and we don't want to override the information
var navigator
// @ts-ignore: browser code so must be skipped by ts
return window.navigator.userAgent
return navigator?.userAgent
}
})
): BoltAgent {
Expand Down
10 changes: 10 additions & 0 deletions packages/core/test/internal/bolt-agent/browser/bolt-agent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,14 @@ describe('#unit boltAgent', () => {
product: 'neo4j-javascript/5.3'
})
})

it('should handle navigator object does not exist in the default getSystemInfo', () => {
const version = '5.3'

const boltAgent = fromVersion(version)

expect(boltAgent).toEqual({
product: 'neo4j-javascript/5.3'
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@ export function fromVersion (
version: string,
getSystemInfo: () => SystemInfo = () => ({
get userAgent() {
// this should be defined as an `var` since we need to get information
// came from the global scope which not always will be defined
// and we don't want to override the information
var navigator
// @ts-ignore: browser code so must be skipped by ts
return window.navigator.userAgent
return navigator?.userAgent
}
})
): BoltAgent {
Expand Down