/*1* index.js2*3* Copyright (c) 2021 Andrea Cardaci <[email protected]>4*5* Deno port Copyright (C) 2022 Posit Software, PBC6*/78import EventEmitter from "events/mod.ts";9import Chrome from "./chrome.js";1011export default CDP;12export { Protocol, List, New, Activate, Close, Version } from "./devtools.js";13import { nextTick } from "../../deno/next-tick.ts";1415// const EventEmitter = require('events');16// const dns = require('dns');1718/* const devtools = require('./lib/devtools.js');19const Chrome = require('./lib/chrome.js');20*/21// XXX reset the default that has been changed in22// (https://github.com/nodejs/node/pull/39987) to prefer IPv4. since23// implementations alway bind on 127.0.0.1 this solution should be fairly safe24// (see #467)25/*if (dns.setDefaultResultOrder) {26dns.setDefaultResultOrder('ipv4first');27}*/2829function CDP(options, callback) {30if (typeof options === "function") {31callback = options;32options = undefined;33}34const notifier = new EventEmitter();35if (typeof callback === "function") {36// allow to register the error callback later37nextTick(() => {38new Chrome(options, notifier);39});40return notifier.once("connect", callback);41} else {42return new Promise((fulfill, reject) => {43notifier.once("connect", fulfill);44notifier.once("error", reject);45new Chrome(options, notifier);46});47}48}495051