Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

chromium-bidi

Package Overview
Dependencies
Maintainers
2
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chromium-bidi - npm Package Compare versions

Comparing version 0.5.6 to 0.5.7

lib/cjs/bidiMapper/domains/script/DedicatedWorkerRealm.d.ts

2

lib/cjs/bidiMapper/domains/context/BrowsingContextImpl.d.ts

@@ -20,3 +20,3 @@ /**

import { type LoggerFn } from '../../../utils/log.js';
import { Realm } from '../script/Realm.js';
import type { Realm } from '../script/Realm.js';
import type { RealmStorage } from '../script/RealmStorage.js';

@@ -23,0 +23,0 @@ import type { EventManager } from '../session/EventManager.js';

@@ -25,3 +25,3 @@ "use strict";

const unitConversions_js_1 = require("../../../utils/unitConversions.js");
const Realm_js_1 = require("../script/Realm.js");
const WindowRealm_js_1 = require("../script/WindowRealm.js");
class BrowsingContextImpl {

@@ -336,7 +336,3 @@ static LOGGER_PREFIX = `${log_js_1.LogType.debug}:browsingContext`;

}
const realm = new Realm_js_1.Realm(this.#realmStorage, this.#browsingContextStorage, uniqueId, this.id, id, origin,
// XXX: differentiate types.
'window',
// Sandbox name for isolated world.
sandbox, this.#cdpTarget.cdpClient, this.#eventManager, this.#sharedIdWithFrame, this.#logger);
const realm = new WindowRealm_js_1.WindowRealm(this.id, this.#browsingContextStorage, this.#cdpTarget.cdpClient, this.#eventManager, id, this.#logger, origin, uniqueId, this.#realmStorage, sandbox, this.#sharedIdWithFrame);
if (auxData.isDefault) {

@@ -343,0 +339,0 @@ this.#maybeDefaultRealm = realm;

@@ -6,3 +6,3 @@ "use strict";

const log_js_1 = require("../../../utils/log.js");
const Realm_js_1 = require("../script/Realm.js");
const DedicatedWorkerRealm_js_1 = require("../script/DedicatedWorkerRealm.js");
const BrowsingContextImpl_js_1 = require("./BrowsingContextImpl.js");

@@ -230,4 +230,3 @@ const CdpTarget_js_1 = require("./CdpTarget.js");

}
this.#setEventListeners(targetCdpClient);
const cdpTarget = CdpTarget_js_1.CdpTarget.create(targetInfo.targetId, targetCdpClient, this.#browserCdpClient, sessionId, this.#realmStorage, this.#eventManager, this.#preloadScriptStorage, this.#networkStorage, this.#acceptInsecureCerts);
const cdpTarget = this.#createCdpTarget(targetCdpClient, targetInfo, sessionId);
const maybeContext = this.#browsingContextStorage.findContext(targetInfo.targetId);

@@ -248,4 +247,2 @@ if (maybeContext) {

case 'worker': {
this.#setEventListeners(targetCdpClient);
const cdpTarget = CdpTarget_js_1.CdpTarget.create(targetInfo.targetId, targetCdpClient, this.#browserCdpClient, sessionId, this.#realmStorage, this.#eventManager, this.#preloadScriptStorage, this.#networkStorage, this.#acceptInsecureCerts);
const browsingContext = parentSessionCdpClient.sessionId &&

@@ -257,3 +254,8 @@ this.#browsingContextStorage.findContextBySession(parentSessionCdpClient.sessionId);

}
this.#handleWorkerTarget(cdpTarget, browsingContext.id);
const cdpTarget = this.#createCdpTarget(targetCdpClient, targetInfo, sessionId);
this.#handleWorkerTarget(cdpTarget, this.#realmStorage.getRealm({
browsingContextId: browsingContext.id,
type: 'window',
sandbox: undefined,
}));
return;

@@ -269,8 +271,12 @@ }

}
#createCdpTarget(targetCdpClient, targetInfo, sessionId) {
this.#setEventListeners(targetCdpClient);
return CdpTarget_js_1.CdpTarget.create(targetInfo.targetId, targetCdpClient, this.#browserCdpClient, sessionId, this.#realmStorage, this.#eventManager, this.#preloadScriptStorage, this.#networkStorage, this.#acceptInsecureCerts, this.#logger);
}
#workers = new Map();
#handleWorkerTarget(cdpTarget, browsingContextId) {
#handleWorkerTarget(cdpTarget, ownerRealm) {
cdpTarget.cdpClient.on('Runtime.executionContextCreated', (params) => {
const { uniqueId, id, origin } = params.context;
const realm = new Realm_js_1.Realm(this.#realmStorage, this.#browsingContextStorage, uniqueId, browsingContextId, id, (0, BrowsingContextImpl_js_1.serializeOrigin)(origin), 'dedicated-worker', undefined, cdpTarget.cdpClient, this.#eventManager, this.#sharedIdWithFrame, this.#logger);
this.#workers.set(cdpTarget.cdpSessionId, realm);
const workerRealm = new DedicatedWorkerRealm_js_1.DedicatedWorkerRealm(cdpTarget.cdpClient, this.#eventManager, id, this.#logger, (0, BrowsingContextImpl_js_1.serializeOrigin)(origin), ownerRealm, uniqueId, this.#realmStorage);
this.#workers.set(cdpTarget.cdpSessionId, workerRealm);
});

@@ -277,0 +283,0 @@ }

import type { Protocol } from 'devtools-protocol';
import type { CdpClient } from '../../../cdp/CdpClient.js';
import { Deferred } from '../../../utils/Deferred.js';
import type { LoggerFn } from '../../../utils/log.js';
import type { Result } from '../../../utils/result.js';

@@ -12,3 +13,3 @@ import type { NetworkStorage } from '../network/NetworkStorage.js';

#private;
static create(targetId: Protocol.Target.TargetID, cdpClient: CdpClient, browserCdpClient: CdpClient, cdpSessionId: Protocol.Target.SessionID, realmStorage: RealmStorage, eventManager: EventManager, preloadScriptStorage: PreloadScriptStorage, networkStorage: NetworkStorage, acceptInsecureCerts: boolean): CdpTarget;
static create(targetId: Protocol.Target.TargetID, cdpClient: CdpClient, browserCdpClient: CdpClient, cdpSessionId: Protocol.Target.SessionID, realmStorage: RealmStorage, eventManager: EventManager, preloadScriptStorage: PreloadScriptStorage, networkStorage: NetworkStorage, acceptInsecureCerts: boolean, logger?: LoggerFn): CdpTarget;
constructor(targetId: Protocol.Target.TargetID, cdpClient: CdpClient, browserCdpClient: CdpClient, cdpSessionId: Protocol.Target.SessionID, eventManager: EventManager, preloadScriptStorage: PreloadScriptStorage, networkStorage: NetworkStorage, acceptInsecureCerts: boolean);

@@ -15,0 +16,0 @@ /** Returns a promise that resolves when the target is unblocked. */

@@ -17,5 +17,5 @@ "use strict";

#acceptInsecureCerts;
static create(targetId, cdpClient, browserCdpClient, cdpSessionId, realmStorage, eventManager, preloadScriptStorage, networkStorage, acceptInsecureCerts) {
static create(targetId, cdpClient, browserCdpClient, cdpSessionId, realmStorage, eventManager, preloadScriptStorage, networkStorage, acceptInsecureCerts, logger) {
const cdpTarget = new CdpTarget(targetId, cdpClient, browserCdpClient, cdpSessionId, eventManager, preloadScriptStorage, networkStorage, acceptInsecureCerts);
LogManager_js_1.LogManager.create(cdpTarget, realmStorage, eventManager);
LogManager_js_1.LogManager.create(cdpTarget, realmStorage, eventManager, logger);
NetworkManager_js_1.NetworkManager.create(cdpTarget, eventManager, networkStorage);

@@ -22,0 +22,0 @@ cdpTarget.#setEventListeners();

@@ -104,3 +104,3 @@ "use strict";

})) {
const { objectId } = await realm.deserializeToCdpArg(params.element);
const { objectId } = await realm.deserializeForCdp(params.element);
// This cannot throw since this was just used in `callFunction` above.

@@ -107,0 +107,0 @@ (0, assert_js_1.assert)(objectId !== undefined);

@@ -54,9 +54,9 @@ /**

count: number;
"__#89096@#x": number;
"__#89096@#y": number;
"__#89096@#time": number;
"__#89098@#x": number;
"__#89098@#y": number;
"__#89098@#time": number;
compare(context: any): boolean;
};
"__#89096@#DOUBLE_CLICK_TIME_MS": number;
"__#89096@#MAX_DOUBLE_CLICK_RADIUS": number;
"__#89098@#DOUBLE_CLICK_TIME_MS": number;
"__#89098@#MAX_DOUBLE_CLICK_RADIUS": number;
};

@@ -63,0 +63,0 @@ setClickCount(button: number, context: InstanceType<typeof PointerSource.ClickContext>): number;

@@ -0,1 +1,2 @@

import { type LoggerFn } from '../../../utils/log.js';
import type { CdpTarget } from '../context/CdpTarget.js';

@@ -7,3 +8,3 @@ import type { RealmStorage } from '../script/RealmStorage.js';

private constructor();
static create(cdpTarget: CdpTarget, realmStorage: RealmStorage, eventManager: EventManager): LogManager;
static create(cdpTarget: CdpTarget, realmStorage: RealmStorage, eventManager: EventManager, logger?: LoggerFn): LogManager;
}

@@ -5,2 +5,3 @@ "use strict";

const protocol_js_1 = require("../../../protocol/protocol.js");
const log_js_1 = require("../../../utils/log.js");
const logHelper_js_1 = require("./logHelper.js");

@@ -35,9 +36,11 @@ /** Converts CDP StackTrace object to BiDi StackTrace object. */

#cdpTarget;
constructor(cdpTarget, realmStorage, eventManager) {
#logger;
constructor(cdpTarget, realmStorage, eventManager, logger) {
this.#cdpTarget = cdpTarget;
this.#realmStorage = realmStorage;
this.#eventManager = eventManager;
this.#logger = logger;
}
static create(cdpTarget, realmStorage, eventManager) {
const logManager = new LogManager(cdpTarget, realmStorage, eventManager);
static create(cdpTarget, realmStorage, eventManager, logger) {
const logManager = new LogManager(cdpTarget, realmStorage, eventManager, logger);
logManager.#initializeEntryAddedEventListener();

@@ -54,2 +57,7 @@ return logManager;

});
if (realm === undefined) {
// Ignore exceptions not attached to any realm.
this.#logger?.(log_js_1.LogType.cdp, params);
return;
}
const argsPromise = realm === undefined

@@ -61,23 +69,22 @@ ? Promise.resolve(params.args)

}));
this.#eventManager.registerPromiseEvent(argsPromise.then((args) => ({
kind: 'success',
value: {
type: 'event',
method: protocol_js_1.ChromiumBidi.Log.EventNames.LogEntryAdded,
params: {
level: getLogLevel(params.type),
source: {
realm: realm?.realmId ?? 'UNKNOWN',
context: realm?.browsingContextId ?? 'UNKNOWN',
for (const browsingContext of realm.associatedBrowsingContexts) {
this.#eventManager.registerPromiseEvent(argsPromise.then((args) => ({
kind: 'success',
value: {
type: 'event',
method: protocol_js_1.ChromiumBidi.Log.EventNames.LogEntryAdded,
params: {
level: getLogLevel(params.type),
source: realm.source,
text: (0, logHelper_js_1.getRemoteValuesText)(args, true),
timestamp: Math.round(params.timestamp),
stackTrace: getBidiStackTrace(params.stackTrace),
type: 'console',
// Console method is `warn`, not `warning`.
method: params.type === 'warning' ? 'warn' : params.type,
args,
},
text: (0, logHelper_js_1.getRemoteValuesText)(args, true),
timestamp: Math.round(params.timestamp),
stackTrace: getBidiStackTrace(params.stackTrace),
type: 'console',
// Console method is `warn`, not `warning`.
method: params.type === 'warning' ? 'warn' : params.type,
args,
},
},
})), realm?.browsingContextId ?? 'UNKNOWN', protocol_js_1.ChromiumBidi.Log.EventNames.LogEntryAdded);
})), browsingContext.id, protocol_js_1.ChromiumBidi.Log.EventNames.LogEntryAdded);
}
});

@@ -91,20 +98,24 @@ this.#cdpTarget.cdpClient.on('Runtime.exceptionThrown', (params) => {

});
this.#eventManager.registerPromiseEvent(LogManager.#getExceptionText(params, realm).then((text) => ({
kind: 'success',
value: {
type: 'event',
method: protocol_js_1.ChromiumBidi.Log.EventNames.LogEntryAdded,
params: {
level: "error" /* Log.Level.Error */,
source: {
realm: realm?.realmId ?? 'UNKNOWN',
context: realm?.browsingContextId ?? 'UNKNOWN',
if (realm === undefined) {
// Ignore exceptions not attached to any realm.
this.#logger?.(log_js_1.LogType.cdp, params);
return;
}
for (const browsingContext of realm.associatedBrowsingContexts) {
this.#eventManager.registerPromiseEvent(LogManager.#getExceptionText(params, realm).then((text) => ({
kind: 'success',
value: {
type: 'event',
method: protocol_js_1.ChromiumBidi.Log.EventNames.LogEntryAdded,
params: {
level: "error" /* Log.Level.Error */,
source: realm.source,
text,
timestamp: Math.round(params.timestamp),
stackTrace: getBidiStackTrace(params.exceptionDetails.stackTrace),
type: 'javascript',
},
text,
timestamp: Math.round(params.timestamp),
stackTrace: getBidiStackTrace(params.exceptionDetails.stackTrace),
type: 'javascript',
},
},
})), realm?.browsingContextId ?? 'UNKNOWN', protocol_js_1.ChromiumBidi.Log.EventNames.LogEntryAdded);
})), browsingContext.id, protocol_js_1.ChromiumBidi.Log.EventNames.LogEntryAdded);
}
});

@@ -111,0 +122,0 @@ }

@@ -17,5 +17,2 @@ "use strict";

async addIntercept(params) {
if (params.phases.length === 0) {
throw new protocol_js_1.InvalidArgumentException('At least one phase must be specified.');
}
// If AuthRequired is specified, BeforeRequestSent must also be specified.

@@ -22,0 +19,0 @@ // This is a CDP quirk.

@@ -144,14 +144,13 @@ "use strict";

}
eventManager.registerEvent({
type: 'event',
method: protocol_js_1.ChromiumBidi.Script.EventNames.Message,
params: {
channel: this.#properties.channel,
data: realm.cdpToBidiValue(message, this.#properties.ownership ?? "none" /* Script.ResultOwnership.None */),
source: {
realm: realm.realmId,
context: realm.browsingContextId,
for (const browsingContext of realm.associatedBrowsingContexts) {
eventManager.registerEvent({
type: 'event',
method: protocol_js_1.ChromiumBidi.Script.EventNames.Message,
params: {
channel: this.#properties.channel,
data: realm.cdpToBidiValue(message, this.#properties.ownership ?? "none" /* Script.ResultOwnership.None */),
source: realm.source,
},
},
}, realm.browsingContextId);
}, browsingContext.id);
}
}

@@ -158,0 +157,0 @@ catch (error) {

@@ -19,21 +19,34 @@ /**

import type { CdpClient } from '../../../cdp/CdpClient.js';
import { type BrowsingContext, Script } from '../../../protocol/protocol.js';
import { Script } from '../../../protocol/protocol.js';
import { type LoggerFn } from '../../../utils/log.js';
import type { BrowsingContextStorage } from '../context/BrowsingContextStorage.js';
import type { BrowsingContextImpl } from '../context/BrowsingContextImpl.js';
import type { EventManager } from '../session/EventManager.js';
import type { RealmStorage } from './RealmStorage.js';
export declare class Realm {
export declare abstract class Realm {
#private;
readonly sandbox?: string;
constructor(realmStorage: RealmStorage, browsingContextStorage: BrowsingContextStorage, realmId: Script.Realm, browsingContextId: BrowsingContext.BrowsingContext, executionContextId: Protocol.Runtime.ExecutionContextId, origin: string, type: Script.RealmType, sandbox: string | undefined, cdpClient: CdpClient, eventManager: EventManager, sharedIdWithFrame: boolean, logger?: LoggerFn);
constructor(cdpClient: CdpClient, eventManager: EventManager, executionContextId: Protocol.Runtime.ExecutionContextId, logger: LoggerFn | undefined, origin: string, realmId: Script.Realm, realmStorage: RealmStorage);
cdpToBidiValue(cdpValue: Protocol.Runtime.CallFunctionOnResponse | Protocol.Runtime.EvaluateResponse, resultOwnership: Script.ResultOwnership): Script.RemoteValue;
/**
* Relies on the CDP to implement proper BiDi serialization, except:
* * CDP integer property `backendNodeId` is replaced with `sharedId` of
* `{documentId}_element_{backendNodeId}`;
* * CDP integer property `weakLocalObjectReference` is replaced with UUID `internalId`
* using unique-per serialization `internalIdMap`.
* * CDP type `platformobject` is replaced with `object`.
* @param deepSerializedValue - CDP value to be converted to BiDi.
* @param internalIdMap - Map from CDP integer `weakLocalObjectReference` to BiDi UUID
* `internalId`.
*/
protected serializeForBiDi(deepSerializedValue: Protocol.Runtime.DeepSerializedValue, internalIdMap: Map<number, string>): Script.RemoteValue;
get realmId(): Script.Realm;
get navigableId(): string;
get browsingContextId(): BrowsingContext.BrowsingContext;
get executionContextId(): Protocol.Runtime.ExecutionContextId;
get origin(): string;
get type(): Script.RealmType;
get source(): Script.Source;
get cdpClient(): CdpClient;
get realmInfo(): Script.RealmInfo;
abstract get associatedBrowsingContexts(): BrowsingContextImpl[];
abstract get realmType(): Script.RealmType;
protected get baseInfo(): Script.BaseRealmInfo;
abstract get realmInfo(): Script.RealmInfo;
evaluate(expression: string, awaitPromise: boolean, resultOwnership: Script.ResultOwnership, serializationOptions: Script.SerializationOptions, userActivation?: boolean): Promise<Script.EvaluateResult>;
protected initialize(): void;
/**

@@ -50,5 +63,5 @@ * Serializes a given CDP object into BiDi, keeping references in the

callFunction(functionDeclaration: string, thisLocalValue: Script.LocalValue, argumentsLocalValues: Script.LocalValue[], awaitPromise: boolean, resultOwnership: Script.ResultOwnership, serializationOptions: Script.SerializationOptions, userActivation?: boolean): Promise<Script.EvaluateResult>;
deserializeToCdpArg(localValue: Script.LocalValue): Promise<Protocol.Runtime.CallArgument>;
deserializeForCdp(localValue: Script.LocalValue): Promise<Protocol.Runtime.CallArgument>;
disown(handle: Script.Handle): Promise<void>;
dispose(): void;
}

@@ -8,38 +8,22 @@ "use strict";

const ChannelProxy_js_1 = require("./ChannelProxy.js");
const SharedId_js_1 = require("./SharedId.js");
class Realm {
#realmStorage;
#browsingContextStorage;
#realmId;
#browsingContextId;
#executionContextId;
#origin;
#sharedIdWithFrame;
#type;
#cdpClient;
#eventManager;
sandbox;
#executionContextId;
#logger;
constructor(realmStorage, browsingContextStorage, realmId, browsingContextId, executionContextId, origin, type, sandbox, cdpClient, eventManager, sharedIdWithFrame, logger) {
this.#sharedIdWithFrame = sharedIdWithFrame;
this.#realmId = realmId;
this.#browsingContextId = browsingContextId;
#origin;
#realmId;
#realmStorage;
constructor(cdpClient, eventManager, executionContextId, logger, origin, realmId, realmStorage) {
this.#cdpClient = cdpClient;
this.#eventManager = eventManager;
this.#executionContextId = executionContextId;
this.sandbox = sandbox;
this.#logger = logger;
this.#origin = origin;
this.#type = type;
this.#cdpClient = cdpClient;
this.#realmId = realmId;
this.#realmStorage = realmStorage;
this.#browsingContextStorage = browsingContextStorage;
this.#eventManager = eventManager;
this.#logger = logger;
this.#realmStorage.addRealm(this);
this.#eventManager.registerEvent({
type: 'event',
method: protocol_js_1.ChromiumBidi.Script.EventNames.RealmCreated,
params: this.realmInfo,
}, this.browsingContextId);
}
cdpToBidiValue(cdpValue, resultOwnership) {
const bidiValue = this.#deepSerializedToBiDi(cdpValue.result.deepSerializedValue, new Map());
const bidiValue = this.serializeForBiDi(cdpValue.result.deepSerializedValue, new Map());
if (cdpValue.result.objectId) {

@@ -83,3 +67,3 @@ const objectId = cdpValue.result.objectId;

*/
#deepSerializedToBiDi(deepSerializedValue, internalIdMap) {
serializeForBiDi(deepSerializedValue, internalIdMap) {
if (Object.hasOwn(deepSerializedValue, 'weakLocalObjectReference')) {

@@ -102,34 +86,6 @@ const weakLocalObjectReference = deepSerializedValue.weakLocalObjectReference;

}
if (deepSerializedValue.type === 'node') {
if (Object.hasOwn(bidiValue, 'backendNodeId')) {
let navigableId = this.navigableId;
if (Object.hasOwn(bidiValue, 'loaderId')) {
// `loaderId` should be always there after ~2024-03-05, when
// https://crrev.com/c/5116240 reaches stable.
// TODO: remove the check after the date.
navigableId = bidiValue.loaderId;
delete bidiValue['loaderId'];
}
deepSerializedValue.sharedId =
(0, SharedId_js_1.getSharedId)(this.#getBrowsingContextId(navigableId), navigableId, bidiValue.backendNodeId, this.#sharedIdWithFrame);
delete bidiValue['backendNodeId'];
}
if (Object.hasOwn(bidiValue, 'children')) {
for (const i in bidiValue.children) {
bidiValue.children[i] = this.#deepSerializedToBiDi(bidiValue.children[i], internalIdMap);
}
}
if (Object.hasOwn(bidiValue, 'shadowRoot') &&
bidiValue.shadowRoot !== null) {
bidiValue.shadowRoot = this.#deepSerializedToBiDi(bidiValue.shadowRoot, internalIdMap);
}
// `namespaceURI` can be is either `null` or non-empty string.
if (bidiValue.namespaceURI === '') {
bidiValue.namespaceURI = null;
}
}
// Recursively update the nested values.
if (['array', 'set', 'htmlcollection', 'nodelist'].includes(deepSerializedValue.type)) {
for (const i in bidiValue) {
bidiValue[i] = this.#deepSerializedToBiDi(bidiValue[i], internalIdMap);
bidiValue[i] = this.serializeForBiDi(bidiValue[i], internalIdMap);
}

@@ -140,4 +96,4 @@ }

bidiValue[i] = [
this.#deepSerializedToBiDi(bidiValue[i][0], internalIdMap),
this.#deepSerializedToBiDi(bidiValue[i][1], internalIdMap),
this.serializeForBiDi(bidiValue[i][0], internalIdMap),
this.serializeForBiDi(bidiValue[i][1], internalIdMap),
];

@@ -148,20 +104,5 @@ }

}
#getBrowsingContextId(navigableId) {
const maybeBrowsingContext = this.#browsingContextStorage
.getAllContexts()
.find((context) => context.navigableId === navigableId);
return maybeBrowsingContext?.id ?? 'UNKNOWN';
}
get realmId() {
return this.#realmId;
}
get navigableId() {
return ((this.browsingContextId &&
this.#browsingContextStorage.findContext(this.browsingContextId)
?.navigableId) ??
'UNKNOWN');
}
get browsingContextId() {
return this.#browsingContextId;
}
get executionContextId() {

@@ -173,4 +114,6 @@ return this.#executionContextId;

}
get type() {
return this.#type;
get source() {
return {
realm: this.realmId,
};
}

@@ -180,27 +123,9 @@ get cdpClient() {

}
get realmInfo() {
switch (this.type) {
case 'window':
return {
realm: this.realmId,
origin: this.origin,
type: this.type,
context: this.browsingContextId,
...(this.sandbox === undefined ? {} : { sandbox: this.sandbox }),
};
default:
return {
// TODO: add proper owners.
// https://github.com/GoogleChromeLabs/chromium-bidi/issues/1667
owners: [],
realm: this.realmId,
origin: this.origin,
type: this.type,
};
}
get baseInfo() {
return {
realm: this.realmId,
origin: this.origin,
};
}
async evaluate(expression, awaitPromise, resultOwnership, serializationOptions, userActivation = false) {
await this.#browsingContextStorage
.getContext(this.browsingContextId)
.targetUnblockedOrThrow();
const cdpEvaluateResult = await this.cdpClient.sendCommand('Runtime.evaluate', {

@@ -222,2 +147,11 @@ contextId: this.executionContextId,

}
initialize() {
for (const browsingContext of this.associatedBrowsingContexts) {
this.#eventManager.registerEvent({
type: 'event',
method: protocol_js_1.ChromiumBidi.Script.EventNames.RealmCreated,
params: this.realmInfo,
}, browsingContext.id);
}
}
/**

@@ -273,5 +207,5 @@ * Serializes a given CDP object into BiDi, keeping references in the

// Key is a serialized value.
keyArg = await this.deserializeToCdpArg(key);
keyArg = await this.deserializeForCdp(key);
}
const valueArg = await this.deserializeToCdpArg(value);
const valueArg = await this.deserializeForCdp(value);
keyValueArray.push(keyArg);

@@ -283,3 +217,3 @@ keyValueArray.push(valueArg);

async #flattenValueList(listLocalValue) {
return await Promise.all(listLocalValue.map((localValue) => this.deserializeToCdpArg(localValue)));
return await Promise.all(listLocalValue.map((localValue) => this.deserializeForCdp(localValue)));
}

@@ -306,5 +240,2 @@ async #serializeCdpExceptionDetails(cdpExceptionDetails, lineOffset, resultOwnership) {

async callFunction(functionDeclaration, thisLocalValue, argumentsLocalValues, awaitPromise, resultOwnership, serializationOptions, userActivation = false) {
await this.#browsingContextStorage
.getContext(this.browsingContextId)
.targetUnblockedOrThrow();
const callFunctionAndSerializeScript = `(...args) => {

@@ -321,4 +252,4 @@ function callFunction(f, args) {

const thisAndArgumentsList = [
await this.deserializeToCdpArg(thisLocalValue),
...(await Promise.all(argumentsLocalValues.map(async (argumentLocalValue) => await this.deserializeToCdpArg(argumentLocalValue)))),
await this.deserializeForCdp(thisLocalValue),
...(await Promise.all(argumentsLocalValues.map(async (argumentLocalValue) => await this.deserializeForCdp(argumentLocalValue)))),
];

@@ -359,32 +290,4 @@ let cdpCallFunctionResult;

}
async deserializeToCdpArg(localValue) {
if ('sharedId' in localValue && localValue.sharedId) {
const parsedSharedId = (0, SharedId_js_1.parseSharedId)(localValue.sharedId);
if (parsedSharedId === null) {
throw new protocol_js_1.NoSuchNodeException(`SharedId "${localValue.sharedId}" was not found.`);
}
const { documentId, backendNodeId } = parsedSharedId;
// TODO: add proper validation if the element is accessible from the current realm.
if (this.navigableId !== documentId) {
throw new protocol_js_1.NoSuchNodeException(`SharedId "${localValue.sharedId}" belongs to different document. Current document is ${this.navigableId}.`);
}
try {
const { object } = await this.cdpClient.sendCommand('DOM.resolveNode', {
backendNodeId,
executionContextId: this.executionContextId,
});
// TODO(#375): Release `obj.object.objectId` after using.
return { objectId: object.objectId };
}
catch (error) {
// Heuristic to detect "no such node" exception. Based on the specific
// CDP implementation.
if (error.code === -32000 /* CdpErrorConstants.GENERIC_ERROR */ &&
error.message === 'No node with given id found') {
throw new protocol_js_1.NoSuchNodeException(`SharedId "${localValue.sharedId}" was not found.`);
}
throw new protocol_js_1.UnknownErrorException(error.message, error.stack);
}
}
else if ('handle' in localValue && localValue.handle) {
async deserializeForCdp(localValue) {
if ('handle' in localValue && localValue.handle) {
return { objectId: localValue.handle };

@@ -572,9 +475,11 @@ // We tried to find a handle value but failed

dispose() {
this.#eventManager.registerEvent({
type: 'event',
method: protocol_js_1.ChromiumBidi.Script.EventNames.RealmDestroyed,
params: {
realm: this.realmId,
},
}, this.browsingContextId);
for (const browsingContext of this.associatedBrowsingContexts) {
this.#eventManager.registerEvent({
type: 'event',
method: protocol_js_1.ChromiumBidi.Script.EventNames.RealmDestroyed,
params: {
realm: this.realmId,
},
}, browsingContext.id);
}
}

@@ -581,0 +486,0 @@ }

@@ -18,3 +18,3 @@ /**

import type { Protocol } from 'devtools-protocol';
import { type Script, type BrowsingContext } from '../../../protocol/protocol.js';
import { type BrowsingContext, type Script } from '../../../protocol/protocol.js';
import type { Realm } from './Realm.js';

@@ -24,3 +24,2 @@ type RealmFilter = {

browsingContextId?: BrowsingContext.BrowsingContext;
navigableId?: string;
executionContextId?: Protocol.Runtime.ExecutionContextId;

@@ -27,0 +26,0 @@ origin?: string;

@@ -5,2 +5,3 @@ "use strict";

const protocol_js_1 = require("../../../protocol/protocol.js");
const WindowRealm_js_1 = require("./WindowRealm.js");
/** Container class for browsing realms. */

@@ -25,7 +26,9 @@ class RealmStorage {

if (filter.browsingContextId !== undefined &&
filter.browsingContextId !== realm.browsingContextId) {
!realm.associatedBrowsingContexts
.map((browsingContext) => browsingContext.id)
.includes(filter.browsingContextId)) {
return false;
}
if (filter.navigableId !== undefined &&
filter.navigableId !== realm.navigableId) {
if (filter.sandbox !== undefined &&
(!(realm instanceof WindowRealm_js_1.WindowRealm) || filter.sandbox !== realm.sandbox)) {
return false;

@@ -40,8 +43,5 @@ }

}
if (filter.type !== undefined && filter.type !== realm.type) {
if (filter.type !== undefined && filter.type !== realm.realmType) {
return false;
}
if (filter.sandbox !== undefined && filter.sandbox !== realm.sandbox) {
return false;
}
if (filter.cdpSessionId !== undefined &&

@@ -48,0 +48,0 @@ filter.cdpSessionId !== realm.cdpClient.sessionId) {

@@ -23,3 +23,5 @@ "use strict";

const partitionKey = this.#expandStoragePartitionSpec(params.partition);
const cdpResponse = await this.#browserCdpClient.sendCommand('Storage.getCookies', {});
const cdpResponse = await this.#browserCdpClient.sendCommand('Storage.getCookies', {
browserContextId: partitionKey.userContext,
});
const filteredBiDiCookies = cdpResponse.cookies

@@ -45,2 +47,3 @@ .filter(

cookies: [cdpCookie],
browserContextId: partitionKey.userContext,
});

@@ -58,4 +61,3 @@ }

const browsingContextId = descriptor.context;
// Assert the browsing context exists.
this.#browsingContextStorage.getContext(browsingContextId);
const browsingContext = this.#browsingContextStorage.getContext(browsingContextId);
// https://w3c.github.io/webdriver-bidi/#associated-storage-partition.

@@ -65,4 +67,7 @@ // Each browsing context also has an associated storage partition, which is the

// which maps to BiDi `UserContext`.
// TODO: extend with UserContext.
return {};
return {
userContext: browsingContext.userContext === 'default'
? undefined
: browsingContext.userContext,
};
}

@@ -84,2 +89,3 @@ #expandStoragePartitionSpecByStorageKey(descriptor) {

}
const userContext = descriptor.userContext === 'default' ? undefined : descriptor.userContext;
// Partition spec is a storage partition.

@@ -90,3 +96,3 @@ // Let partition key be partition spec.

value !== undefined &&
!['type', 'sourceOrigin'].includes(key)) {
!['type', 'sourceOrigin', 'userContext'].includes(key)) {
unsupportedPartitionKeys.set(key, value);

@@ -100,2 +106,3 @@ }

...(sourceOrigin === undefined ? {} : { sourceOrigin }),
...(userContext === undefined ? {} : { userContext }),
};

@@ -102,0 +109,0 @@ }

{
"name": "chromium-bidi",
"version": "0.5.6",
"version": "0.5.7",
"description": "An implementation of the WebDriver BiDi protocol for Chromium implemented as a JavaScript layer translating between BiDi and CDP, running inside a Chrome tab.",

@@ -5,0 +5,0 @@ "scripts": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc