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:30

First, I don't really know a thing of Cappucino or what you're trying to do. But I've seen this when working with Qt WebKit and JavaScript objects. It happened after javascript window object was cleared, e.g. if I didn't load my native JS objects to WebKit after new page was loaded.

This basically means, you are trying to use internally deleted JavaScript object.

查看更多
家丑人穷心不美
3楼-- · 2019-01-10 17:32

This problem occured for me because I used the Audio API like this:

let someAudio = new Audio(file);
someAudio.play();
someAudio.pause();

But this is not correct because the play() function is async. Instead you need to use the then function of the returned Promise.

someAudio.play().then(() => someAudio.pause());

Return value: A Promise which is fulfilled when playback has been started, or is rejected if for any reason playback cannot be started. MDN

查看更多
Anthone
4楼-- · 2019-01-10 17:39

This can also happen when Javascript tries to document.write() into an XHTML page (Content-Type: application/xhtml+xml).

查看更多
太酷不给撩
5楼-- · 2019-01-10 17:39

I've seen this happen when trying to dynamically write an input[type="file"] element with its value attribute set.

When i removed the value attr from what i was injecting it all worked.

In a sense, I see this error as meaning "you tried to do something that specification does not allow" based upon this article here -- http://designbyjeeba.blogspot.com/2011/04/dreaded-invalidstateerr-dom-exception.html

查看更多
叼着烟拽天下
6楼-- · 2019-01-10 17:46

Chrome canary offers stack traces for DOM Exceptions!

查看更多
一纸荒年 Trace。
7楼-- · 2019-01-10 17:47

In this case I believe the issue was stemming from trying to draw images to canvas using a pattern fill with an image that was not fully loaded. This question was related to Cappuccino issue 811 and my reasoning is based on aparajita's advice to make sure the image is loaded before attempting to use it as a pattern fill.

Still, this error is frustratingly opaque considering the key piece of information (what object was called) is not obvious and the places it can crop up in are varied.

查看更多
登录 后发表回答