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

isSafariBrowser update #5077

Merged
merged 4 commits into from
Apr 8, 2020
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
2 changes: 1 addition & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ export function inIframe() {
}

export function isSafariBrowser() {
return /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
return /^((?!chrome|android|crios|fxios).)*safari/i.test(navigator.userAgent);
}

export function replaceAuctionPrice(str, cpm) {
Expand Down
36 changes: 36 additions & 0 deletions test/spec/utils_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -922,4 +922,40 @@ describe('Utils', function () {
});
});
});

describe('isSafariBrowser', function () {
let userAgentStub;
let userAgent;

before(function () {
userAgentStub = sinon.stub(navigator, 'userAgent').get(function () {
return userAgent;
});
});

after(function () {
userAgentStub.restore();
});

it('properly detects safari', function () {
userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/536.25 (KHTML, like Gecko) Version/6.0 Safari/536.25';
expect(utils.isSafariBrowser()).to.equal(true);
});
it('does not flag Chrome on MacOS', function () {
userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36';
expect(utils.isSafariBrowser()).to.equal(false);
});
it('does not flag Chrome iOS', function () {
userAgent = 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/80.0.3987.95 Mobile/15E148 Safari/604.1';
expect(utils.isSafariBrowser()).to.equal(false);
});
it('does not flag Firefox iOS', function () {
userAgent = 'Mozilla/5.0 (iPhone; CPU OS 13_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/23.0 Mobile/15E148 Safari/605.1.15';
expect(utils.isSafariBrowser()).to.equal(false);
});
it('does not flag Windows Edge', function () {
userAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.74 Safari/537.36 Edg/79.0.309.43';
expect(utils.isSafariBrowser()).to.equal(false);
});
});
});