-
Notifications
You must be signed in to change notification settings - Fork 38
fix: expose isSupportedBrowser() utility #1859
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
Open
oliverlaz
wants to merge
11
commits into
main
Choose a base branch
from
supported-browsers
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
459129b
fix: expose isSupportedBrowser() utility
oliverlaz 11861e8
feat: allowlist webviews too
oliverlaz b24f140
Merge branch 'refs/heads/main' into supported-browsers
oliverlaz 0e593c3
Merge branch 'main' into supported-browsers
oliverlaz e559e00
Merge branch 'main' into supported-browsers
oliverlaz a37dda2
Merge branch 'main' into supported-browsers
oliverlaz b019dc2
feat: detect exotic browsers too
oliverlaz 1fedd53
chore: more clarifications
oliverlaz 677f061
fix: update the supported browsers list
oliverlaz 932102e
Merge branch 'refs/heads/main' into supported-browsers
oliverlaz bfb32c2
fix: bump webview version too
oliverlaz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
import { beforeEach, describe, expect, it, vi } from 'vitest'; | ||
import { isChrome, isFirefox, isSafari, isSupportedBrowser } from '../browsers'; | ||
import { getClientDetails } from '../client-details'; | ||
import { ClientDetails } from '../../gen/video/sfu/models/models'; | ||
|
||
describe('browsers', () => { | ||
beforeEach(() => { | ||
Object.defineProperty(globalThis, 'navigator', { | ||
value: { userAgent: '' }, | ||
writable: true, | ||
}); | ||
}); | ||
|
||
describe('isSafari', () => { | ||
it('should return false if navigator is undefined', () => { | ||
expect(isSafari()).toBe(false); | ||
}); | ||
|
||
it('should return true for Safari user agent', () => { | ||
// @ts-expect-error - mocking navigator | ||
globalThis.navigator.userAgent = | ||
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.0 Safari/605.1.15'; | ||
expect(isSafari()).toBe(true); | ||
}); | ||
|
||
it('should return false for Chrome user agent', () => { | ||
// @ts-expect-error - mocking navigator | ||
globalThis.navigator.userAgent = | ||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'; | ||
expect(isSafari()).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('isFirefox', () => { | ||
it('should return false if navigator is undefined', () => { | ||
expect(isFirefox()).toBe(false); | ||
}); | ||
|
||
it('should return true for Firefox user agent', () => { | ||
// @ts-expect-error - mocking navigator | ||
globalThis.navigator.userAgent = | ||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0'; | ||
expect(isFirefox()).toBe(true); | ||
}); | ||
|
||
it('should return false for Chrome user agent', () => { | ||
// @ts-expect-error - mocking navigator | ||
globalThis.navigator.userAgent = | ||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'; | ||
expect(isFirefox()).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('isChrome', () => { | ||
it('should return false if navigator is undefined', () => { | ||
expect(isChrome()).toBe(false); | ||
}); | ||
|
||
it('should return true for Chrome user agent', () => { | ||
// @ts-expect-error - mocking navigator | ||
globalThis.navigator.userAgent = | ||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'; | ||
expect(isChrome()).toBe(true); | ||
}); | ||
|
||
it('should return false for Firefox user agent', () => { | ||
// @ts-expect-error - mocking navigator | ||
globalThis.navigator.userAgent = | ||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0'; | ||
expect(isChrome()).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('isSupportedBrowser', () => { | ||
vi.mock('../client-details', () => ({ | ||
getClientDetails: vi.fn(), | ||
})); | ||
|
||
it('should return false if browser is undefined', async () => { | ||
vi.mocked(getClientDetails).mockResolvedValue({ | ||
browser: undefined, | ||
} as ClientDetails); | ||
expect(await isSupportedBrowser()).toBe(false); | ||
}); | ||
|
||
it('should return true for supported Chrome version', async () => { | ||
vi.mocked(getClientDetails).mockResolvedValue({ | ||
browser: { name: 'Chrome', version: '124' }, | ||
} as ClientDetails); | ||
expect(await isSupportedBrowser()).toBe(true); | ||
}); | ||
|
||
it('should return true for supported Chrome detailed version', async () => { | ||
vi.mocked(getClientDetails).mockResolvedValue({ | ||
browser: { name: 'Chrome', version: '124.0.7204.158' }, | ||
} as ClientDetails); | ||
expect(await isSupportedBrowser()).toBe(true); | ||
}); | ||
|
||
it('should return false for unsupported Chrome version', async () => { | ||
vi.mocked(getClientDetails).mockResolvedValue({ | ||
browser: { name: 'Chrome', version: '123' }, | ||
} as ClientDetails); | ||
expect(await isSupportedBrowser()).toBe(false); | ||
}); | ||
|
||
it('should return false for unsupported Chrome detailed version', async () => { | ||
vi.mocked(getClientDetails).mockResolvedValue({ | ||
browser: { name: 'Chrome', version: '123.0.1234.99' }, | ||
} as ClientDetails); | ||
expect(await isSupportedBrowser()).toBe(false); | ||
}); | ||
|
||
it('should return true for supported Edge version', async () => { | ||
vi.mocked(getClientDetails).mockResolvedValue({ | ||
browser: { name: 'Edge', version: '124' }, | ||
} as ClientDetails); | ||
expect(await isSupportedBrowser()).toBe(true); | ||
}); | ||
|
||
it('should return false for unsupported Edge version', async () => { | ||
vi.mocked(getClientDetails).mockResolvedValue({ | ||
browser: { name: 'Edge', version: '123' }, | ||
} as ClientDetails); | ||
expect(await isSupportedBrowser()).toBe(false); | ||
}); | ||
|
||
it('should return true for supported Firefox version', async () => { | ||
vi.mocked(getClientDetails).mockResolvedValue({ | ||
browser: { name: 'Firefox', version: '124' }, | ||
} as ClientDetails); | ||
expect(await isSupportedBrowser()).toBe(true); | ||
}); | ||
|
||
it('should return false for unsupported Firefox version', async () => { | ||
vi.mocked(getClientDetails).mockResolvedValue({ | ||
browser: { name: 'Firefox', version: '123' }, | ||
} as ClientDetails); | ||
expect(await isSupportedBrowser()).toBe(false); | ||
}); | ||
|
||
it('should return true for supported Safari version', async () => { | ||
vi.mocked(getClientDetails).mockResolvedValue({ | ||
browser: { name: 'Safari', version: '17' }, | ||
} as ClientDetails); | ||
expect(await isSupportedBrowser()).toBe(true); | ||
}); | ||
|
||
it('should return false for unsupported Safari version', async () => { | ||
vi.mocked(getClientDetails).mockResolvedValue({ | ||
browser: { name: 'Safari', version: '16' }, | ||
} as ClientDetails); | ||
expect(await isSupportedBrowser()).toBe(false); | ||
}); | ||
|
||
it('should return true for supported WebKit version (WebView on iOS)', async () => { | ||
vi.mocked(getClientDetails).mockResolvedValue({ | ||
browser: { name: 'WebKit', version: '605' }, | ||
} as ClientDetails); | ||
expect(await isSupportedBrowser()).toBe(true); | ||
}); | ||
|
||
it('should return false for unsupported WebKit version (WebView on iOS)', async () => { | ||
vi.mocked(getClientDetails).mockResolvedValue({ | ||
browser: { name: 'WebKit', version: '604' }, | ||
} as ClientDetails); | ||
expect(await isSupportedBrowser()).toBe(false); | ||
}); | ||
|
||
it('should return true for supported WebView version (WebView on Android)', async () => { | ||
vi.mocked(getClientDetails).mockResolvedValue({ | ||
browser: { name: 'WebView', version: '124' }, | ||
} as ClientDetails); | ||
expect(await isSupportedBrowser()).toBe(true); | ||
}); | ||
|
||
it('should return false for unsupported WebView version (WebView on Android)', async () => { | ||
vi.mocked(getClientDetails).mockResolvedValue({ | ||
browser: { name: 'WebView', version: '123' }, | ||
} as ClientDetails); | ||
expect(await isSupportedBrowser()).toBe(false); | ||
}); | ||
|
||
it('should return false for unsupported browser', async () => { | ||
vi.mocked(getClientDetails).mockResolvedValue({ | ||
browser: { name: 'Opera', version: '78' }, | ||
} as ClientDetails); | ||
expect(await isSupportedBrowser()).toBe(false); | ||
}); | ||
}); | ||
}); |
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.