如何在Electron中设置devTools窗口位置

rel*_*don 5 electron

我从文档中得到了这个

app.on('ready', function(){
    devtools = new BrowserWindow()
    window = new BrowserWindow({width:800, height:600})
    window.loadURL(path.join('file://', __dirname, 'static/index.html'))
    window.webContents.setDevToolsWebContents(devtools.webContents)
    window.webContents.openDevTools({mode: 'detach'})
})
Run Code Online (Sandbox Code Playgroud)

它打开两个窗口,一个是开发工具。但它就在主窗口的下面。

有没有办法让它们并排(屏幕足够大)?

Mik*_*ike 9

调用后,您setDevToolsWebContents只需调用 即可移动开发工具窗口devtools.setPosition(x, y)

以下是通过在移动时设置其位置来将开发工具移动到窗口旁边的示例:

app.on('ready', function () {
    var devtools = new BrowserWindow();
    var window   = new BrowserWindow({width: 800, height: 600});
    window.loadURL('/sf/ask/3652501471/');

    window.webContents.setDevToolsWebContents(devtools.webContents);
    window.webContents.openDevTools({mode: 'detach'});

    // Set the devtools position when the parent window has finished loading.
    window.webContents.once('did-finish-load', function () {
        var windowBounds = window.getBounds();
        devtools.setPosition(windowBounds.x + windowBounds.width, windowBounds.y);
    });

    // Set the devtools position when the parent window is moved.
    window.on('move', function () {
        var windowBounds = window.getBounds();
        devtools.setPosition(windowBounds.x + windowBounds.width, windowBounds.y);
    });
});
Run Code Online (Sandbox Code Playgroud)