[solved] iOS9 fails with setRequestHeader [native] with custom headers in $http service


#1

We were testing our app on iOS9 GM. We applied the patch from angular team for $browser. But We are noticing this error for network requests. Its triggered when a network request is made using $http service.

** After Digging around, I figured the cause of this is triggered by adding custom headers to network request.

[Solved]: Custom headers should not have a leading space in the value. for example in my case

“Authorization”: " Token 123456789"

leading space before "Token"was causing the issue, removing it fixed this issue for me.

Its working fine on iOS 8

OS: iOS 9
Angular: 1.3.13
Ionic: 1.1.0

[Error] Error: SyntaxError: DOM Exception 12
setRequestHeader@[native code]
file:///var/mobile/Containers/Bundle/Application/1234/myapp.app/www/angular.js:9769:33
forEach@file:///var/mobile/Containers/Bundle/Application/1234/myapp.app/www/angular.js:331:24
file:///var/mobile/Containers/Bundle/Application/1234/myapp.app/www/angular.js:9767:14
sendReq@file:///var/mobile/Containers/Bundle/Application/1234/myapp.app/www/angular.js:9628:21
serverRequest@file:///var/mobile/Containers/Bundle/Application/1234/myapp.app/www/angular.js:9344:23
processQueue@file:///var/mobile/Containers/Bundle/Application/1234/myapp.app/www/angular.js:13189:29
file:///var/mobile/Containers/Bundle/Application/1234/myapp.app/www/angular.js:13205:39
$eval@file:///var/mobile/Containers/Bundle/Application/1234/myapp.app/www/angular.js:14401:28
$digest@file:///var/mobile/Containers/Bundle/Application/1234/myapp.app/www/angular.js:14217:36
$apply@file:///var/mobile/Containers/Bundle/Application/1234/myapp.app/www/angular.js:14506:31
file:///var/mobile/Containers/Bundle/Application/1234/myapp.app/www/ionic-angular.js:11656:19
dispatch@file:///var/mobile/Containers/Bundle/Application/1234/myapp.app/www/jquery.js:4435:14
handle@file:///var/mobile/Containers/Bundle/Application/1234/myapp.app/www/jquery.js:4121:33
dispatchEvent@[native code]
triggerMouseEvent@file:///var/mobile/Containers/Bundle/Application/1234/myapp.app/www/ionic.js:2858:20
tapClick@file:///var/mobile/Containers/Bundle/Application/1234/myapp.app/www/ionic.js:2847:20
tapTouchEnd@file:///var/mobile/Containers/Bundle/Application/1234/myapp.app/www/ionic.js:2970:13
(anonymous function) (console-via-logger.js, line 173)
(anonymous function) (angular.js, line 11607)
(anonymous function) (angular.js, line 8557)
processQueue (angular.js, line 13197)
(anonymous function) (angular.js, line 13205)
$eval (angular.js, line 14401)
$digest (angular.js, line 14217)
$apply (angular.js, line 14506)
(anonymous function) (ionic-angular.js, line 11656)
dispatch (jquery.js, line 4435)
handle (jquery.js, line 4121)
dispatchEvent ([native code], line 0)
triggerMouseEvent (ionic.js, line 2858)
tapClick (ionic.js, line 2847)
tapTouchEnd (ionic.js, line 2970)


#2

Hi, I have a exact same issue and wondering if you (or anyone) already figure out
what causes this error? I’m planning to dig into this problem later today so
I will share it here if I make any progress.


#3

I might have some lead into it. Are you setting any custom headers?
I am noticing errors when there is a custom header added to the requests. Please let me know if that is the case with your app.


#5

@tomo Hey, So check if your custom headers have a leading space in the value. for example in my case

“Authorization”: " Token 123456789"

leading space before "Token"was causing the issue, removing it fixed this issue for me.
Hope it helps you.


#6

Hi @Sravankacha, I think you nail it - I don’t know how you figure this out but
it seems like I’m having the exact same issue, as I do use header with space in front!
I have to physically relocated to another floor for testing/verifying this, so I still haven’t
had a chance to work on it but I will post back the result whenever I actually get to test this out.

Thank you so much for posting back, I think you could easily save me days if not weeks
worth of effort (because I have no clue that might cause the DOM 12 Exception) -
and it’s good to know that you got it working!


#7

Finally I get to work on the fix and verified that what you described was the
cause of exception and after addressing it, our app started to function again!

Once again thank you so much for sharing your solution, I would never thought
it is a http header that could cause this error!!!


#8

Thanks! This solved it for me as well :smile:


#9

Same problem just manifested itself on Safari 9.0 (10601.1.56.2) upgrade. It turned out I was appending whitespace on the http.defaults.headers.common.Authorization string. Removed it and all good.


Ionic ios9 issues
#10

AWESOME!!! It worked for us too! We spent so many hrs burning ourselves to find the fix until I landed on your page…Cool one!


#11

Dude, saved my life as well. Who could guess that!