Socket
Socket
Sign inDemoInstall

chromium-bidi

Package Overview
Dependencies
Maintainers
2
Versions
69
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.20 to 0.5.21

2

lib/cjs/bidiMapper/modules/cdp/CdpTarget.d.ts

@@ -16,3 +16,3 @@ import type { Protocol } from 'devtools-protocol';

static create(targetId: Protocol.Target.TargetID, cdpClient: CdpClient, browserCdpClient: CdpClient, realmStorage: RealmStorage, eventManager: EventManager, preloadScriptStorage: PreloadScriptStorage, browsingContextStorage: BrowsingContextStorage, networkStorage: NetworkStorage, acceptInsecureCerts: boolean, logger?: LoggerFn): CdpTarget;
constructor(targetId: Protocol.Target.TargetID, cdpClient: CdpClient, browserCdpClient: CdpClient, eventManager: EventManager, preloadScriptStorage: PreloadScriptStorage, browsingContextStorage: BrowsingContextStorage, networkStorage: NetworkStorage, acceptInsecureCerts: boolean);
constructor(targetId: Protocol.Target.TargetID, cdpClient: CdpClient, browserCdpClient: CdpClient, eventManager: EventManager, realmStorage: RealmStorage, preloadScriptStorage: PreloadScriptStorage, browsingContextStorage: BrowsingContextStorage, networkStorage: NetworkStorage, acceptInsecureCerts: boolean, logger?: LoggerFn);
/** Returns a deferred that resolves when the target is unblocked. */

@@ -19,0 +19,0 @@ get unblocked(): Deferred<Result<void>>;

@@ -6,2 +6,4 @@ "use strict";

const Deferred_js_1 = require("../../../utils/Deferred.js");
const log_js_1 = require("../../../utils/log.js");
const BrowsingContextImpl_js_1 = require("../context/BrowsingContextImpl.js");
const LogManager_js_1 = require("../log/LogManager.js");

@@ -12,2 +14,3 @@ class CdpTarget {

#browserCdpClient;
#realmStorage;
#eventManager;

@@ -19,2 +22,3 @@ #preloadScriptStorage;

#acceptInsecureCerts;
#logger;
#networkDomainEnabled = false;

@@ -27,3 +31,3 @@ #fetchDomainStages = {

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

@@ -36,3 +40,3 @@ cdpTarget.#setEventListeners();

}
constructor(targetId, cdpClient, browserCdpClient, eventManager, preloadScriptStorage, browsingContextStorage, networkStorage, acceptInsecureCerts) {
constructor(targetId, cdpClient, browserCdpClient, eventManager, realmStorage, preloadScriptStorage, browsingContextStorage, networkStorage, acceptInsecureCerts, logger) {
this.#id = targetId;

@@ -42,2 +46,3 @@ this.#cdpClient = cdpClient;

this.#eventManager = eventManager;
this.#realmStorage = realmStorage;
this.#preloadScriptStorage = preloadScriptStorage;

@@ -47,2 +52,3 @@ this.#networkStorage = networkStorage;

this.#acceptInsecureCerts = acceptInsecureCerts;
this.#logger = logger;
}

@@ -73,4 +79,15 @@ /** Returns a deferred that resolves when the target is unblocked. */

await Promise.all([
this.#cdpClient.sendCommand('Page.enable'),
// There can be some existing frames in the target, if reconnecting to an
// existing browser instance, e.g. via Puppeteer. Need to restore the browsing
// contexts for the frames to correctly handle further events, like
// `Runtime.executionContextCreated`.
// It's important to schedule this task together with enabling domains commands to
// prepare the tree before the events (e.g. Runtime.executionContextCreated) start
// coming.
// https://github.com/GoogleChromeLabs/chromium-bidi/issues/2282
this.#cdpClient
.sendCommand('Page.getFrameTree')
.then((frameTree) => this.#restoreFrameTreeState(frameTree.frameTree)),
this.#cdpClient.sendCommand('Runtime.enable'),
this.#cdpClient.sendCommand('Page.enable'),
this.#cdpClient.sendCommand('Page.setLifecycleEventsEnabled', {

@@ -94,2 +111,3 @@ enabled: true,

catch (error) {
this.#logger?.(log_js_1.LogType.debugError, 'Failed to unblock target', error);
// The target might have been closed before the initialization finished.

@@ -109,2 +127,13 @@ if (!this.#cdpClient.isCloseError(error)) {

}
#restoreFrameTreeState(frameTree) {
const frame = frameTree.frame;
if (this.#browsingContextStorage.findContext(frame.id) === undefined &&
frame.parentId !== undefined) {
// Can restore only not yet known nested frames. The top-level frame is created
// when the target is attached.
const parentBrowsingContext = this.#browsingContextStorage.getContext(frame.parentId);
BrowsingContextImpl_js_1.BrowsingContextImpl.create(frame.id, frame.parentId, parentBrowsingContext.userContext, parentBrowsingContext.cdpTarget, this.#eventManager, this.#browsingContextStorage, this.#realmStorage, frame.url, this.#logger);
}
frameTree.childFrames?.map((frameTree) => this.#restoreFrameTreeState(frameTree));
}
async toggleFetchIfNeeded() {

@@ -111,0 +140,0 @@ const stages = this.#networkStorage.getInterceptionStages(this.topLevelId);

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

if (parentBrowsingContext !== undefined) {
BrowsingContextImpl_js_1.BrowsingContextImpl.create(params.frameId, params.parentFrameId, parentBrowsingContext.userContext, parentBrowsingContext.cdpTarget, this.#eventManager, this.#browsingContextStorage, this.#realmStorage, this.#logger);
BrowsingContextImpl_js_1.BrowsingContextImpl.create(params.frameId, params.parentFrameId, parentBrowsingContext.userContext, parentBrowsingContext.cdpTarget, this.#eventManager, this.#browsingContextStorage, this.#realmStorage,
// At this point, we don't know the URL of the frame yet, so it will be updated
// later.
'about:blank', this.#logger);
}

@@ -90,3 +93,12 @@ }

// New context.
BrowsingContextImpl_js_1.BrowsingContextImpl.create(targetInfo.targetId, null, userContext, cdpTarget, this.#eventManager, this.#browsingContextStorage, this.#realmStorage, this.#logger);
BrowsingContextImpl_js_1.BrowsingContextImpl.create(targetInfo.targetId, null, userContext, cdpTarget, this.#eventManager, this.#browsingContextStorage, this.#realmStorage,
// Hack: when a new target created, CDP emits targetInfoChanged with an empty
// url, and navigates it to about:blank later. When the event is emitted for
// an existing target (reconnect), the url is already known, and navigation
// events will not be emitted anymore. Replacing empty url with `about:blank`
// allows to handle both cases in the same way.
// "7.3.2.1 Creating browsing contexts".
// https://html.spec.whatwg.org/multipage/document-sequences.html#creating-browsing-contexts
// TODO: check who to deal with non-null creator and its `creatorOrigin`.
targetInfo.url === '' ? 'about:blank' : targetInfo.url, this.#logger);
}

@@ -93,0 +105,0 @@ return;

@@ -30,3 +30,3 @@ /**

private constructor();
static create(id: BrowsingContext.BrowsingContext, parentId: BrowsingContext.BrowsingContext | null, userContext: string, cdpTarget: CdpTarget, eventManager: EventManager, browsingContextStorage: BrowsingContextStorage, realmStorage: RealmStorage, logger?: LoggerFn): BrowsingContextImpl;
static create(id: BrowsingContext.BrowsingContext, parentId: BrowsingContext.BrowsingContext | null, userContext: string, cdpTarget: CdpTarget, eventManager: EventManager, browsingContextStorage: BrowsingContextStorage, realmStorage: RealmStorage, url: string, logger?: LoggerFn): BrowsingContextImpl;
static getTimestamp(): number;

@@ -33,0 +33,0 @@ /**

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

};
#url = 'about:blank';
#url;
#eventManager;

@@ -52,7 +52,8 @@ #realmStorage;

#cdpTarget;
#maybeDefaultRealm;
// The deferred will be resolved when the default realm is created.
#defaultRealmDeferred = new Deferred_js_1.Deferred();
#logger;
// Keeps track of the previously set viewport.
#previousViewport = { width: 0, height: 0 };
constructor(id, parentId, userContext, cdpTarget, eventManager, browsingContextStorage, realmStorage, logger) {
constructor(id, parentId, userContext, cdpTarget, eventManager, browsingContextStorage, realmStorage, url, logger) {
this.#cdpTarget = cdpTarget;

@@ -66,5 +67,6 @@ this.#id = id;

this.#logger = logger;
this.#url = url;
}
static create(id, parentId, userContext, cdpTarget, eventManager, browsingContextStorage, realmStorage, logger) {
const context = new BrowsingContextImpl(id, parentId, userContext, cdpTarget, eventManager, browsingContextStorage, realmStorage, logger);
static create(id, parentId, userContext, cdpTarget, eventManager, browsingContextStorage, realmStorage, url, logger) {
const context = new BrowsingContextImpl(id, parentId, userContext, cdpTarget, eventManager, browsingContextStorage, realmStorage, url, logger);
context.#initListeners();

@@ -160,6 +162,2 @@ browsingContextStorage.addContext(context);

}
get #defaultRealm() {
(0, assert_js_1.assert)(this.#maybeDefaultRealm, `No default realm for browsing context ${this.#id}`);
return this.#maybeDefaultRealm;
}
get cdpTarget() {

@@ -186,3 +184,4 @@ return this.#cdpTarget;

if (sandbox === undefined || sandbox === '') {
return this.#defaultRealm;
// Default realm is not guaranteed to be created at this point, so return a deferred.
return await this.#defaultRealmDeferred;
}

@@ -335,3 +334,9 @@ let maybeSandboxes = this.#realmStorage.findRealms({

// it has an empty one.
origin = this.#defaultRealm.origin;
if (!this.#defaultRealmDeferred.isFinished) {
this.#logger?.(log_js_1.LogType.debugError, 'Unexpectedly, isolated realm created before the default one');
}
origin = this.#defaultRealmDeferred.isFinished
? this.#defaultRealmDeferred.result.origin
: // This fallback is not expected to be ever reached.
'';
break;

@@ -346,3 +351,3 @@ case 'default':

if (auxData.isDefault) {
this.#maybeDefaultRealm = realm;
this.#defaultRealmDeferred.resolve(realm);
// Initialize ChannelProxy listeners for all the channels of all the

@@ -357,2 +362,7 @@ // preload scripts related to this BrowsingContext.

this.#cdpTarget.cdpClient.on('Runtime.executionContextDestroyed', (params) => {
if (this.#defaultRealmDeferred.isFinished &&
this.#defaultRealmDeferred.result.executionContextId ===
params.executionContextId) {
this.#defaultRealmDeferred = new Deferred_js_1.Deferred();
}
this.#realmStorage.deleteRealms({

@@ -364,2 +374,6 @@ cdpSessionId: this.#cdpTarget.cdpSessionId,

this.#cdpTarget.cdpClient.on('Runtime.executionContextsCleared', () => {
if (!this.#defaultRealmDeferred.isFinished) {
this.#defaultRealmDeferred.reject(new protocol_js_1.UnknownErrorException('execution contexts cleared'));
}
this.#defaultRealmDeferred = new Deferred_js_1.Deferred();
this.#realmStorage.deleteRealms({

@@ -764,3 +778,3 @@ cdpSessionId: this.#cdpTarget.cdpSessionId,

// TODO: create a dedicated sandbox instead of `#defaultRealm`.
return await this.#locateNodesByLocator(this.#defaultRealm, params.locator, params.startNodes ?? [], params.maxNodeCount, params.serializationOptions);
return await this.#locateNodesByLocator(await this.#defaultRealmDeferred, params.locator, params.startNodes ?? [], params.maxNodeCount, params.serializationOptions);
}

@@ -934,3 +948,3 @@ async #getLocatorDelegate(realm, locator, maxNodeCount, startNodes) {

// preserved. We probably do not need to disable them if the
// client is using a11y features but we could by calling
// client is using a11y features, but we could by calling
// Accessibility.disable.

@@ -937,0 +951,0 @@ await Promise.all([

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

browserContextId: userContext === 'default' ? undefined : userContext,
background: params.background === true,
});

@@ -61,0 +62,0 @@ }

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

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

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

@@ -19,2 +19,3 @@ import { Network, type EmptyResult } from '../../../protocol/protocol.js';

static validateHeaders(headers: Network.Header[]): void;
static isMethodValid(method: string): boolean;
/**

@@ -21,0 +22,0 @@ * Attempts to parse the given url.

@@ -35,2 +35,7 @@ "use strict";

}
if (params.method !== undefined) {
if (!NetworkProcessor.isMethodValid(params.method)) {
throw new protocol_js_1.InvalidArgumentException(`Method '${method}' is invalid.`);
}
}
if (params.headers) {

@@ -223,2 +228,6 @@ NetworkProcessor.validateHeaders(params.headers);

}
static isMethodValid(method) {
// https://httpwg.org/specs/rfc9110.html#method.overview
return /^[!#$%&'*+\-.^_`|~a-zA-Z\d]+$/.test(method);
}
/**

@@ -225,0 +234,0 @@ * Attempts to parse the given url.

@@ -168,5 +168,8 @@ "use strict";

httpOnly: params.cookie.httpOnly ?? false,
// CDP's `partitionKey` is the BiDi's `partition.sourceOrigin`.
...(partitionKey.sourceOrigin !== undefined && {
partitionKey: partitionKey.sourceOrigin,
partitionKey: {
hasCrossSiteAncestor: false,
// CDP's `partitionKey.topLevelSite` is the BiDi's `partition.sourceOrigin`.
topLevelSite: partitionKey.sourceOrigin,
},
}),

@@ -173,0 +176,0 @@ ...(params.cookie.expiry !== undefined && {

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

(c) => partitionKey.sourceOrigin === undefined ||
c.partitionKey === partitionKey.sourceOrigin)
c.partitionKey?.topLevelSite === partitionKey.sourceOrigin)
.filter((cdpCookie) => {

@@ -82,3 +82,3 @@ const bidiCookie = (0, NetworkUtils_js_1.cdpToBiDiCookie)(cdpCookie);

(c) => partitionKey.sourceOrigin === undefined ||
c.partitionKey === partitionKey.sourceOrigin)
c.partitionKey?.topLevelSite === partitionKey.sourceOrigin)
.map((c) => (0, NetworkUtils_js_1.cdpToBiDiCookie)(c))

@@ -85,0 +85,0 @@ .filter((c) => this.#matchCookie(c, params.filter));

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

get isFinished(): boolean;
get result(): T;
constructor();

@@ -22,0 +23,0 @@ then<TResult1 = T, TResult2 = never>(onFulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null, onRejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;

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

#promise;
#result;
#resolve;

@@ -29,2 +30,8 @@ #reject;

}
get result() {
if (!this.#isFinished) {
throw new Error('Deferred is not finished yet');
}
return this.#result;
}
constructor() {

@@ -48,2 +55,3 @@ this.#promise = new Promise((resolve, reject) => {

resolve(value) {
this.#result = value;
if (!this.#isFinished) {

@@ -50,0 +58,0 @@ this.#isFinished = true;

{
"name": "chromium-bidi",
"version": "0.5.20",
"version": "0.5.21",
"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.",

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

"@puppeteer/browsers": "2.2.3",
"@rollup/plugin-commonjs": "25.0.7",
"@rollup/plugin-commonjs": "25.0.8",
"@rollup/plugin-node-resolve": "15.2.3",
"@rollup/wasm-node": "4.17.2",
"@rollup/wasm-node": "4.18.0",
"@types/chai": "4.3.11",

@@ -159,3 +159,3 @@ "@types/chai-as-promised": "7.1.8",

"@types/mocha": "10.0.6",
"@types/node": "20.12.8",
"@types/node": "20.14.0",
"@types/sinon": "17.0.3",

@@ -165,8 +165,8 @@ "@types/websocket": "1.0.10",

"@types/yargs": "17.0.32",
"@typescript-eslint/eslint-plugin": "7.8.0",
"@typescript-eslint/parser": "7.8.0",
"@typescript-eslint/eslint-plugin": "7.11.0",
"@typescript-eslint/parser": "7.11.0",
"chai": "4.4.1",
"chai-as-promised": "7.1.1",
"debug": "4.3.4",
"devtools-protocol": "0.0.1306150",
"chai-as-promised": "7.1.2",
"debug": "4.3.5",
"devtools-protocol": "0.0.1311068",
"eslint": "8.57.0",

@@ -178,3 +178,3 @@ "eslint-config-prettier": "9.1.0",

"eslint-plugin-prettier": "5.1.3",
"eslint-plugin-promise": "6.1.1",
"eslint-plugin-promise": "6.2.0",
"gts": "5.3.0",

@@ -184,13 +184,13 @@ "mocha": "10.4.0",

"pkg-dir": "8.0.0",
"prettier": "3.2.5",
"rimraf": "5.0.5",
"rollup": "4.17.2",
"rollup-plugin-license": "3.3.1",
"selenium-webdriver": "4.20.0",
"sinon": "17.0.1",
"prettier": "3.3.0",
"rimraf": "5.0.7",
"rollup": "4.18.0",
"rollup-plugin-license": "3.4.0",
"selenium-webdriver": "4.21.0",
"sinon": "18.0.0",
"source-map-support": "0.5.21",
"tslib": "2.6.2",
"typescript": "5.4.5",
"webdriverio": "8.36.1",
"websocket": "1.0.34",
"webdriverio": "8.38.0",
"websocket": "1.0.35",
"wireit": "0.14.4",

@@ -203,4 +203,4 @@ "ws": "8.17.0",

"urlpattern-polyfill": "10.0.0",
"zod": "3.23.5"
"zod": "3.23.8"
}
}

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 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