Use:

<webview src={MALL_LOGIN_URL}
         disablewebsecurity="true"
         allowpopups="true"
         useragent={USER_AGENT}
         preload={preloadJsFile}/>
Copy the code

Tag attributes

src

Specifying your own value for SRC reloads the current page. The SRC attribute can also accept data urls, such as data:text/plain, Hellp,world! .

<webview src="https://www.github.com/"></webview>
Copy the code

nodeintegration

When this property is present, the guest page in the WebView will have Node integration and can access low-level system resources using Node APIs like require and Process. Node integration is disabled by default in the visitor page.

<webview src="http://www.google.com/" nodeintegration></webview>
Copy the code

nodeintegrationinsubframes

Whether node.js integration is allowed in child pages (iframe) or child Windows (Child Window); The preloaded script is injected into each iframe, and you can use process.isMainFrame to determine if the current iframe is in the main frame.

<webview src="http://www.google.com/" nodeintegrationinsubframes></webview>
Copy the code

enableremotemodule

When this property is false, the remote module will not be accessible to the visitor page in the WebView. By default, remote modules are available.

<webview src="http://www.google.com/" enableremotemodule="false"></webview>
Copy the code

plugins

When this property is present, the visitor page in the WebView will be able to use the browser plug-in. Plug-ins are disabled by default.

<webview src="https://www.github.com/" plugins></webview>
Copy the code

preload

Preload the specified script before the page runs other scripts. This script has access to all Node API scripts regardless of whether the page is integrated with Node. The script path is the absolute path of the file. When Node Integration is closed, the preloaded script reintroduces node’s global reference flag from global scope

<webview src="https://www.github.com/" preload="./test.js"></webview>
Copy the code

httpreferrer

HTTP URL reference

<webview src="https://www.github.com/" httpreferrer="http://cheng.guru"></webview>
Copy the code

useragent

It sets up the user agent for the visitor page before navigating to it. After the page loads, change the user agent using the setUserAgent method.

<webview SRC ="https://www.github.com/" useragent="Mozilla/5.0 (Windows NT 6.1; WOW64; Trident / 7.0; AS; The rv: 11.0) like Gecko "> < / webview >Copy the code

disablewebsecurity

When this property is present, web security is disabled on the visitor page. Web security is enabled by default.

<webview src="https://www.github.com/" disablewebsecurity></webview>
Copy the code

partition

Set the interface session using the partition string of the session. If a partition starts with persist:, the page will use a persistent session, run on all pages, and use the same partition. If there is no persist: prefix, the page will use an in-memory session. Multiple pages can share the same session by assigning the same partition. The default session is used.

<webview src="https://github.com" partition="persist:github"></webview>
<webview src="https://electronjs.org" partition="electron"></webview>
Copy the code

allowpopups

When this property exists, it allows the visitor page to open a new window. By default, pop-ups are disabled.

<webview src="https://www.github.com/" allowpopups></webview>
Copy the code

webpreferences

For a complete list of supported preference strings, see BrowserWindow

This string has the same format as the feature string in window.open. Those with only their own names will be given the true Boolean value. Other values can be assigned by =. Yes and 1 are resolved to true, while no and 0 are resolved to false.

<webview src="https://github.com" webpreferences="allowRunningInsecureContent, javascript=no"></webview>
Copy the code

enableblinkfeatures

Comma-separated list the characteristics of the need to enable such as CSSVariables, KeyboardEventKey in RuntimeEnabledFeatures. Json5 file view supported all the features.

<webview src="https://www.github.com/" enableblinkfeatures="PreciseMemoryInfo, CSSVariables"></webview>
Copy the code

disableblinkfeatures

To separate to disable the feature list, such as CSSVariables KeyboardEventKey. In RuntimeEnabledFeatures. Json5 file view supported all the features.

<webview src="https://www.github.com/" disableblinkfeatures="PreciseMemoryInfo, CSSVariables"></webview>
Copy the code

methods

Note: The <0> WebView </0> element must have been loaded before using the method.

const webview = document.querySelector('webview')
webview.addEventListener('dom-ready', () => {
  webview.openDevTools()
})
Copy the code

See the source link for more

Source: www.electronjs.org/docs/api/we…

Source: www.electronjs.org/docs/api/br…