Skip to content

webContents.debugger.sendCommand does not complete (callback) until something is loaded into the window #14810

Closed

Description

@bughit
  • Output of node_modules/.bin/electron --version: 3.0.0 x86
  • Operating System (Platform and Version): win7 sp1 x64

Expected Behavior
sendCommand completion should not be delayed

Actual behavior
sendCommand callback is delayed until loadURL (5 seconds in my example)

[2018-09-26T02:17:09.713Z] before sendCommand

[2018-09-26T02:17:09.714Z] after sendCommand

[2018-09-26T02:17:14.715Z] before loadURL

[2018-09-26T02:17:14.721Z] Inspector.targetReloadedAfterCrash:
{}

[2018-09-26T02:17:14.723Z] after loadURL

[2018-09-26T02:17:14.805Z] sendCommand callback:
error: {}
result: {}

To Reproduce
run the following

'use strict';

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

let win;

if (OFFSCREEN)
  app.disableHardwareAcceleration();

app.on('ready', () => {

  win = new BrowserWindow({
    width: 1440,
    height: 900,
    useContentSize: true,
    show: !OFFSCREEN,
    webPreferences: {
      nodeIntegration: false,
      partition: 'memory_partition_1',
      offscreen: OFFSCREEN
    },
  });

  if (OFFSCREEN) {
    win.webContents.setFrameRate(1);
    win.webContents.stopPainting();
  }

  win.webContents.on('did-stop-loading', event => {
    log('did-stop-loading: %s', win.webContents.getURL());
    setTimeout(exit, 2000);
  });


  const dev = win.webContents.debugger;
  dev.attach();
  dev.on('message', (event, method, params) => {
    log('%s:\n%O', method, params);
  });

  log('before sendCommand');
  dev.sendCommand('Page.enable', {}, (error, result) => log('sendCommand callback:\nerror: %O\nresult: %O', error, result));
  log('after sendCommand');

  setTimeout(() => {
    log('before loadURL');
    win.loadURL('http://example.org/');
    log('after loadURL');
  }, 5000);

});

function log(msg, ...args) {
  console.log(`[${new Date().toISOString()}] ${msg}\n`, ...args);
}

function exit() {
  log('exiting');
  app.exit();
}

Activity

  1. MarshallOfSound commented on Sep 26, 2018

    @MarshallOfSound
    Member

    @bughit Just like you can't debug an empty browser window with devtools you can't send any debugger messages to an empty browser window with the debugger API.

    This is working as intended, there is nothing to debug until the page starts loading.

    screen shot 2018-09-26 at 1 19 54 pm

  2. bughit commented on Sep 26, 2018

    @bughit
    ContributorAuthor

    you can't send any debugger messages to an empty browser window

    @MarshallOfSound Please clarify "can't". The attach and sendCommand calls do not fail and the message is not discarded or ignored, it's received and obeyed, so what is being delayed/buffered, the sending in the main process or the processing in the renderer?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions