相关疑难解决方法(0)

在网络应用中注册在线服务工作者

我想将Web推送通知添加到由应用脚本托管的Web应用中。为此,我需要注册服务工作者,并且遇到跨域请求错误。原始内容来自,*.googleusercontent.com而脚本URL为script.google.com/*

通过使用通过脚本创建的内联URL上的这篇文章,我能够成功创建内联工作器blob。现在,我陷入了在浏览器中注册工作人员的问题。

以下模型适用:

的HTML

<!-- Display the worker status -->
<div id="log"></log>
Run Code Online (Sandbox Code Playgroud)

服务人员

<script id="worker" type="javascript/worker">
  self.onmessage = function(e) {
    self.postMessage('msg from worker');
  };
  console.log('[Service Worker] Process started');

  })
</script> 
Run Code Online (Sandbox Code Playgroud)

内联安装

<script>
  function log(msg) {
    var fragment = document.createDocumentFragment();
    fragment.appendChild(document.createTextNode(msg));
    fragment.appendChild(document.createElement('br'));

    document.querySelector("#log").appendChild(fragment);
  }

  // Create the object with the script
  var blob = new Blob([ document.querySelector("#worker").textContent ]);

  // assign a absolute URL to the obejct for hosting
  var worker = new Worker(window.URL.createObjectURL(blob)); …
Run Code Online (Sandbox Code Playgroud)

javascript google-apps-script web-notifications service-worker

1
推荐指数
1
解决办法
1422
查看次数