Skip to content

fix: Add method to check for WebKit WebView user agent string #7479

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 3 commits into from
Jul 21, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add user agent related method tests
  • Loading branch information
camdecoster committed Jul 18, 2025
commit ae0835dbc61f300d4d6e0084374731b49df1a68f
61 changes: 61 additions & 0 deletions test/jasmine/tests/lib_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2956,6 +2956,67 @@ describe('Test lib.js:', function() {
});
});
});

describe("User agent", () => {
const userAgentStrings = {
iOSSafari: "Mozilla/5.0 (iPhone; CPU iPhone OS 18_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.4 Mobile/15E148 Safari/604.1",
iOSChrome: "Mozilla/5.0 (iPhone; CPU iPhone OS 18_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/138.0.7204.156 Mobile/15E148 Safari/604.1",
macChrome: "Mozilla/5.0 (Macintosh; Intel Mac OS X 15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36",
macSafari: "Mozilla/5.0 (Macintosh; Intel Mac OS X 15_5) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.4 Safari/605.1.15",
macWKWebView: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko)",
winFirefox: "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:140.0) Gecko/20100101 Firefox/140.0"
}

describe('isIOS', () => {
[userAgentStrings.iOSChrome, userAgentStrings.iOSSafari].forEach(uaString => {
it('matches an iOS user agent string', () => {
spyOnProperty(navigator, 'userAgent').and.returnValue(uaString)
expect(Lib.isIOS()).toBe(true)
})
})

it("doesn't match a non-iOS user agent string", () => {
spyOnProperty(navigator, 'userAgent').and.returnValue(userAgentStrings.macSafari)
expect(Lib.isIOS()).toBe(false)
})
})

describe('isSafari', () => {
it('matches a Safari user agent string', () => {
spyOnProperty(navigator, 'userAgent').and.returnValue(userAgentStrings.macSafari)
expect(Lib.isSafari()).toBe(true)
})

it("doesn't match a non-Safari user agent string", () => {
spyOnProperty(navigator, 'userAgent').and.returnValue(userAgentStrings.macChrome)
expect(Lib.isSafari()).toBe(false)
})
})

describe('isMacWKWebView', () => {
it('matches a Safari user agent string', () => {
spyOnProperty(navigator, 'userAgent').and.returnValue(userAgentStrings.macWKWebView)
expect(Lib.isMacWKWebView()).toBe(true)
})

it("doesn't match a non-Safari user agent string", () => {
spyOnProperty(navigator, 'userAgent').and.returnValue(userAgentStrings.macSafari)
expect(Lib.isMacWKWebView()).toBe(false)
})
})

describe('getFirefoxVersion', () => {
it('gets the Firefox version from the user agent string', () => {
spyOnProperty(navigator, 'userAgent').and.returnValue(userAgentStrings.winFirefox)
expect(Lib.getFirefoxVersion()).toBe(140)
})

it("returns null for a non-Firefox user agent string", () => {
spyOnProperty(navigator, 'userAgent').and.returnValue(userAgentStrings.macSafari)
expect(Lib.getFirefoxVersion()).toBe(null)
})
})
})
});

describe('Queue', function() {
Expand Down