cloudflare
Version:
The official TypeScript library for the Cloudflare API
165 lines • 6.67 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Browser = exports.BaseBrowser = void 0;
const tslib_1 = require("../../../../internal/tslib.js");
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
const resource_1 = require("../../../../core/resource.js");
const LiveViewAPI = tslib_1.__importStar(require("./live-view.js"));
const live_view_1 = require("./live-view.js");
const PageAPI = tslib_1.__importStar(require("./page.js"));
const page_1 = require("./page.js");
const TargetsAPI = tslib_1.__importStar(require("./targets.js"));
const targets_1 = require("./targets.js");
const headers_1 = require("../../../../internal/headers.js");
const path_1 = require("../../../../internal/utils/path.js");
var BaseBrowser = /* @__PURE__ */ (() => {
class BaseBrowser extends resource_1.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((0, path_1.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((0, path_1.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((0, path_1.path) `/accounts/${account_id}/browser-rendering/devtools/browser/${sessionID}`, {
query,
...options,
headers: (0, headers_1.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((0, path_1.path) `/accounts/${account_id}/browser-rendering/devtools/browser`, {
query,
...options,
headers: (0, headers_1.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((0, path_1.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((0, path_1.path) `/accounts/${account_id}/browser-rendering/devtools/browser/${sessionID}/json/version`, options);
}
}
BaseBrowser._key = Object.freeze([
'browserRendering',
'devtools',
'browser',
]);
return BaseBrowser;
})();
exports.BaseBrowser = BaseBrowser;
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 = live_view_1.LiveView;
Browser.BaseLiveView = live_view_1.BaseLiveView;
Browser.Page = page_1.Page;
Browser.BasePage = page_1.BasePage;
Browser.Targets = targets_1.Targets;
Browser.BaseTargets = targets_1.BaseTargets;
return Browser;
})();
exports.Browser = Browser;
//# sourceMappingURL=browser.js.map