admin管理员组文章数量:1317906
I'm trying to register a service worker from an iframe that is created dynamically like this:
var iframe = document.createElement('iframe');
var html = '
<head><script src="/script.js"></script></head>
<body>Iframe</body>
';
document.body.appendChild(iframe);
iframe.contentWindow.document.open();
iframe.contentWindow.document.write(html);
iframe.contentWindow.document.close();
script.js
contains the code that registers a service worker (texbook example from google's documentation).
This throws an error saying "Failed to register a ServiceWorker: The document is in an invalid state."
I tried having the service worker registration code in the 'load' event handler of the iframe and adding a timeout to account for the service worker registration code potentially being called at a bad time without any success.
In the source code of Chromium I found the following code which is where I think the error is ing from:
if (!m_provider) {
resolver->reject(DOMException::create(InvalidStateError, "Failed to register a ServiceWorker: The document is in an invalid state."));
return promise;
}
What does "The document is in an invalid state" mean in this context?
What is m_provider
and why is it that it's not available?
I'm trying to register a service worker from an iframe that is created dynamically like this:
var iframe = document.createElement('iframe');
var html = '
<head><script src="/script.js"></script></head>
<body>Iframe</body>
';
document.body.appendChild(iframe);
iframe.contentWindow.document.open();
iframe.contentWindow.document.write(html);
iframe.contentWindow.document.close();
script.js
contains the code that registers a service worker (texbook example from google's documentation).
This throws an error saying "Failed to register a ServiceWorker: The document is in an invalid state."
I tried having the service worker registration code in the 'load' event handler of the iframe and adding a timeout to account for the service worker registration code potentially being called at a bad time without any success.
In the source code of Chromium I found the following code which is where I think the error is ing from:
if (!m_provider) {
resolver->reject(DOMException::create(InvalidStateError, "Failed to register a ServiceWorker: The document is in an invalid state."));
return promise;
}
What does "The document is in an invalid state" mean in this context?
What is m_provider
and why is it that it's not available?
- Were you using HTTPS or localhost? – Nikhil Pathania Commented Jul 23, 2020 at 19:02
- I'm using localhost over http – PotatoProgrammer Commented Jul 24, 2020 at 15:25
- possibly related: stackoverflow./q/67698176/11107541 – starball Commented Jun 29, 2023 at 2:38
1 Answer
Reset to default 4This looks to be caused by a bug in Chromium: https://bugs.chromium/p/chromium/issues/detail?id=1102209
Ideally, the dynamically-created frame would inherit the services workers registered on the parent, eliminating the need to write in the iframe's contentWindow at all.
本文标签:
版权声明:本文标题:javascript - What does the error "Failed to register a ServiceWorker: The document is in an invalid state." me 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742031065a2416450.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论