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

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]
dispatchEvent@[native code]
(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)


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.

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.

@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.

1 Like

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!

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!!!

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

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.

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!

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