且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

后台js脚本是否在Chrome操作系统应用程序中的其他线程上运行?

更新时间:2023-10-20 18:18:34

Chrome应用程序窗口仅是视图",并不位于单独的进程中.这是证明.每个应用程序查看页面都可以运行chrome.runtime.getBackgroundPage来直接引用后台页面的javascript上下文(所有变量,函数等).此外,背景页面还可以使用chrome.app.window.getAll引用返回的appWindow对象上的contentWindow来获取对应用程序窗口的javascript上下文的引用.

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.

正如另一位评论者所指出的,Chrome扩展程序的情况有所不同,但是由于问题是关于应用程序的,因此我们只关心自己.

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.