What is partition attribute for webview tag in Chr

2019-09-05 09:02发布

问题:

I'm developing a Google Chrome packaged app right now.

I'm going to use webview tag to embed webpages for this app that I'm working on.

And I was reading this document below that describe webview tag.

https://developer.chrome.com/apps/tags/webview

But, I didn't quite understand what this is for.

Could anyone please explain what partition attribute is for?

Thanks!

<webview id="foo" src="http://www.google.com/" style="width:640px; height:480px" partition="persist:googlepluswidgets"></webview>

Storage partition ID used by the webview tag. If the storage partition ID starts with persist: (partition="persist:googlepluswidgets"), the webview will use a persistent storage partition available to all guests in the app with the same storage partition ID. If the ID is unset or if there is no 'persist': prefix, the webview will use an in-memory storage partition. This value can only be modified before the first navigation, since the storage partition of an active renderer process cannot change. Subsequent attempts to modify the value will fail with a DOM exception. By assigning the same partition ID, multiple webviews can share the same storage partition.

回答1:

A browser has a certain local state; localStorage, sessionStorage, cookies, etc.

A webview is a "mini browser". You can have multiple webviews, and you need to indicate the same partition so that they share this state (be multiple "tabs" of the same browser). Note that they will not share their state with the main Chrome instance.

And if you want this state to persist through closing your window, you need to add persistent to the ID. Useful if you're working with something that needs cookies.

The ID itself doesn't mean anything, it's just an identifier.