Backbone: DOM Exception 18 on navigate() in Safari 9.1

Created on 13 May 2016  ·  11Comments  ·  Source: jashkenas/backbone

SecurityError: DOM Exception 18 is thrown by Safari (iOS and OSX) from the moment pushState() is called 100 times.

https://forums.developer.apple.com/thread/36650
fiddle: https://jsfiddle.net/n3uxkyhr/5/

var TestRouter = Backbone.Router.extend( {
    initialize: function() {
        this.route("/test/:id", function( id ) { console.log("test" + id) });
    }
} );
var router = new TestRouter();
Backbone.history.start({pushState: true});

try {
  for(var i = 0; i < 200; i++ ) {
      router.navigate("/test/"+i);
    }
    alert("passed, i = " + i);
} catch( e ) {
    var msg = "failed on i " + i + " with error: " + e + "\nStack: " + e.stack;
  console.error( e, msg );
  alert(msg);
}

fails with:

failed on i 100 with error: Error: SecurityError: DOM Exception 18
Stack: pushState@[native code]
navigate@https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.3.3/backbone.js:1823:69
navigate@https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.3.3/backbone.js:1522:32
global code@https://fiddle.jshell.net/n3uxkyhr/6/show/:63:22"
global code — show:68
wontfix

All 11 comments

The apple developer forum link you posted seems to suggest this issue is with safari. What do you want backbone to do about this?

backbone needs to workaround the browser bug.

Is there a workaround you're aware of @zowers? Does this bug only occur if navigate is called 100 times synchronously or will it happen if its called 100 times in general?

to workaround I had to wrap navigate in a try/catch
in safari 9.1 (latest stable as of today) - it 100 times total
in safari 9.1.1 developer preview - it's 100 times in 30 seconds

why is it won't fix?
do you say it's acceptable to have a non-working functionality?

I placed that there because reading the safari bug I did not see an acceptable solution. Using a try/catch and not changing the route after the 100th change is not acceptable IMO

Using a try/catch and not changing the route after the 100th change is not acceptable IMO

Agreed. That's a silent failure, which is worse than the current behavior.

probably navigate should fallback to hash in case of error

today safari 9.1.1 with the fix got released
in safari safari 9.1.1 history.pushState() fails only if called 100 times in 30 seconds

closed? hoping people will get the update soon?

This is a bug in Safari without much we can do. Given that 9.1 has only been out for 2 months, I think we're safe not doing anything and letting people update.

Was this page helpful?
0 / 5 - 0 ratings