- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试向服务人员实例发布消息。我收到以下错误:
Failed to execute 'postMessage' on 'ServiceWorker': function (){ obj.removeListener(ev, fn); } could not be cloned.
var socket = io();
function onYouTubeIframeAPIReady() {
//Tell the service worker who I am
navigator.serviceWorker.ready.then(serviceWorkerRegistration => {
navigator.serviceWorker.controller.postMessage({
name: 'socketInit',
value: socket
});
});
}
最佳答案
实际上立即找到了答案,它在文档中。你基本上不能有 Function
-type 属性(它可能在 io() 对象的某个地方),因为它不能被克隆:
Parameters
message
The message to send to the service worker. This can be any structured-clonable type.
structured-clonable-type
被定义为:
The structured clone algorithm is an algorithm defined by the HTML5 specification for copying complex JavaScript objects. It is used internally when transferring data to and from Workers via postMessage(). It builds up a clone by recursing through the input object while maintaining a map of previously visited references in order to avoid infinitely traversing cycles.
Things that don't work with structured clone
Error and Function objects cannot be duplicated by the structured clone algorithm; attempting to do so will throw a DATA_CLONE_ERR exception. Attempting to clone DOM nodes will likewise throw a DATA_CLONE_ERR exception. Certain parameters of objects are not preserved: The lastIndex field of RegExp objects is not preserved. Property descriptors, setters, and getters (as well as similar metadata-like features) are not duplicated. For example, if an object is marked read-only using a property descriptor, it will be read-write in the duplicate, since that's the default condition. The prototype chain does not get walked and duplicated.
关于javascript - 'postMessage'上执行 'ServiceWorker'失败 : function could not be cloned,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46145403/
我想做什么? 我正在创建一个渐进式 Web 应用程序 (PWA),为了正确发送升级应用程序,我正在处理通知用户的步骤,一旦用户说“升级”,serviceWorker 调用 skipWaiting()
我正在尝试在 Chrome 中测试推送通知功能。我在此处克隆了 Google 提供的示例 Chrome 推送通知 Web 应用程序:https://github.com/GoogleChrome/sa
我正在用 Service Workers 编写我的第一个应用程序,并试图获得注册以便与 pushManager 进行交互。 我可以使用以下任一方法执行此操作: nagivator.serviceWor
I'm wondering why ServiceWorkerRegistration has an updatefound event but no event that fires as s
这是一个奇怪的。 我正在开发 Django/Bootstrap 3 网络应用程序,最近我开始在 JavaScript 控制台中收到此错误: Failed to register/update a Se
我最近在和服务人员一起玩。我在Service Worker文件中写了一些代码,突然它坏了。是否有人知道“ServiceWorker脚本评估失败”是什么意思,何时可能出现? 最佳答案 通常,这意味着软件
在 ServiceWorker 范围内使用 RequireJS 导入外部库的正确方法是什么? 在 WebWorkers 范围内我们可以使用 importScripts() RequireJS in w
我有一个关于 ServiceWorkers 的问题。我知道这些 Worker 可能会被用户代理终止。如此终止的 ServiceWorker 是否仍然能够接收推送通知并唤醒它们? 如果没有,是否有关于该
我正在尝试更新我的 ServiceWorker。 我有一个旧的服务 worker ,一些窗口在它的控制之下。现在有一个新版本的ServiceWorker。它安装正确。但它不会为新页面激活。我的目标是为
自从 Google Chrome 新更新(版本 69.0.3497.92(官方版本)(64 位))以来,我在导航器中找不到 serviceWorker 服务。实际上我可以按如下方式注册我的 Servi
我已经实现了 ServiceWorker在我的一些网络应用程序上利用离线功能和一些与 ServiceWorkers 相关的其他好东西。现在,一切正常,直到我添加了一些外部嵌入式脚本。我在我的网络应用程
我正在尝试安装一个 ServiceWorker,它会在我每次更改当前使用的缓存版本时清除缓存。 我在 v0.0.1 缓存中缓存了 index.html,如果缓存版本更改为 v0.0.2 或其他任何版本
好的,我才刚刚开始使用 Service Workers。 我的 sw.js 中有以下代码: const cacheName = "v2" // Call Install Event self.addE
navigator.serviceWorker.register('/service-worker.js'); 如何在不初始化额外 AJAX 请求的情况下检索 /service-worker.js h
我致力于将 [Service Worker 技术] 实现到网站中。 除图像 外,一切都按预期工作。 图像根本没有加载。 我想知道这是否是预期的行为,或者是否应该加载图像。 为了重现此错误,我全新安装了
if ('serviceWorker' in navigator) { console.log('Service Worker is supported'); navigator.
我有一个简单的 service worker 安装 self.addEventListener('install', function(event) { console.log('Service
关闭。这个问题需要debugging details .它目前不接受答案。 想改进这个问题?将问题更新为 on-topic对于堆栈溢出。 上个月关门。 Improve this question 编辑
比如说,我想在 Android 上制作一个闹钟应用程序作为渐进式网络应用程序。 与原生闹钟应用一样,即使没有事件的网页,它也应该在选定的时间收到通知。 起初,我考虑过使用push api。但是当然离线
我的网站有 6 个不同的内容元素,我想通过服务工作线程特定的缓存方法来控制它们。 [预缓存]静态内容(css、js、字体) [缓存回退到网络] CDN(来自 CloudFront S3 的图像) [网
我是一名优秀的程序员,十分优秀!