最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - DevTools was disconnected from the page, electron - Stack Overflow

programmeradmin0浏览0评论

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.
so i used BrowserView, BUT i got DevTools was disconnected from the page error!
simply i need DevTools for my BrowserView not my entire app. what should i do?

myCode: just 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('');
    win.openDevTools();
});

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.
so i used BrowserView, BUT i got DevTools was disconnected from the page error!
simply i need DevTools for my BrowserView not my entire app. what should i do?

myCode: just 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.');
    win.openDevTools();
});
Share Improve this question edited Aug 22, 2021 at 18:27 Amir Meimari asked Mar 5, 2019 at 8:07 Amir MeimariAmir Meimari 5386 silver badges22 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 4

openDevTools is basically a function of webContents (when used on BrowserWindow it's only redirected)

So you can open devtools of main window with

win.webContents.openDevTools()

And for the BrowserView with

view.webContents.openDevTools()

This happens when you open DevTools without giving an HTML (or some valid URL) file to the current window.

When you start your application you need to load an HTML file to the window before use toggleDevTools. Solve it by using for example mainWindow.loadUrl('url to an html file or some url') after you build mainWindow using BrowserWindow(). 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.

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.

发布评论

评论列表(0)

  1. 暂无评论