Do background js scripts run on a different thread in Chrome OS apps?

萝らか妹 提交于 2020-05-16 04:04:34

问题


On the manifest for Chrome OS apps one must declare background js scripts.

{
  "name": "Hello World!",
  "description": "My first Chrome App.",
  "version": "0.1",
  "manifest_version": 2,
  "app": {
    "background": {
      "scripts": ["background.js"]
    }
  },
  "icons": { "16": "calculator-16.png", "128": "calculator-128.png" }
}

Are each of these running in their own thread?

Do they block each other or the JS threads running on the app windows?


回答1:


Chrome App windows are only "views", and are not living in separate processes. Here's the proof. Each app view page can run chrome.runtime.getBackgroundPage to get a direct reference to the background page's javascript context (all variables, functions, etc). Also the background page can get references to the javascript contexts of the app windows, using chrome.app.window.getAll to reference contentWindow on the appWindow objects returned.

As another commenter points out, the situation is a bit different for chrome extensions, but since the question is about apps, we only concern ourselves with that.



来源:https://stackoverflow.com/questions/45258907/do-background-js-scripts-run-on-a-different-thread-in-chrome-os-apps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!