Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/src/core/cri/deno-cri/index.js
3587 views
1
/*
2
* index.js
3
*
4
* Copyright (c) 2021 Andrea Cardaci <[email protected]>
5
*
6
* Deno port Copyright (C) 2022 Posit Software, PBC
7
*/
8
9
import EventEmitter from "events/mod.ts";
10
import Chrome from "./chrome.js";
11
12
export default CDP;
13
export { Protocol, List, New, Activate, Close, Version } from "./devtools.js";
14
import { nextTick } from "../../deno/next-tick.ts";
15
16
// const EventEmitter = require('events');
17
// const dns = require('dns');
18
19
/* const devtools = require('./lib/devtools.js');
20
const Chrome = require('./lib/chrome.js');
21
*/
22
// XXX reset the default that has been changed in
23
// (https://github.com/nodejs/node/pull/39987) to prefer IPv4. since
24
// implementations alway bind on 127.0.0.1 this solution should be fairly safe
25
// (see #467)
26
/*if (dns.setDefaultResultOrder) {
27
dns.setDefaultResultOrder('ipv4first');
28
}*/
29
30
function CDP(options, callback) {
31
if (typeof options === "function") {
32
callback = options;
33
options = undefined;
34
}
35
const notifier = new EventEmitter();
36
if (typeof callback === "function") {
37
// allow to register the error callback later
38
nextTick(() => {
39
new Chrome(options, notifier);
40
});
41
return notifier.once("connect", callback);
42
} else {
43
return new Promise((fulfill, reject) => {
44
notifier.once("connect", fulfill);
45
notifier.once("error", reject);
46
new Chrome(options, notifier);
47
});
48
}
49
}
50
51