cloudflare
Version:
The official TypeScript library for the Cloudflare API
159 lines • 6.24 kB
JavaScript
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from "../../../../core/resource.mjs";
import * as LiveViewAPI from "./live-view.mjs";
import { BaseLiveView, LiveView } from "./live-view.mjs";
import * as PageAPI from "./page.mjs";
import { BasePage, Page } from "./page.mjs";
import * as TargetsAPI from "./targets.mjs";
import { BaseTargets, Targets, } from "./targets.mjs";
import { buildHeaders } from "../../../../internal/headers.mjs";
import { path } from "../../../../internal/utils/path.mjs";
export var BaseBrowser = /* @__PURE__ */ (() => {
class BaseBrowser extends APIResource {
/**
* Acquires a browser and returns its session ID and websocket URL. Optionally
* accepts a JSON body with session guardrails to restrict outbound HTTP/S traffic.
*
* @example
* ```ts
* const browser =
* await client.browserRendering.devtools.browser.create({
* account_id: 'account_id',
* });
* ```
*/
create(params, options) {
const { account_id, keep_alive, lab, liveViewUrlExpiresInMs, recording, targets, ...body } = params;
return this._client.post(path `/accounts/${account_id}/browser-rendering/devtools/browser`, {
query: { keep_alive, lab, liveViewUrlExpiresInMs, recording, targets },
body,
...options,
});
}
/**
* Closes an existing browser session.
*
* @example
* ```ts
* const browser =
* await client.browserRendering.devtools.browser.delete(
* '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
* { account_id: 'account_id' },
* );
* ```
*/
delete(sessionID, params, options) {
const { account_id } = params;
return this._client.delete(path `/accounts/${account_id}/browser-rendering/devtools/browser/${sessionID}`, options);
}
/**
* Establishes a WebSocket connection to an existing browser session.
*
* @example
* ```ts
* await client.browserRendering.devtools.browser.connect(
* '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
* { account_id: 'account_id' },
* );
* ```
*/
connect(sessionID, params, options) {
const { account_id, 'cf-brapi-guardrails': cfBrapiGuardrails, ...query } = params;
return this._client.get(path `/accounts/${account_id}/browser-rendering/devtools/browser/${sessionID}`, {
query,
...options,
headers: buildHeaders([
{
Accept: '*/*',
...(cfBrapiGuardrails != null ? { 'cf-brapi-guardrails': cfBrapiGuardrails } : undefined),
},
options?.headers,
]),
});
}
/**
* Acquires and establishes a WebSocket connection to a browser session. Session
* guardrails may be supplied in the `cf-brapi-guardrails` header as
* base64url-encoded JSON of the same `guardrails` object the POST body accepts
* (for example `{"allowedDomains":["*.example.com"]}`).
*
* @example
* ```ts
* await client.browserRendering.devtools.browser.launch({
* account_id: 'account_id',
* });
* ```
*/
launch(params, options) {
const { account_id, 'cf-brapi-guardrails': cfBrapiGuardrails, ...query } = params;
return this._client.get(path `/accounts/${account_id}/browser-rendering/devtools/browser`, {
query,
...options,
headers: buildHeaders([
{
Accept: '*/*',
...(cfBrapiGuardrails != null ? { 'cf-brapi-guardrails': cfBrapiGuardrails } : undefined),
},
options?.headers,
]),
});
}
/**
* Returns the complete Chrome DevTools Protocol schema including all domains,
* commands, events, and types. This schema describes the entire CDP API surface.
*
* @example
* ```ts
* const response =
* await client.browserRendering.devtools.browser.protocol(
* '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
* { account_id: 'account_id' },
* );
* ```
*/
protocol(sessionID, params, options) {
const { account_id } = params;
return this._client.get(path `/accounts/${account_id}/browser-rendering/devtools/browser/${sessionID}/json/protocol`, options);
}
/**
* Get browser version metadata.
*
* @example
* ```ts
* const response =
* await client.browserRendering.devtools.browser.version(
* '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
* { account_id: 'account_id' },
* );
* ```
*/
version(sessionID, params, options) {
const { account_id } = params;
return this._client.get(path `/accounts/${account_id}/browser-rendering/devtools/browser/${sessionID}/json/version`, options);
}
}
BaseBrowser._key = Object.freeze([
'browserRendering',
'devtools',
'browser',
]);
return BaseBrowser;
})();
export var Browser = /* @__PURE__ */ (() => {
class Browser extends BaseBrowser {
constructor() {
super(...arguments);
this.liveView = new LiveViewAPI.LiveView(this._client);
this.page = new PageAPI.Page(this._client);
this.targets = new TargetsAPI.Targets(this._client);
}
}
Browser.LiveView = LiveView;
Browser.BaseLiveView = BaseLiveView;
Browser.Page = Page;
Browser.BasePage = BasePage;
Browser.Targets = Targets;
Browser.BaseTargets = BaseTargets;
return Browser;
})();
//# sourceMappingURL=browser.mjs.map