[英]Google Chrome App: Webview behavior
在Chrome擴展程序中研究<iframe>
上的問題時,Chrome應用中的<webview>
引起了我的注意,讓我感興趣。
所以我決定做一個我在<iframe>
面臨的問題的小例子,看看<webview>
是否解決了問題。 根據我對觀看Chrome Dev視頻的理解, webview
在與您的應用程序不同的單獨進程中運行; 它與您的應用沒有相同的權限。 所以我假設如果運行中的內容以某種方式與“主線程”(app)分開,我猜他們的內容將彼此分開執行,不會阻止應用程序或其他任何一個可能有一個可能長時間運行js executon。 因此我做了以下事情:
chrome.app.runtime.onLaunched.addListener(function() {
// Tell your app what to launch and how.
chrome.app.window.create('window.html', {
width: 1800,
height: 1000
});
});
{
// Required
"name": "Hello World!",
"version": "0.1",
"manifest_version": 2,
// Recommended
"description": "My first packaged app.",
"icons": { "16": "calculator-16.png", "128": "calculator-128.png" },
// "default_locale": "en",
// Pick one (or none) OF browser_action, page_action, theme, app
"app": {
"background": {
"scripts": [ "background.js" ]
}
},
"minimum_chrome_version": "23",
"permissions": [ "webview" ]
}
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div>Hello, world!</div>
<webview id="wv1" style="width: 450px; height: 300px; border: 2px solid red" src="http://www.google.com"></webview>
<webview id="wv2" style="width: 450px; height: 300px; border: 2px solid red" src="http://www.nytimes.com"></webview>
<webview id="wv3" style="width: 450px; height: 300px; border: 2px solid red" src="http://www.stackoverflow.com"></webview>
<webview id="wv4" style="width: 450px; height: 300px; border: 2px solid red" src="http://db.tt/FCCA7nuz"></webview>
</body>
</html>
其中三個webview是普通的網頁,第四個只是一個長期運行的js文件的例子,你可以檢查代碼或我可以在以后提供它。 如果我打開4個谷歌瀏覽器瀏覽器窗口,輸入地址,按回車鍵,我會觀察到:3個頁面立即加載,另一個與長js執行仍然有效。
如果我在網頁中執行此操作,使用打開這4個網頁,因為它們都在同一個進程中,如果由於js執行導致1個頁面緩慢/阻塞,則所有其他網頁都將被阻止。
現在使用Chrome App,使用我注意到一些有趣和奇怪的行為。 我注意到以下幾點:
<webview id="wv5" style="width: 450px; height: 300px; border: 2px solid red" src="http://developer.chrome.com"></webview>
,對我來說會發生的是:前三個加載,第四個是執行,完成后顯示然后我看到第五個渲染。 我的主要問題/疑問是關於行為,因為它們實際上是在一個單獨的進程中運行,為什么它與瀏覽器窗口沒有相同的行為,例如,為什么那個webview會阻止其他人工作/渲染,是不是按原樣工作? 我應該做一些解決方法來檢測一段時間后webview是否沒有完成跳過負載並讓其他人加載,那么我可以回到慢速?
先感謝您。
Web視圖在與您的應用程序不同的進程中運行,但它們在同一分區中以相同的進程運行。 如果未指定分區屬性,則它們將處於相同的默認屬性中。 如果您查看Chrome任務管理器(shift + esc),您會看到:
(注意Process ID列)
如果您使用tag屬性將每個webview設置為不同的分區:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div>Hello, world!</div>
<webview id="wv1" partition="p1" style="width: 450px; height: 300px; border: 2px solid red" src="http://www.google.com"></webview>
<webview id="wv2" partition="p2" style="width: 450px; height: 300px; border: 2px solid red" src="http://www.nytimes.com"></webview>
<webview id="wv3" partition="p3" style="width: 450px; height: 300px; border: 2px solid red" src="http://www.stackoverflow.com"></webview>
<webview id="wv4" partition="p4" style="width: 450px; height: 300px; border: 2px solid red" src="http://db.tt/FCCA7nuz"></webview>
</body>
</html>
您將看到每個webview現在都在自己的進程中運行:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.