10

I have a web app that's triggering what appears to be an iOS8 bug in Safari, and I'm looking for clues into what's setting it off and how to work around it.

The bug is characterized by "A problem occurred with this webpage so it was reloaded" appearing at the top of the page after the user has spent enough time navigating in Safari. It looks like something is crashing behind the scenes, and Safari is simply doing a really good job of gracefully recovering. Reading the crash log revealed this:

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x00000000
Triggered by Thread:  0

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   JavaScriptCore                  0x2d4291d4 0x2d24a000 + 1962452
1   JavaScriptCore                  0x2d50e166 0x2d24a000 + 2900326
2   JavaScriptCore                  0x2d2bc88c 0x2d24a000 + 469132
...

Research hinted that instances of translate3d and keyframe in the CSS files might be to blame. While getting rid of them seemed to make the bug less likely to recur, the bug nevertheless still exists. Likewise, reducing the size of the (very, very large) CSS file associated with the pages most likely to trigger the bug seemed to help but not make it go away.

My company handles a bunch of mobile-optimized commerce-oriented web apps, and this is the only one that seems to be running afoul of this bug; I have no idea what's making this particular app such an angry little special snowflake, but I'd like to figure it out and correct it. Does anybody have any ideas about what might be triggering the bug and how we can work around it?

BlairHippo
  • 9,502
  • 10
  • 54
  • 78
  • All I can tell you is that you have triggered Segmentation Fault in Safari. Your crash logs suggests it may be JavaScript causing it. Without the code that triggers it, it's impossible to figure out what is crashing it, but it's definitely a bug in Safari. – Alexander O'Mara Feb 12 '15 at 23:27
  • @AlexanderO'Mara: This is honestly something of a fishing expedition. The amount of Javascript we have is pretty sizable, and I have yet to turn up any clues pointing to any particular section of it being the likely culprit. If I can get some hints about what MIGHT be causing it (are there any Javascript-related memory leaks to which Safari is unusually susceptible?), that'll go a long way towards helping me pin down what actually IS causing it. – BlairHippo Feb 13 '15 at 14:17
  • ... assuming it is, in fact, JavaScript, and not some unique combination of CSS settings that somehow combines to form an eldritch spell that will attempt to download Cthulhu, in which case the Apple team is to be commended for handling the condition gracefully. I'm seriously operating on way more blind guesswork than I prefer. Though, yeah, those "JavaScriptCore" references do seem to implicate JavaScript. – BlairHippo Feb 13 '15 at 14:23
  • 1
    It seems unlikely it would be a memory-leak causing the SegFault, but I suppose it's possible. If you can, try profiling the memory usage. [This question offers some advice](https://stackoverflow.com/questions/3971218/techniques-for-profiling-memory-in-safari-desktop-and-ios). – Alexander O'Mara Feb 13 '15 at 16:39
  • Thank you, that question looks potentially promising. – BlairHippo Feb 13 '15 at 18:21
  • 1
    @BlairHippo can you elabourate on "Research hinted that instances of translate3d and keyframe in the CSS files might be to blame"? Any links that indicate this etc? I've hit the same problem in our app that consistently crashes (taking developer tools with it, frustratingly) Safari with this error. – unwitting Mar 26 '15 at 13:54

3 Answers3

4

I had the same problem as described. In my case crash occurred when part of application that controlled few DOM elements (i.e. element.style.width...) was completed. On completion those elements were intentionally removed from DOM. The crash occurred after that without any JS errors. With try and error I isolated which parts of code are responsible for this and in my case commenting all element.style.* lines solved the problem - application does not crash anymore. Only mobile safari (iOS 7 and 8) had this problem, other browsers worked fine.

Wild guess is that maybe something strange happens on garbage collection and is connected with DOM elements controlled by JS.

frikovc
  • 111
  • 1
  • 5
3

I'm having the same exact problem with safari on iOS 8.1.3.

Actually the browser is acting a bit crazy. I have a load more button in my app which is wired to load next 20 records. Sometimes when you open the page and click on the link safari crashes with the "A problem occurred with this webpage so it was reloaded" message.

After it crashes and reloads it will crash every time. But when it works it's also stable.

Finally resolved the issue by limiting number of loaded records to 10 so it might have to do something with memory usage.

Also had this issue in a number of other places like image uploading or just loading some data via ajax.

What is more funny actually is that it never happens in chrome on iOS which actually uses webview component.

Not sure that it's of some help to you but it's not only your application so unless apple get it's act together and release a stable browser we can only try to work around some of it's limitations.

korral
  • 31
  • 2
2

Review the applicable JavaScript and CSS lines for possible syntax violations. A good IDE editor should highlight potential issues to ease this effort. Also review the generated HTML page source for ill-formed pages. Page format issues can create erratic behaviors for some browsers, yet not show any problems for others.

Another diagnostic procedure to try is to disable or comment out different sections of JavaScript code and/or CSS lines to try and isolate the location of the problem. Take out large sections as is possible to have a functional page that does not produce the error. Then, enable or un-comment lines until the error returns. Repeat this process until the problem area has been isolated for correction.

Also consider changing the sequence in which CSS definitions are made in the "very, very large" CSS file. This may produce a different behavior on the page that can either correct the problem or help to show what is the cause of the problem.

JohnH
  • 1,920
  • 4
  • 25
  • 32
  • 2
    Are there any JavaScript or CSS errors that aren't going to be logging to console? Because we're not seeing anything suspicious-looking there. And removing large chunks of CSS or JavaScript is difficult without rendering the site unable to function. Though I suppose I could go in and try surgically removing whatever I can wherever I can to see if the bug is down to some bit of presentation fluff or a core piece of functionality. Still, I'm tired of flailing blindly, and would like to at least have a theory about what I'm looking for. – BlairHippo Feb 16 '15 at 20:50
  • My suggestions presumed that either iOS8 and Safari were not the cause of the bug or if they were, no fix was available so a work around had to be found involving updates to CSS, JavaScript, etc. That presumption may not be correct. It may be worthwhile to search for updates for iOS8 and/or Safari that may address your specific issue. Also test with a non-Safari browser to see if this issue is Safari specific. Other browsers can provide insight into this issue. – JohnH Feb 17 '15 at 16:51
  • 1
    Also, add "alert" methods to debug your JavaScript code. This too can help isolate the cause of your problem. At least it will let you know what lines were successfully executed just before the problem was generated. – JohnH Feb 18 '15 at 14:54
  • Honestly, this wasn't the insight I was hoping to get from the site. But it seems like a shame to let the bounty rep go to waste, and I DO appreciate the effort to help, so here ya go. – BlairHippo Feb 20 '15 at 18:53