Add Brave CDP automation, replace Oracle browser mode
Connects to user's running Brave via Chrome DevTools Protocol to automate ChatGPT interaction. Uses puppeteer-core to open a tab, send the prompt, wait for response, and extract the result. No cookies, no separate profiles, no copy/paste. Just connects to the browser where the user is already logged in. One-time setup: relaunch Brave with --remote-debugging-port=9222 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
37
node_modules/chromium-bidi/lib/esm/bidiMapper/modules/browser/BrowserProcessor.d.ts
generated
vendored
Normal file
37
node_modules/chromium-bidi/lib/esm/bidiMapper/modules/browser/BrowserProcessor.d.ts
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Copyright 2023 Google LLC.
|
||||
* Copyright (c) Microsoft Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { type Browser, type EmptyResult, type Session } from '../../../protocol/protocol.js';
|
||||
import type { CdpClient } from '../../BidiMapper.js';
|
||||
import type { BrowsingContextStorage } from '../context/BrowsingContextStorage.js';
|
||||
import type { ContextConfigStorage } from './ContextConfigStorage.js';
|
||||
import type { UserContextStorage } from './UserContextStorage.js';
|
||||
export declare class BrowserProcessor {
|
||||
#private;
|
||||
constructor(browserCdpClient: CdpClient, browsingContextStorage: BrowsingContextStorage, configStorage: ContextConfigStorage, userContextStorage: UserContextStorage);
|
||||
close(): EmptyResult;
|
||||
createUserContext(params: Record<string, any>): Promise<Browser.CreateUserContextResult>;
|
||||
removeUserContext(params: Browser.RemoveUserContextParameters): Promise<EmptyResult>;
|
||||
getUserContexts(): Promise<Browser.GetUserContextsResult>;
|
||||
setClientWindowState(params: Browser.SetClientWindowStateParameters): Promise<Browser.SetClientWindowStateResult>;
|
||||
getClientWindows(): Promise<Browser.GetClientWindowsResult>;
|
||||
setDownloadBehavior(params: Browser.SetDownloadBehaviorParameters): Promise<EmptyResult>;
|
||||
}
|
||||
/**
|
||||
* Proxy config parse implementation:
|
||||
* https://source.chromium.org/chromium/chromium/src/+/main:net/proxy_resolution/proxy_config.h;drc=743a82d08e59d803c94ee1b8564b8b11dd7b462f;l=107
|
||||
*/
|
||||
export declare function getProxyStr(proxyConfig: Session.ProxyConfiguration): string | undefined;
|
||||
289
node_modules/chromium-bidi/lib/esm/bidiMapper/modules/browser/BrowserProcessor.js
generated
vendored
Normal file
289
node_modules/chromium-bidi/lib/esm/bidiMapper/modules/browser/BrowserProcessor.js
generated
vendored
Normal file
@@ -0,0 +1,289 @@
|
||||
/**
|
||||
* Copyright 2023 Google LLC.
|
||||
* Copyright (c) Microsoft Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { InvalidArgumentException, NoSuchUserContextException, UnknownErrorException, UnsupportedOperationException, } from '../../../protocol/protocol.js';
|
||||
export class BrowserProcessor {
|
||||
#browserCdpClient;
|
||||
#browsingContextStorage;
|
||||
#configStorage;
|
||||
#userContextStorage;
|
||||
constructor(browserCdpClient, browsingContextStorage, configStorage, userContextStorage) {
|
||||
this.#browserCdpClient = browserCdpClient;
|
||||
this.#browsingContextStorage = browsingContextStorage;
|
||||
this.#configStorage = configStorage;
|
||||
this.#userContextStorage = userContextStorage;
|
||||
}
|
||||
close() {
|
||||
// Ensure that it is put at the end of the event loop.
|
||||
// This way we send back the response before closing the tab.
|
||||
// Always catch uncaught exceptions.
|
||||
setTimeout(() => this.#browserCdpClient.sendCommand('Browser.close').catch(() => { }), 0);
|
||||
return {};
|
||||
}
|
||||
async createUserContext(params) {
|
||||
// `params` is a record to provide legacy `goog:` parameters. Now as the `proxy`
|
||||
// parameter is specified, we should get rid of `goog:proxyServer` and
|
||||
// `goog:proxyBypassList` and make the params of type
|
||||
// `Browser.CreateUserContextParameters`.
|
||||
const w3cParams = params;
|
||||
const globalConfig = this.#configStorage.getGlobalConfig();
|
||||
if (w3cParams.acceptInsecureCerts !== undefined) {
|
||||
if (w3cParams.acceptInsecureCerts === false &&
|
||||
globalConfig.acceptInsecureCerts === true)
|
||||
// TODO: https://github.com/GoogleChromeLabs/chromium-bidi/issues/3398
|
||||
throw new UnknownErrorException(`Cannot set user context's "acceptInsecureCerts" to false, when a capability "acceptInsecureCerts" is set to true`);
|
||||
}
|
||||
const request = {};
|
||||
if (w3cParams.proxy) {
|
||||
const proxyStr = getProxyStr(w3cParams.proxy);
|
||||
if (proxyStr) {
|
||||
request.proxyServer = proxyStr;
|
||||
}
|
||||
if (w3cParams.proxy.noProxy) {
|
||||
request.proxyBypassList = w3cParams.proxy.noProxy.join(',');
|
||||
}
|
||||
}
|
||||
else {
|
||||
// TODO: remove after Puppeteer stops using it.
|
||||
if (params['goog:proxyServer'] !== undefined) {
|
||||
request.proxyServer = params['goog:proxyServer'];
|
||||
}
|
||||
const proxyBypassList = params['goog:proxyBypassList'] ?? undefined;
|
||||
if (proxyBypassList) {
|
||||
request.proxyBypassList = proxyBypassList.join(',');
|
||||
}
|
||||
}
|
||||
const context = await this.#browserCdpClient.sendCommand('Target.createBrowserContext', request);
|
||||
await this.#applyDownloadBehavior(globalConfig.downloadBehavior ?? null, context.browserContextId);
|
||||
this.#configStorage.updateUserContextConfig(context.browserContextId, {
|
||||
acceptInsecureCerts: params['acceptInsecureCerts'],
|
||||
userPromptHandler: params['unhandledPromptBehavior'],
|
||||
});
|
||||
return {
|
||||
userContext: context.browserContextId,
|
||||
};
|
||||
}
|
||||
async removeUserContext(params) {
|
||||
const userContext = params.userContext;
|
||||
if (userContext === 'default') {
|
||||
throw new InvalidArgumentException('`default` user context cannot be removed');
|
||||
}
|
||||
try {
|
||||
await this.#browserCdpClient.sendCommand('Target.disposeBrowserContext', {
|
||||
browserContextId: userContext,
|
||||
});
|
||||
}
|
||||
catch (err) {
|
||||
// https://source.chromium.org/chromium/chromium/src/+/main:content/browser/devtools/protocol/target_handler.cc;l=1424;drc=c686e8f4fd379312469fe018f5c390e9c8f20d0d
|
||||
if (err.message.startsWith('Failed to find context with id')) {
|
||||
throw new NoSuchUserContextException(err.message);
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
async getUserContexts() {
|
||||
return {
|
||||
userContexts: await this.#userContextStorage.getUserContexts(),
|
||||
};
|
||||
}
|
||||
async #getWindowInfo(targetId) {
|
||||
const windowInfo = await this.#browserCdpClient.sendCommand('Browser.getWindowForTarget', { targetId });
|
||||
return {
|
||||
// `active` is not supported in CDP yet.
|
||||
active: false,
|
||||
clientWindow: `${windowInfo.windowId}`,
|
||||
state: windowInfo.bounds.windowState ?? 'normal',
|
||||
height: windowInfo.bounds.height ?? 0,
|
||||
width: windowInfo.bounds.width ?? 0,
|
||||
x: windowInfo.bounds.left ?? 0,
|
||||
y: windowInfo.bounds.top ?? 0,
|
||||
};
|
||||
}
|
||||
async setClientWindowState(params) {
|
||||
const { clientWindow } = params;
|
||||
const bounds = {
|
||||
windowState: params.state,
|
||||
};
|
||||
if (params.state === 'normal') {
|
||||
if (params.width !== undefined) {
|
||||
bounds.width = params.width;
|
||||
}
|
||||
if (params.height !== undefined) {
|
||||
bounds.height = params.height;
|
||||
}
|
||||
if (params.x !== undefined) {
|
||||
bounds.left = params.x;
|
||||
}
|
||||
if (params.y !== undefined) {
|
||||
bounds.top = params.y;
|
||||
}
|
||||
}
|
||||
const windowId = Number.parseInt(clientWindow);
|
||||
if (isNaN(windowId)) {
|
||||
throw new InvalidArgumentException('no such client window');
|
||||
}
|
||||
await this.#browserCdpClient.sendCommand('Browser.setWindowBounds', {
|
||||
windowId,
|
||||
bounds,
|
||||
});
|
||||
const result = await this.#browserCdpClient.sendCommand('Browser.getWindowBounds', {
|
||||
windowId,
|
||||
});
|
||||
return {
|
||||
active: false,
|
||||
clientWindow: `${windowId}`,
|
||||
state: result.bounds.windowState ?? 'normal',
|
||||
height: result.bounds.height ?? 0,
|
||||
width: result.bounds.width ?? 0,
|
||||
x: result.bounds.left ?? 0,
|
||||
y: result.bounds.top ?? 0,
|
||||
};
|
||||
}
|
||||
async getClientWindows() {
|
||||
const topLevelTargetIds = this.#browsingContextStorage
|
||||
.getTopLevelContexts()
|
||||
.map((b) => b.cdpTarget.id);
|
||||
const clientWindows = await Promise.all(topLevelTargetIds.map(async (targetId) => await this.#getWindowInfo(targetId)));
|
||||
const uniqueClientWindowIds = new Set();
|
||||
const uniqueClientWindows = new Array();
|
||||
// Filter out duplicated client windows.
|
||||
for (const window of clientWindows) {
|
||||
if (!uniqueClientWindowIds.has(window.clientWindow)) {
|
||||
uniqueClientWindowIds.add(window.clientWindow);
|
||||
uniqueClientWindows.push(window);
|
||||
}
|
||||
}
|
||||
return { clientWindows: uniqueClientWindows };
|
||||
}
|
||||
#toCdpDownloadBehavior(downloadBehavior) {
|
||||
if (downloadBehavior === null)
|
||||
// CDP "default" behavior.
|
||||
return {
|
||||
behavior: 'default',
|
||||
};
|
||||
if (downloadBehavior?.type === 'denied')
|
||||
// Deny all the downloads.
|
||||
return {
|
||||
behavior: 'deny',
|
||||
};
|
||||
if (downloadBehavior?.type === 'allowed') {
|
||||
// CDP behavior "allow" means "save downloaded files to the specific download path".
|
||||
return {
|
||||
behavior: 'allow',
|
||||
downloadPath: downloadBehavior.destinationFolder,
|
||||
};
|
||||
}
|
||||
// Unreachable. Handled by params parser.
|
||||
throw new UnknownErrorException('Unexpected download behavior');
|
||||
}
|
||||
async #applyDownloadBehavior(downloadBehavior, userContext) {
|
||||
await this.#browserCdpClient.sendCommand('Browser.setDownloadBehavior', {
|
||||
...this.#toCdpDownloadBehavior(downloadBehavior),
|
||||
browserContextId: userContext === 'default' ? undefined : userContext,
|
||||
// Required for enabling download events.
|
||||
eventsEnabled: true,
|
||||
});
|
||||
}
|
||||
async setDownloadBehavior(params) {
|
||||
let userContexts;
|
||||
if (params.userContexts === undefined) {
|
||||
// Global download behavior.
|
||||
userContexts = (await this.#userContextStorage.getUserContexts()).map((c) => c.userContext);
|
||||
}
|
||||
else {
|
||||
// Download behavior for the specific user contexts.
|
||||
userContexts = Array.from(await this.#userContextStorage.verifyUserContextIdList(params.userContexts));
|
||||
}
|
||||
if (params.userContexts === undefined) {
|
||||
// Store the global setting to be applied for the future user contexts.
|
||||
this.#configStorage.updateGlobalConfig({
|
||||
downloadBehavior: params.downloadBehavior,
|
||||
});
|
||||
}
|
||||
else {
|
||||
params.userContexts.map((userContext) => this.#configStorage.updateUserContextConfig(userContext, {
|
||||
downloadBehavior: params.downloadBehavior,
|
||||
}));
|
||||
}
|
||||
await Promise.all(userContexts.map(async (userContext) => {
|
||||
// Download behavior can be already set per user context, in which case the global
|
||||
// one should not be applied.
|
||||
const downloadBehavior = this.#configStorage.getActiveConfig(undefined, userContext)
|
||||
.downloadBehavior ?? null;
|
||||
await this.#applyDownloadBehavior(downloadBehavior, userContext);
|
||||
}));
|
||||
return {};
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Proxy config parse implementation:
|
||||
* https://source.chromium.org/chromium/chromium/src/+/main:net/proxy_resolution/proxy_config.h;drc=743a82d08e59d803c94ee1b8564b8b11dd7b462f;l=107
|
||||
*/
|
||||
export function getProxyStr(proxyConfig) {
|
||||
if (proxyConfig.proxyType === 'direct' ||
|
||||
proxyConfig.proxyType === 'system') {
|
||||
// These types imply that Chrome should use its default behavior (e.g., direct
|
||||
// connection or system-configured proxy). No specific `proxyServer` string is
|
||||
// needed.
|
||||
return undefined;
|
||||
}
|
||||
if (proxyConfig.proxyType === 'pac') {
|
||||
throw new UnsupportedOperationException(`PAC proxy configuration is not supported per user context`);
|
||||
}
|
||||
if (proxyConfig.proxyType === 'autodetect') {
|
||||
throw new UnsupportedOperationException(`Autodetect proxy is not supported per user context`);
|
||||
}
|
||||
if (proxyConfig.proxyType === 'manual') {
|
||||
const servers = [];
|
||||
// HTTP Proxy
|
||||
if (proxyConfig.httpProxy !== undefined) {
|
||||
// servers.push(proxyConfig.httpProxy);
|
||||
servers.push(`http=${proxyConfig.httpProxy}`);
|
||||
}
|
||||
// SSL Proxy (uses 'https' scheme)
|
||||
if (proxyConfig.sslProxy !== undefined) {
|
||||
// servers.push(proxyConfig.sslProxy);
|
||||
servers.push(`https=${proxyConfig.sslProxy}`);
|
||||
}
|
||||
// SOCKS Proxy
|
||||
if (proxyConfig.socksProxy !== undefined ||
|
||||
proxyConfig.socksVersion !== undefined) {
|
||||
// socksVersion is mandatory and must be a valid integer if socksProxy is
|
||||
// specified.
|
||||
if (proxyConfig.socksProxy === undefined) {
|
||||
throw new InvalidArgumentException(`'socksVersion' cannot be set without 'socksProxy'`);
|
||||
}
|
||||
if (proxyConfig.socksVersion === undefined ||
|
||||
typeof proxyConfig.socksVersion !== 'number' ||
|
||||
!Number.isInteger(proxyConfig.socksVersion) ||
|
||||
proxyConfig.socksVersion < 0 ||
|
||||
proxyConfig.socksVersion > 255) {
|
||||
throw new InvalidArgumentException(`'socksVersion' must be between 0 and 255`);
|
||||
}
|
||||
servers.push(`socks=socks${proxyConfig.socksVersion}://${proxyConfig.socksProxy}`);
|
||||
}
|
||||
if (servers.length === 0) {
|
||||
// If 'manual' proxyType is chosen but no specific proxy servers (http, ssl, socks)
|
||||
// are provided, it means no proxy server should be configured.
|
||||
return undefined;
|
||||
}
|
||||
return servers.join(';');
|
||||
}
|
||||
// Unreachable.
|
||||
throw new UnknownErrorException(`Unknown proxy type`);
|
||||
}
|
||||
//# sourceMappingURL=BrowserProcessor.js.map
|
||||
1
node_modules/chromium-bidi/lib/esm/bidiMapper/modules/browser/BrowserProcessor.js.map
generated
vendored
Normal file
1
node_modules/chromium-bidi/lib/esm/bidiMapper/modules/browser/BrowserProcessor.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
50
node_modules/chromium-bidi/lib/esm/bidiMapper/modules/browser/ContextConfig.d.ts
generated
vendored
Normal file
50
node_modules/chromium-bidi/lib/esm/bidiMapper/modules/browser/ContextConfig.d.ts
generated
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* Copyright 2025 Google LLC.
|
||||
* Copyright (c) Microsoft Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import type { Protocol } from 'devtools-protocol';
|
||||
import type { Browser, BrowsingContext, Emulation, Session, UAClientHints } from '../../../protocol/protocol.js';
|
||||
/**
|
||||
* Represents a context configurations. It can be global, per User Context, or per
|
||||
* Browsing Context. The undefined value means the config will be taken from the upstream
|
||||
* config. `null` values means the value should be default regardless of the upstream.
|
||||
*/
|
||||
export declare class ContextConfig {
|
||||
acceptInsecureCerts?: boolean;
|
||||
clientHints?: UAClientHints.Emulation.ClientHintsMetadata | null;
|
||||
devicePixelRatio?: number | null;
|
||||
disableNetworkDurableMessages?: true;
|
||||
downloadBehavior?: Browser.DownloadBehavior | null;
|
||||
emulatedNetworkConditions?: Emulation.NetworkConditions | null;
|
||||
extraHeaders?: Protocol.Network.Headers;
|
||||
geolocation?: Emulation.GeolocationCoordinates | Emulation.GeolocationPositionError | null;
|
||||
locale?: string | null;
|
||||
maxTouchPoints?: number | null;
|
||||
prerenderingDisabled?: boolean;
|
||||
screenArea?: Emulation.ScreenArea | null;
|
||||
screenOrientation?: Emulation.ScreenOrientation | null;
|
||||
scriptingEnabled?: false | null;
|
||||
timezone?: string | null;
|
||||
userAgent?: string | null;
|
||||
userPromptHandler?: Session.UserPromptHandler;
|
||||
viewport?: BrowsingContext.Viewport | null;
|
||||
/**
|
||||
* Merges multiple `ContextConfig` objects. The configs are merged in the order they are
|
||||
* provided. For each property, the value from the last config that defines it will be
|
||||
* used. The final result will not contain any `undefined` or `null` properties.
|
||||
* `undefined` values are ignored. `null` values remove the already set value.
|
||||
*/
|
||||
static merge(...configs: (ContextConfig | undefined)[]): ContextConfig;
|
||||
}
|
||||
70
node_modules/chromium-bidi/lib/esm/bidiMapper/modules/browser/ContextConfig.js
generated
vendored
Normal file
70
node_modules/chromium-bidi/lib/esm/bidiMapper/modules/browser/ContextConfig.js
generated
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
* Copyright 2025 Google LLC.
|
||||
* Copyright (c) Microsoft Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* Represents a context configurations. It can be global, per User Context, or per
|
||||
* Browsing Context. The undefined value means the config will be taken from the upstream
|
||||
* config. `null` values means the value should be default regardless of the upstream.
|
||||
*/
|
||||
export class ContextConfig {
|
||||
// keep-sorted start block=yes
|
||||
acceptInsecureCerts;
|
||||
clientHints;
|
||||
devicePixelRatio;
|
||||
disableNetworkDurableMessages;
|
||||
downloadBehavior;
|
||||
emulatedNetworkConditions;
|
||||
// Extra headers are kept in CDP format.
|
||||
extraHeaders;
|
||||
geolocation;
|
||||
locale;
|
||||
maxTouchPoints;
|
||||
prerenderingDisabled;
|
||||
screenArea;
|
||||
screenOrientation;
|
||||
scriptingEnabled;
|
||||
// Timezone is kept in CDP format with GMT prefix for offset values.
|
||||
timezone;
|
||||
userAgent;
|
||||
userPromptHandler;
|
||||
viewport;
|
||||
// keep-sorted end
|
||||
/**
|
||||
* Merges multiple `ContextConfig` objects. The configs are merged in the order they are
|
||||
* provided. For each property, the value from the last config that defines it will be
|
||||
* used. The final result will not contain any `undefined` or `null` properties.
|
||||
* `undefined` values are ignored. `null` values remove the already set value.
|
||||
*/
|
||||
static merge(...configs) {
|
||||
const result = new ContextConfig();
|
||||
for (const config of configs) {
|
||||
if (!config) {
|
||||
continue;
|
||||
}
|
||||
for (const key in config) {
|
||||
const value = config[key];
|
||||
if (value === null) {
|
||||
delete result[key];
|
||||
}
|
||||
else if (value !== undefined) {
|
||||
result[key] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=ContextConfig.js.map
|
||||
1
node_modules/chromium-bidi/lib/esm/bidiMapper/modules/browser/ContextConfig.js.map
generated
vendored
Normal file
1
node_modules/chromium-bidi/lib/esm/bidiMapper/modules/browser/ContextConfig.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"ContextConfig.js","sourceRoot":"","sources":["../../../../../src/bidiMapper/modules/browser/ContextConfig.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAYH;;;;GAIG;AACH,MAAM,OAAO,aAAa;IACxB,8BAA8B;IAC9B,mBAAmB,CAAW;IAC9B,WAAW,CAAsD;IACjE,gBAAgB,CAAiB;IACjC,6BAA6B,CAAQ;IACrC,gBAAgB,CAAmC;IACnD,yBAAyB,CAAsC;IAC/D,wCAAwC;IACxC,YAAY,CAA4B;IACxC,WAAW,CAGF;IACT,MAAM,CAAiB;IACvB,cAAc,CAAiB;IAC/B,oBAAoB,CAAW;IAC/B,UAAU,CAA+B;IACzC,iBAAiB,CAAsC;IACvD,gBAAgB,CAAgB;IAChC,oEAAoE;IACpE,QAAQ,CAAiB;IACzB,SAAS,CAAiB;IAC1B,iBAAiB,CAA6B;IAC9C,QAAQ,CAAmC;IAC3C,kBAAkB;IAElB;;;;;OAKG;IACH,MAAM,CAAC,KAAK,CAAC,GAAG,OAAsC;QACpD,MAAM,MAAM,GAAG,IAAI,aAAa,EAAE,CAAC;QAEnC,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;YAC7B,IAAI,CAAC,MAAM,EAAE,CAAC;gBACZ,SAAS;YACX,CAAC;YACD,KAAK,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC;gBACzB,MAAM,KAAK,GAAG,MAAM,CAAC,GAA0B,CAAC,CAAC;gBACjD,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;oBACnB,OAAQ,MAAc,CAAC,GAAG,CAAC,CAAC;gBAC9B,CAAC;qBAAM,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;oBAC9B,MAAc,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;gBAC/B,CAAC;YACH,CAAC;QACH,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
|
||||
42
node_modules/chromium-bidi/lib/esm/bidiMapper/modules/browser/ContextConfigStorage.d.ts
generated
vendored
Normal file
42
node_modules/chromium-bidi/lib/esm/bidiMapper/modules/browser/ContextConfigStorage.d.ts
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
import { ContextConfig } from './ContextConfig.js';
|
||||
/**
|
||||
* Manages context-specific configurations. This class allows setting
|
||||
* configurations at three levels: global, user context, and browsing context.
|
||||
*
|
||||
* When `getActiveConfig` is called, it merges the configurations in a specific
|
||||
* order of precedence: `global -> user context -> browsing context`. For each
|
||||
* configuration property, the value from the highest-precedence level that has a
|
||||
* non-`undefined` value is used.
|
||||
*
|
||||
* The `update` methods (`updateGlobalConfig`, `updateUserContextConfig`,
|
||||
* `updateBrowsingContextConfig`) merge the provided configuration with the
|
||||
* existing one at the corresponding level. Properties with `undefined` values in
|
||||
* the provided configuration are ignored, preserving the existing value.
|
||||
*/
|
||||
export declare class ContextConfigStorage {
|
||||
#private;
|
||||
/**
|
||||
* Updates the global configuration. Properties with `undefined` values in the
|
||||
* provided `config` are ignored.
|
||||
*/
|
||||
updateGlobalConfig(config: ContextConfig): void;
|
||||
/**
|
||||
* Updates the configuration for a specific browsing context. Properties with
|
||||
* `undefined` values in the provided `config` are ignored.
|
||||
*/
|
||||
updateBrowsingContextConfig(browsingContextId: string, config: ContextConfig): void;
|
||||
/**
|
||||
* Updates the configuration for a specific user context. Properties with
|
||||
* `undefined` values in the provided `config` are ignored.
|
||||
*/
|
||||
updateUserContextConfig(userContext: string, config: ContextConfig): void;
|
||||
/**
|
||||
* Returns the current global configuration.
|
||||
*/
|
||||
getGlobalConfig(): ContextConfig;
|
||||
/**
|
||||
* Calculates the active configuration by merging global, user context, and
|
||||
* browsing context settings.
|
||||
*/
|
||||
getActiveConfig(topLevelBrowsingContextId: string | undefined, userContext: string): ContextConfig;
|
||||
}
|
||||
92
node_modules/chromium-bidi/lib/esm/bidiMapper/modules/browser/ContextConfigStorage.js
generated
vendored
Normal file
92
node_modules/chromium-bidi/lib/esm/bidiMapper/modules/browser/ContextConfigStorage.js
generated
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright 2025 Google LLC.
|
||||
* Copyright (c) Microsoft Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { ContextConfig } from './ContextConfig.js';
|
||||
/**
|
||||
* Manages context-specific configurations. This class allows setting
|
||||
* configurations at three levels: global, user context, and browsing context.
|
||||
*
|
||||
* When `getActiveConfig` is called, it merges the configurations in a specific
|
||||
* order of precedence: `global -> user context -> browsing context`. For each
|
||||
* configuration property, the value from the highest-precedence level that has a
|
||||
* non-`undefined` value is used.
|
||||
*
|
||||
* The `update` methods (`updateGlobalConfig`, `updateUserContextConfig`,
|
||||
* `updateBrowsingContextConfig`) merge the provided configuration with the
|
||||
* existing one at the corresponding level. Properties with `undefined` values in
|
||||
* the provided configuration are ignored, preserving the existing value.
|
||||
*/
|
||||
export class ContextConfigStorage {
|
||||
#global = new ContextConfig();
|
||||
#userContextConfigs = new Map();
|
||||
#browsingContextConfigs = new Map();
|
||||
/**
|
||||
* Updates the global configuration. Properties with `undefined` values in the
|
||||
* provided `config` are ignored.
|
||||
*/
|
||||
updateGlobalConfig(config) {
|
||||
this.#global = ContextConfig.merge(this.#global, config);
|
||||
}
|
||||
/**
|
||||
* Updates the configuration for a specific browsing context. Properties with
|
||||
* `undefined` values in the provided `config` are ignored.
|
||||
*/
|
||||
updateBrowsingContextConfig(browsingContextId, config) {
|
||||
this.#browsingContextConfigs.set(browsingContextId, ContextConfig.merge(this.#browsingContextConfigs.get(browsingContextId), config));
|
||||
}
|
||||
/**
|
||||
* Updates the configuration for a specific user context. Properties with
|
||||
* `undefined` values in the provided `config` are ignored.
|
||||
*/
|
||||
updateUserContextConfig(userContext, config) {
|
||||
this.#userContextConfigs.set(userContext, ContextConfig.merge(this.#userContextConfigs.get(userContext), config));
|
||||
}
|
||||
/**
|
||||
* Returns the current global configuration.
|
||||
*/
|
||||
getGlobalConfig() {
|
||||
return this.#global;
|
||||
}
|
||||
/**
|
||||
* Extra headers is a special case. The headers from the different levels have to be
|
||||
* merged instead of being overridden.
|
||||
*/
|
||||
#getExtraHeaders(topLevelBrowsingContextId, userContext) {
|
||||
const globalHeaders = this.#global.extraHeaders ?? {};
|
||||
const userContextHeaders = this.#userContextConfigs.get(userContext)?.extraHeaders ?? {};
|
||||
const browsingContextHeaders = topLevelBrowsingContextId === undefined
|
||||
? {}
|
||||
: (this.#browsingContextConfigs.get(topLevelBrowsingContextId)
|
||||
?.extraHeaders ?? {});
|
||||
return { ...globalHeaders, ...userContextHeaders, ...browsingContextHeaders };
|
||||
}
|
||||
/**
|
||||
* Calculates the active configuration by merging global, user context, and
|
||||
* browsing context settings.
|
||||
*/
|
||||
getActiveConfig(topLevelBrowsingContextId, userContext) {
|
||||
let result = ContextConfig.merge(this.#global, this.#userContextConfigs.get(userContext));
|
||||
if (topLevelBrowsingContextId !== undefined) {
|
||||
result = ContextConfig.merge(result, this.#browsingContextConfigs.get(topLevelBrowsingContextId));
|
||||
}
|
||||
// Extra headers is a special case which have to be treated in a special way.
|
||||
const extraHeaders = this.#getExtraHeaders(topLevelBrowsingContextId, userContext);
|
||||
result.extraHeaders =
|
||||
Object.keys(extraHeaders).length > 0 ? extraHeaders : undefined;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=ContextConfigStorage.js.map
|
||||
1
node_modules/chromium-bidi/lib/esm/bidiMapper/modules/browser/ContextConfigStorage.js.map
generated
vendored
Normal file
1
node_modules/chromium-bidi/lib/esm/bidiMapper/modules/browser/ContextConfigStorage.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"ContextConfigStorage.js","sourceRoot":"","sources":["../../../../../src/bidiMapper/modules/browser/ContextConfigStorage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAC,aAAa,EAAC,MAAM,oBAAoB,CAAC;AAEjD;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,oBAAoB;IAC/B,OAAO,GAAG,IAAI,aAAa,EAAE,CAAC;IAC9B,mBAAmB,GAAG,IAAI,GAAG,EAAyB,CAAC;IACvD,uBAAuB,GAAG,IAAI,GAAG,EAAyB,CAAC;IAE3D;;;OAGG;IACH,kBAAkB,CAAC,MAAqB;QACtC,IAAI,CAAC,OAAO,GAAG,aAAa,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC3D,CAAC;IAED;;;OAGG;IACH,2BAA2B,CACzB,iBAAyB,EACzB,MAAqB;QAErB,IAAI,CAAC,uBAAuB,CAAC,GAAG,CAC9B,iBAAiB,EACjB,aAAa,CAAC,KAAK,CACjB,IAAI,CAAC,uBAAuB,CAAC,GAAG,CAAC,iBAAiB,CAAC,EACnD,MAAM,CACP,CACF,CAAC;IACJ,CAAC;IAED;;;OAGG;IACH,uBAAuB,CAAC,WAAmB,EAAE,MAAqB;QAChE,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAC1B,WAAW,EACX,aAAa,CAAC,KAAK,CAAC,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC,CACvE,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,eAAe;QACb,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED;;;OAGG;IACH,gBAAgB,CACd,yBAA6C,EAC7C,WAAmB;QAEnB,MAAM,aAAa,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,IAAI,EAAE,CAAC;QACtD,MAAM,kBAAkB,GACtB,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,YAAY,IAAI,EAAE,CAAC;QAChE,MAAM,sBAAsB,GAC1B,yBAAyB,KAAK,SAAS;YACrC,CAAC,CAAC,EAAE;YACJ,CAAC,CAAC,CAAC,IAAI,CAAC,uBAAuB,CAAC,GAAG,CAAC,yBAAyB,CAAC;gBAC1D,EAAE,YAAY,IAAI,EAAE,CAAC,CAAC;QAE9B,OAAO,EAAC,GAAG,aAAa,EAAE,GAAG,kBAAkB,EAAE,GAAG,sBAAsB,EAAC,CAAC;IAC9E,CAAC;IAED;;;OAGG;IACH,eAAe,CACb,yBAA6C,EAC7C,WAAmB;QAEnB,IAAI,MAAM,GAAG,aAAa,CAAC,KAAK,CAC9B,IAAI,CAAC,OAAO,EACZ,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,WAAW,CAAC,CAC1C,CAAC;QACF,IAAI,yBAAyB,KAAK,SAAS,EAAE,CAAC;YAC5C,MAAM,GAAG,aAAa,CAAC,KAAK,CAC1B,MAAM,EACN,IAAI,CAAC,uBAAuB,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAC5D,CAAC;QACJ,CAAC;QAED,6EAA6E;QAC7E,MAAM,YAAY,GAAG,IAAI,CAAC,gBAAgB,CACxC,yBAAyB,EACzB,WAAW,CACZ,CAAC;QACF,MAAM,CAAC,YAAY;YACjB,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC;QAElE,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
|
||||
27
node_modules/chromium-bidi/lib/esm/bidiMapper/modules/browser/UserContextStorage.d.ts
generated
vendored
Normal file
27
node_modules/chromium-bidi/lib/esm/bidiMapper/modules/browser/UserContextStorage.d.ts
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* Copyright 2025 Google LLC.
|
||||
* Copyright (c) Microsoft Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import type { CdpClient } from '../../../cdp/CdpClient.js';
|
||||
import { type Browser } from '../../../protocol/protocol.js';
|
||||
export declare class UserContextStorage {
|
||||
#private;
|
||||
constructor(browserClient: CdpClient);
|
||||
getUserContexts(): Promise<[
|
||||
Browser.UserContextInfo,
|
||||
...Browser.UserContextInfo[]
|
||||
]>;
|
||||
verifyUserContextIdList(userContextIds: Browser.UserContext[]): Promise<Set<string>>;
|
||||
}
|
||||
52
node_modules/chromium-bidi/lib/esm/bidiMapper/modules/browser/UserContextStorage.js
generated
vendored
Normal file
52
node_modules/chromium-bidi/lib/esm/bidiMapper/modules/browser/UserContextStorage.js
generated
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* Copyright 2025 Google LLC.
|
||||
* Copyright (c) Microsoft Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { NoSuchUserContextException, } from '../../../protocol/protocol.js';
|
||||
export class UserContextStorage {
|
||||
#browserClient;
|
||||
constructor(browserClient) {
|
||||
this.#browserClient = browserClient;
|
||||
}
|
||||
async getUserContexts() {
|
||||
const result = await this.#browserClient.sendCommand('Target.getBrowserContexts');
|
||||
return [
|
||||
{
|
||||
userContext: 'default',
|
||||
},
|
||||
...result.browserContextIds.map((id) => {
|
||||
return {
|
||||
userContext: id,
|
||||
};
|
||||
}),
|
||||
];
|
||||
}
|
||||
async verifyUserContextIdList(userContextIds) {
|
||||
const foundContexts = new Set();
|
||||
if (!userContextIds.length) {
|
||||
return foundContexts;
|
||||
}
|
||||
const userContexts = await this.getUserContexts();
|
||||
const knownUserContextIds = new Set(userContexts.map((userContext) => userContext.userContext));
|
||||
for (const userContextId of userContextIds) {
|
||||
if (!knownUserContextIds.has(userContextId)) {
|
||||
throw new NoSuchUserContextException(`User context ${userContextId} not found`);
|
||||
}
|
||||
foundContexts.add(userContextId);
|
||||
}
|
||||
return foundContexts;
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=UserContextStorage.js.map
|
||||
1
node_modules/chromium-bidi/lib/esm/bidiMapper/modules/browser/UserContextStorage.js.map
generated
vendored
Normal file
1
node_modules/chromium-bidi/lib/esm/bidiMapper/modules/browser/UserContextStorage.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"UserContextStorage.js","sourceRoot":"","sources":["../../../../../src/bidiMapper/modules/browser/UserContextStorage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,EACL,0BAA0B,GAE3B,MAAM,+BAA+B,CAAC;AAEvC,MAAM,OAAO,kBAAkB;IAC7B,cAAc,CAAY;IAC1B,YAAY,aAAwB;QAClC,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC;IACtC,CAAC;IAED,KAAK,CAAC,eAAe;QAGnB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,WAAW,CAClD,2BAA2B,CAC5B,CAAC;QACF,OAAO;YACL;gBACE,WAAW,EAAE,SAAS;aACvB;YACD,GAAG,MAAM,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE;gBACrC,OAAO;oBACL,WAAW,EAAE,EAAE;iBAChB,CAAC;YACJ,CAAC,CAAC;SACH,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,uBAAuB,CAAC,cAAqC;QACjE,MAAM,aAAa,GAAG,IAAI,GAAG,EAAuB,CAAC;QACrD,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,CAAC;YAC3B,OAAO,aAAa,CAAC;QACvB,CAAC;QAED,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,eAAe,EAAE,CAAC;QAClD,MAAM,mBAAmB,GAAG,IAAI,GAAG,CACjC,YAAY,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,WAAW,CAAC,WAAW,CAAC,CAC3D,CAAC;QACF,KAAK,MAAM,aAAa,IAAI,cAAc,EAAE,CAAC;YAC3C,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE,CAAC;gBAC5C,MAAM,IAAI,0BAA0B,CAClC,gBAAgB,aAAa,YAAY,CAC1C,CAAC;YACJ,CAAC;YACD,aAAa,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;QACnC,CAAC;QAED,OAAO,aAAa,CAAC;IACvB,CAAC;CACF"}
|
||||
Reference in New Issue
Block a user