Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 带有多个选项卡式浏览器窗口的Electron应用程序连接到https站点_Javascript_Html_Node.js_Electron - Fatal编程技术网

Javascript 带有多个选项卡式浏览器窗口的Electron应用程序连接到https站点

Javascript 带有多个选项卡式浏览器窗口的Electron应用程序连接到https站点,javascript,html,node.js,electron,Javascript,Html,Node.js,Electron,我正在尝试使用Electron创建我自己的版本 该应用程序应该允许多个URL(如和)可见,并具有选项卡式界面 我尝试过生成Webview和BrowserWindow WebView似乎无法完全加载Messenger(不加载登录) 浏览器窗口从主窗口弹出 我之前也尝试过iFrames,但这是不可能的 关于实现允许cookie/https的选项卡式最小浏览器界面的最佳方法,有什么想法吗 index.html <html> <head> <style>

我正在尝试使用Electron创建我自己的版本

该应用程序应该允许多个URL(如和)可见,并具有选项卡式界面

我尝试过生成Webview和BrowserWindow

  • WebView似乎无法完全加载Messenger(不加载登录)
  • 浏览器窗口从主窗口弹出
我之前也尝试过iFrames,但这是不可能的

关于实现允许cookie/https的选项卡式最小浏览器界面的最佳方法,有什么想法吗

index.html

<html>
<head>
    <style>
    webview {
        display: inline-flex; 
        width: 800px; 
        height: 600px;
    }
    </style>
</head>
<body>
    <form name="form">
        <input name="input" placeholder="https://messenger.com/" value="https://messenger.com">
        <button type="submit">submit</button>
    </form>
    <div class="tabs">
    </div>
    <div class="webviews">
    </div>
    <!--<webview src="https://messenger.com/" autosize="on" nodeintegration="on" disablewebsecurity="on" webpreferences="allowRunningInsecureContent"></webview>-->
    <script type="text/javascript">
        require('./app.js')
    </script>
</body>
</html>
app.js

const {app, BrowserWindow, BrowserView} = require('electron')

app.on('ready', createWindow)

function createWindow(){
    let win = new BrowserWindow({
        width: 1000, 
        height: 600,
        height: 600, 
        "node-integration": "iframe", // and this line
        "web-preferences": {
            "web-security": false,
            "nodeIntegration": false,
        }
    })

    win.on('closed', () => {
        win = null
    })

    win.webContents.openDevTools()

    // Load a remote URL
    //win.loadURL('https://github.com')

    // Or load a local HTML file
    win.loadURL(`file://${__dirname}/index.html`)

    /*win.webContents.session.webRequest.onHeadersReceived({}, (d, c) => {
        if(d.responseHeaders['x-frame-options'] || d.responseHeaders['X-Frame-Options']){
            delete d.responseHeaders['x-frame-options']
            delete d.responseHeaders['X-Frame-Options']
        }
        c({cancel: false, responseHeaders: d.responseHeaders})
    })*/

}

//app.commandLine.appendSwitch('disable-web-security')
const {app, BrowserWindow, BrowserView} = require('electron').remote

let tabs = document.querySelector(".tabs")
let webviews = document.querySelector(".webviews")

document.getElementsByTagName("form")[0].onsubmit = function(event){
    //createWebview(form.input.value)
    createBrowserWindow(form.input.value)
    return false;
}

function createWebview(url){

    let webview = new WebView()
    webview.setAttribute("autosize","on")
    webview.setAttribute("nodeintegration","on")
    webview.setAttribute("disablewebsecurity","on")
    webview.setAttribute("webpreferences","allowRunningInsecureContent")
    webview.src = url
    webviews.appendChild(webview)

    let tab = document.createElement("div")
    tab.textContent = url
    tab.target = webview

    tabs.appendChild(tab)

}

function createBrowserWindow(url){

    let win = new BrowserWindow({
        width: 800, 
        height: 600,
        y: 100,
        x: 100,
        webPreferences: {
            webSecurity: false,
            nodeIntegration: false
        }
    })

    win.setMenu(null)

    win.on('closed', () => {
        win = null
    })

    view = new BrowserView({
        webPreferences: {
            nodeIntegration: false
        }
    })

    win.webContents.openDevTools()

    // Load a remote URL
    win.loadURL(url)

}
很明显,如果您想要一个单一窗口,这是一种解决方法。它也比
好得多,因为它安全地与您的应用程序隔离,并在单独的进程中运行

见文件:


如果messenger.com无法正确加载,这应该是您应该解决的问题(例如,检查控制台消息、网络日志)。按照你的直觉去做,你的第一个选择是正确的,现在要做的是让它发挥作用。

谢谢,我让它发挥作用了。我用头撞了它一会儿,通过移除我在生成的webview上添加的一些标记,甚至Messenger也决定展示自己。我使用
webview
做了类似的事情,但它最终使不同视图之间的通信变得复杂。听到不同的解决方案会很好