简体   繁体   English

DevTools 与页面断开连接,electron

[英]DevTools was disconnected from the page, electron

Guys i need to open some web application into my electron app, i used <webview> tag but [official docs][1] of electron offers to use BrowserView .伙计们,我需要在我的电子应用程序中打开一些网络应用程序,我使用了<webview>标签,但是电子的 [official docs][1] 提供使用BrowserView
so i used BrowserView , BUT i got DevTools was disconnected from the page error!所以我使用BrowserView ,但我发现 DevTools 与页面错误断开连接!
simply i need DevTools for my BrowserView not my entire app.只是我的 BrowserView 需要 DevTools, BrowserView不是我的整个应用程序。 what should i do?我该怎么办?

myCode: just main.js myCode:只是main.js

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

let win;
let view;
app.on('ready', () => {
    win = new BrowserWindow({width: 800, height: 600});
    win.on('closed', () => {
        win = null
    });
    view = new BrowserView({
        webPreferences: {
            nodeIntegration: false
        }
    });
    win.setBrowserView(view);
    view.setBounds({x: 0, y: 0, width: 800, height: 600});
    view.webContents.loadURL('https://example.com');
    win.openDevTools();
});

openDevTools is basically a function of webContents (when used on BrowserWindow it's only redirected ) openDevTools是基本上的函数webContents (上使用时BrowserWindow它仅重定向

So you can open devtools of main window with所以你可以打开主窗口的 devtools

win.webContents.openDevTools()

And for the BrowserView with而对于BrowserView

view.webContents.openDevTools()

This happens when you open DevTools without giving an HTML (or some valid URL) file to the current window.当您打开 DevTools 而不向当前窗口提供 HTML(或一些有效的 URL)文件时,就会发生这种情况。

When you start your application you need to load an HTML file to the window before use toggleDevTools .启动应用程序时,您需要在使用toggleDevTools之前将 HTML 文件加载到窗口。 Solve it by using for example mainWindow.loadUrl('url to an html file or some url') after you build mainWindow using BrowserWindow() .使用BrowserWindow()构建 mainWindow 后,通过使用例如mainWindow.loadUrl('url to an html file or some url')解决它。 You tried to open DevTools on the win window but it has no URL defined, so it is just an Electron window with anything inside of this.你试图在win窗口上打开 DevTools,但它没有定义 URL,所以它只是一个包含任何内容的 Electron 窗口。

I faced same issue.. not sure whats the exact error but in my case my model was returning null.我遇到了同样的问题..不知道确切的错误是什么,但在我的情况下,我的模型返回空值。 I changed that to some value and handled using jquery which resolved my problem.我将其更改为某个值并使用 jquery 进行处理,从而解决了我的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM