Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
fix($browser/$location): add a workaround of iOS9 regression in UIWeb…
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorMinar committed Sep 10, 2015
1 parent 00ee090 commit b5464e1
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 3 deletions.
41 changes: 40 additions & 1 deletion src/ng/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,45 @@ function Browser(window, document, $log, $sniffer) {
function $BrowserProvider() {
this.$get = ['$window', '$log', '$sniffer', '$document',
function($window, $log, $sniffer, $document) {
return new Browser($window, $document, $log, $sniffer);
var browser = new Browser($window, $document, $log, $sniffer);

if (isIOS9UIWebView($window.navigator.userAgent)) {
browser = applyIOS9Shim(browser);
}

return browser;
}];
}


function isIOS9UIWebView(userAgent) {
return /(iPhone|iPad|iPod) OS 9_\d/.test(userAgent) && !/Version\/9\./.test(userAgent);
}


function applyIOS9Shim(browser) {
var pendingLocationUrl = null;
var patchedBrowser = Object.create(browser);

patchedBrowser.url = function() {
if (arguments.length) {
pendingLocationUrl = arguments[0];

// reset the current pendingLocationUrl in the next task
(function() {
var pendingLocationUrlToReset = pendingLocationUrl;
setTimeout(function() {
if (pendingLocationUrlToReset === pendingLocationUrl) {
pendingLocationUrl = null;
}
},0);
}());

return browser.url.apply(patchedBrowser, arguments);
}

return pendingLocationUrl || browser.url();
};

return patchedBrowser;
}
19 changes: 18 additions & 1 deletion test/ng/browserSpecs.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

/* global getHash:true, stripHash:true */
/* global getHash:true, stripHash:true, isIOS9UIWebView:true */

var historyEntriesLength;
var sniffer = {};
Expand Down Expand Up @@ -852,4 +852,21 @@ describe('browser', function() {

});


describe('iOS9 UIWebView workarounds', function() {

describe('userAgent sniffing', function() {

it('should identify iOS9 + UIWebView', function() {
var userAgentString = 'Mozilla/5.0 (iPhone; CPU iPhone OS 9_0 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Mobile/13A4325c (358330912)';
expect(isIOS9UIWebView(userAgentString)).toBe(true);
});

it('should ignore iOS9 + WKWebView', function() {
var userAgentString = 'Mozilla/5.0 (iPhone; CPU iPhone OS 9_0 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13A4325c Safari/601.1';
expect(isIOS9UIWebView(userAgentString)).toBe(false);
});
});
});

});
5 changes: 4 additions & 1 deletion test/ng/rafSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ describe('$$rAF', function() {
location: window.location,
history: window.history,
webkitRequestAnimationFrame: jasmine.createSpy('$window.webkitRequestAnimationFrame'),
webkitCancelRequestAnimationFrame: jasmine.createSpy('$window.webkitCancelRequestAnimationFrame')
webkitCancelRequestAnimationFrame: jasmine.createSpy('$window.webkitCancelRequestAnimationFrame'),
navigator: {
userAgent: 'mock navigator'
}
});
}]);

Expand Down

0 comments on commit b5464e1

Please sign in to comment.