|
3 | 3 |
|
4 | 4 | [TOC]
|
5 | 5 |
|
6 |
| -Use the `<webview>` tag to embed 'guest' content (such as web pages) in your app. Different from the `<iframe>`, the `<webview>` runs in a separate process than your app; it doesn't have the same permissions as your app and all interactions between your app and embedded content will be asynchronous. This keeps your app safe from the embedded content. |
| 6 | +Use the `<webview>` tag to embed `guest` content (such as web pages) in your app. Different from the `<iframe>`, the `<webview>` runs in a separate process than your app; it doesn't have the same permissions as your app and all interactions between your app and embedded content will be asynchronous. This keeps your app safe from the embedded content. |
7 | 7 |
|
8 | 8 | ## Synopsis
|
9 | 9 |
|
10 | 10 | To embed a web page in your app, add the webview tag to your app's embedder page (this is the app page that will display the guest content). In its simplest form, the webview tag includes the src of the web page and css styles that control the appearance of the webview container:
|
11 | 11 |
|
12 | 12 | ```html
|
13 |
| -<webview id="foo" src="http://www.google.com/" style="width:640px; height:480px"></webview> |
| 13 | +<webview id="foo" src="http://www.google.com/" style="width:640px; height:480px"> |
| 14 | +</webview> |
14 | 15 | ```
|
15 | 16 |
|
16 | 17 | ## References
|
@@ -38,24 +39,27 @@ Add the following permission to the manifest:
|
38 | 39 | }
|
39 | 40 | ```
|
40 | 41 |
|
41 |
| -and add 'partition="trusted"' attribute to the webview tag. |
| 42 | +and add `partition="trusted"` attribute to the webview tag. |
42 | 43 |
|
43 | 44 | ### Node.js support in webview
|
44 | 45 |
|
45 | 46 | To enable Node.js support in WebView, add the `allownw` attribute to the webview tag. Then Node.js will be turned on, no matter it loads local file or remote site. Use this feature with caution because webview is normally supposed to load untrusted contents.
|
46 | 47 |
|
47 | 48 | ### executeScript in main world
|
48 | 49 |
|
49 |
| -The [executeScript function in Chrome](https://developer.chrome.com/apps/tags/webview#method-executeScript) lets you inject JS code into webview, but in a isolated world. To access JS objects in the target DOM context, you can inject code into the main world context instead. Simply adding `{mainWorld: true}` to `InjectDetails` typed parameter of the function. |
| 50 | +The [executeScript function in Chrome](https://developer.chrome.com/apps/tags/webview#method-executeScript) lets you inject JS code into webview, but in an isolated world. To access JS objects in the target DOM context, you can inject code into the main world context instead. Simply adding `{mainWorld: true}` to `InjectDetails` typed parameter of the function. |
50 | 51 |
|
51 | 52 | ### Cookies support in webview
|
52 | 53 |
|
53 |
| -Webview has 'getCookieStoreId()' function which returns storeId which can be used in [chrome.cookies](https://developer.chrome.com/extensions/cookies) API. |
| 54 | +Webview has `getCookieStoreId()` function which returns storeId which can be used in [chrome.cookies](https://developer.chrome.com/extensions/cookies) API. |
54 | 55 |
|
55 | 56 | ##### Example in console:
|
56 |
| -Lets assume you have simple NW.js app with webview. |
| 57 | +Let's assume you have simple NW.js app with webview. |
57 | 58 |
|
58 | 59 | Show all cookies for e.g. http://docs.nwjs.io in console (to have some cookies there you need to visit page first):
|
59 |
| -```html |
60 |
| -chrome.cookies.getAll({url:"http://docs.nwjs.io", storeId:webview.getCookieStoreId()}, console.log.bind(console)); |
61 |
| -``` |
| 60 | + ```javascript |
| 61 | + chrome.cookies.getAll({ |
| 62 | + url:"http://docs.nwjs.io", |
| 63 | + storeId:webview.getCookieStoreId() |
| 64 | + }, console.log.bind(console)); |
| 65 | + ``` |
0 commit comments