问题
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