INVALID_STATE_ERR: DOM Exception 11 (WebKit)

2019-01-10 17:27发布

I recently tested a Cappuccino app I was working on with Chrome and Safari. I get the error:

INVALID_STATE_ERR: DOM Exception 11: An attempt was made to use an object that is not, or is no longer, usable.

The lack of information is frustrating. What object and where did I attempt to use it? Chrome tries to answer the second question but the line number it gives, 465, doesn't mean anything when the file it gives is just 94 lines long. Without more information I don't even know where to start looking.

11条回答
走好不送
2楼-- · 2019-01-10 17:47

I would like to add to this. Got this bug on a Samsung S4 and S5 using the stock browser.

On my side it was caused by trying to play an audio file that hasn't loaded yet.

This SO Question covers the same problem: DOM Exception 11

查看更多
爷的心禁止访问
3楼-- · 2019-01-10 17:48

Usually this error occurs with the XMLHttpRequest when you call the open method with async = true, or you leave the async parameter undefined so it defaults to asynchronous, and then you access the status or responseText properties. Those properties are only available after you do a synchronous call, or on the readyState becoming ready (once the asynchronous call responds). I suggest you first try with async = false, and then switch to it being true and use the onReadyStateChange.

查看更多
对你真心纯属浪费
4楼-- · 2019-01-10 17:50

Both Chrome and Safari have built in debuggers. Make sure you use the index-debug.html file to launch your application to get easy to read code.

In Safari, go to Preferences and activate the Developer menu. Then go to Develop > Start Debugging JavaScript. Use the pause icon in the lower left to set the debugger to pause on errors. The next time you hit the problem the debugger will pause at the offending line and show you how it got there through the stack trace.

查看更多
啃猪蹄的小仙女
5楼-- · 2019-01-10 17:51

In my case I was setting the headers prior to opening the connection. To prevent this error the headers need to be set after opening the connection:

var fd = new FormData();
fd.append("fileToUpload", file);
var xhr = new XMLHttpRequest();
xhr.open("POST", postUrl, true);
xhr.setRequestHeader("cache-control", "no-cache");
xhr.send(fd);

I understand this answer is specific to my problem and not the generic INVALID_STATE_ERR: DOM Exception 11 message but figured I would post my solution here for the next person.

查看更多
beautiful°
6楼-- · 2019-01-10 17:53

This error is also thrown when attempting to modify the value property of a <input type="file"

This is a security check.

查看更多
登录 后发表回答