1

Why do the Target domain events not fire? There is not supposed to be a Target.enable method but for some reason it still does not work. The Target.createTarget method does work though.

const CDP = require("chrome-remote-interface");

async function example() {
  let client = await CDP();

  const { Network, Page, Browser, Input, Target, DOM, Runtime } = client;
  await Page.enable();

  Target.targetInfoChanged((param) => {
    console.log("targetInfoChanged", param);
  });

  Target.receivedMessageFromTarget((param) => {
    console.log("receivedMessageFromTarget", param);
  });

  Target.targetCreated((param) => {
    console.log("targetCreated", param);
  });

  Target.targetDestroyed((param) => {
    console.log("targetDestroyed", param);
  });

  Page.loadEventFired((param) => {
    console.log("load", param);
  }); 
  
  await Target.createTarget({ url: "https://www.google.com/" });

  await new Promise(() => {});
  return
}

example();

comctimert
  • 43
  • 4

1 Answers1

1

A fun thing about the Target Domain is that it does not have an enable method. However, it does have setDiscoverTargets method, that is used to enable some of the events (as documented). Call it with discover set to true and it should work for you :)

Kle0s
  • 113
  • 1
  • 8