使用WebView元素在Electron应用程序中显示其他页面时,是否可以读取和写入其Cookie?
是的你可以:
const { session } = require('electron').remote
// Here we access the session via the partition name
// You could also get it from the webContents object
// (webContents.session)
const cookies = session.fromPartition(<yourWebviewPartionName>).cookies
// Get a specific Cookie
cookies.get(
{
url: <targetURL>,
name: <cookieName>
},
(error, result) => console.log('Found the following cookies', result)
)
// Get all cookies
cookies.get(
{},
(error, result) => console.log('Found the following cookies', result)
)
// Remove a cookie
cookies.remove(
<targetURL>,
<cookieName>,
error => {
if (error) throw error
console.log('cookie deleted')
}
)
Run Code Online (Sandbox Code Playgroud)
document.cookies通过contentscripts 访问(预加载脚本)| 归档时间: |
|
| 查看次数: |
3823 次 |
| 最近记录: |