Path: blob/main/src/core/cri/deno-cri/devtools.js
3587 views
/*1* devtools.js2*3* Copyright (c) 2021 Andrea Cardaci <[email protected]>4*5* Deno port Copyright (C) 2022 Posit Software, PBC6*/78import * as defaults from "./defaults.js";9import externalRequest from "./external-request.js";1011// don't load localDescriptor for now12// import localDescriptor from "./protocol.json" assert { type: "json" };1314// options.path must be specified; callback(err, data)15function devToolsInterface(options, callback) {16options.host = options.host || defaults.HOST;17options.port = options.port || defaults.PORT;18options.secure = !!options.secure;19options.useHostName = !!options.useHostName;20options.alterPath = options.alterPath || ((path) => path);21// allow the user to alter the path22const newOptions = { ...options };23newOptions.path = options.alterPath(options.path);24newOptions.protocol = options.secure ? "https" : "http";25return externalRequest(newOptions, callback);26}2728export async function Protocol(options) {29// this version doesn't support options.local30/*if (options.local) {31return localDescriptor;32}*/3334// try to fetch the protocol remotely35options.path = "/json/protocol";36const result = await devToolsInterface(options);37return JSON.parse(result);38}3940export async function List(options) {41options.path = "/json/list";4243const result = await devToolsInterface(options);44return JSON.parse(result);45}4647export async function New(options) {48options.path = "/json/new";49if (Object.prototype.hasOwnProperty.call(options, "url")) {50options.path += `?${options.url}`;51}52// we don't mutate here because we don't want other53// calls to have PUT as the method54//55// 2023-03-28: We use PUT since that works on the Chromium release given56// by puppeteer as well as the later chromium versions which require PUT57options = {58...options,59method: "PUT",60};61const result = await devToolsInterface(options);62return JSON.parse(result);63}6465export async function Activate(options) {66options.path = "/json/activate/" + options.id;67await devToolsInterface(options);68return null;69}7071export async function Close(options) {72options.path = "/json/close/" + options.id;73await devToolsInterface(options);74return null;75}7677export async function Version(options) {78options.path = "/json/version";79const result = await devToolsInterface(options);80return JSON.parse(result);81}828384