INVALID_STATE_ERR:DOM 异常 11 (WebKit)

发布于 2024-09-14 18:48:47 字数 303 浏览 10 评论 0 原文

我最近测试了我正在使用 Chrome 和 Safari 开发的卡布奇诺应用程序。我收到错误:

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

缺乏信息令人沮丧。什么对象以及我在哪里尝试使用它? Chrome 尝试回答第二个问题,但是当它给出的文件只有 94 行长时,它给出的行号 465 没有任何意义。如果没有更多信息,我什至不知道从哪里开始寻找。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

荭秂 2024-09-21 18:48:47

通常,当您使用 async = true 调用 open 方法,或者未定义 async 参数以使其默认为异步,然后访问 status 或 responseText 属性时,XMLHttpRequest 中通常会出现此错误。这些属性仅在您执行同步调用后或在 readState 变为就绪状态(异步调用响应后)时才可用。我建议您首先尝试使用 async = false,然后切换为 true 并使用 onReadyStateChange。

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.

与他有关 2024-09-21 18:48:47

就我而言,我在打开连接之前设置标头。为了防止此错误,需要在打开连接后设置标头:

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);

我知道这个答案特定于我的问题,而不是通用的 INVALID_STATE_ERR: DOM Exception 11 消息,但我想我会在这里为下一个人发布我的解决方案。

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.

走走停停 2024-09-21 18:48:47

Chrome canary 提供 DOM 异常的堆栈跟踪!

Chrome canary offers stack traces for DOM Exceptions!

柳絮泡泡 2024-09-21 18:48:47

当 Javascript 尝试将 document.write() 写入 XHTML 页面 (Content-Type: application/xhtml+xml) 时,也会发生这种情况。

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

呢古 2024-09-21 18:48:47

当尝试修改 value 属性时,也会引发此错误

。这是一项安全检查。

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

This is a security check.

丑疤怪 2024-09-21 18:48:47

首先,我对卡布奇诺一无所知,也不知道你想做什么。但我在使用 Qt WebKit 和 JavaScript 对象时看到了这一点。它发生在 javascript 窗口对象被清除之后,例如,如果我在加载新页面后没有将本机 JS 对象加载到 WebKit。

这基本上意味着,您正在尝试使用内部删除的 JavaScript 对象。

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.

冷…雨湿花 2024-09-21 18:48:47

在这种情况下,我认为问题源于尝试使用未完全加载的图像的图案填充将图像绘制到画布上。这个问题与卡布奇诺问题811有关,我的推理基于aparajita 建议在尝试将图像用作图案填充之前确保图像已加载。

尽管如此,考虑到关键信息(被称为什么对象)并不明显,并且它可能出现的位置多种多样,这个错误仍然令人沮丧地不透明。

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.

高冷爸爸 2024-09-21 18:48:47

Chrome 和 Safari 都内置了调试器。确保使用index-debug.html 文件启动应用程序以获得易于阅读的代码。

在 Safari 中,转到“首选项”并激活“开发人员”菜单。然后转到“开发”>“开始调试 JavaScript。使用左下角的暂停图标将调试器设置为在出现错误时暂停。下次遇到问题时,调试器将在有问题的行处暂停,并向您显示它是如何通过堆栈跟踪到达那里的。

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.

耀眼的星火 2024-09-21 18:48:47

当尝试动态编写带有 value 属性集的 input[type="file"] 元素时,我已经看到这种情况发生。

当我从我注入的内容中删除 value attr 时,一切都正常了。

从某种意义上说,我认为这个错误的意思是“你试图做一些规范不允许的事情”,基于这篇文章 - http://designbyjeeba.blogspot.com/2011/04/dreaded-invalidstateerr-dom-exception.html

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

瘫痪情歌 2024-09-21 18:48:47

我之所以出现这个问题,是因为我像这样使用了音频 API:

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

但这是不正确的,因为 play() 函数是异步的。相反,您需要使用返回的 Promise 的 then 函数。

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

返回值:一个 Promise,在播放开始时履行,或者在由于任何原因无法开始播放时被拒绝。
MDN

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

浮云落日 2024-09-21 18:48:47

我想补充一下。使用内置浏览器在 Samsung S4 和 S5 上遇到此错误。

就我而言,这是由于尝试播放尚未加载的音频文件引起的。

这个SO Question涵盖了同样的问题:
DOM 异常 11

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文