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/devtools.js
3587 views
1
/*
2
* devtools.js
3
*
4
* Copyright (c) 2021 Andrea Cardaci <[email protected]>
5
*
6
* Deno port Copyright (C) 2022 Posit Software, PBC
7
*/
8
9
import * as defaults from "./defaults.js";
10
import externalRequest from "./external-request.js";
11
12
// don't load localDescriptor for now
13
// import localDescriptor from "./protocol.json" assert { type: "json" };
14
15
// options.path must be specified; callback(err, data)
16
function devToolsInterface(options, callback) {
17
options.host = options.host || defaults.HOST;
18
options.port = options.port || defaults.PORT;
19
options.secure = !!options.secure;
20
options.useHostName = !!options.useHostName;
21
options.alterPath = options.alterPath || ((path) => path);
22
// allow the user to alter the path
23
const newOptions = { ...options };
24
newOptions.path = options.alterPath(options.path);
25
newOptions.protocol = options.secure ? "https" : "http";
26
return externalRequest(newOptions, callback);
27
}
28
29
export async function Protocol(options) {
30
// this version doesn't support options.local
31
/*if (options.local) {
32
return localDescriptor;
33
}*/
34
35
// try to fetch the protocol remotely
36
options.path = "/json/protocol";
37
const result = await devToolsInterface(options);
38
return JSON.parse(result);
39
}
40
41
export async function List(options) {
42
options.path = "/json/list";
43
44
const result = await devToolsInterface(options);
45
return JSON.parse(result);
46
}
47
48
export async function New(options) {
49
options.path = "/json/new";
50
if (Object.prototype.hasOwnProperty.call(options, "url")) {
51
options.path += `?${options.url}`;
52
}
53
// we don't mutate here because we don't want other
54
// calls to have PUT as the method
55
//
56
// 2023-03-28: We use PUT since that works on the Chromium release given
57
// by puppeteer as well as the later chromium versions which require PUT
58
options = {
59
...options,
60
method: "PUT",
61
};
62
const result = await devToolsInterface(options);
63
return JSON.parse(result);
64
}
65
66
export async function Activate(options) {
67
options.path = "/json/activate/" + options.id;
68
await devToolsInterface(options);
69
return null;
70
}
71
72
export async function Close(options) {
73
options.path = "/json/close/" + options.id;
74
await devToolsInterface(options);
75
return null;
76
}
77
78
export async function Version(options) {
79
options.path = "/json/version";
80
const result = await devToolsInterface(options);
81
return JSON.parse(result);
82
}
83
84