chromium-bidi
Version:
An implementation of the WebDriver BiDi protocol for Chromium implemented as a JavaScript layer translating between BiDi and CDP, running inside a Chrome tab.
130 lines • 5.51 kB
JavaScript
/**
* 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 { ChromiumBidi, InvalidArgumentException, } from '../../../protocol/protocol.js';
import { PreloadScript } from './PreloadScript.js';
export class ScriptProcessor {
constructor(eventManager, browsingContextStorage, realmStorage, preloadScriptStorage, userContextStorage, logger) {
this.
this.
this.
this.
this.
this.
this.
}
const context = this.
const contextsToReport = [
context,
...this.
];
const realms = new Set();
for (const reportContext of contextsToReport) {
const realmsForContext = this.
browsingContextId: reportContext.id,
});
for (const realm of realmsForContext) {
realms.add(realm);
}
}
for (const realm of realms) {
this.
type: 'event',
method: ChromiumBidi.Script.EventNames.RealmCreated,
params: realm.realmInfo,
}, context.id);
}
return Promise.resolve();
}
async addPreloadScript(params) {
if (params.userContexts?.length && params.contexts?.length) {
throw new InvalidArgumentException('Both userContexts and contexts cannot be specified.');
}
const userContexts = await this.
const browsingContexts = this.
const preloadScript = new PreloadScript(params, this.
this.
let contextsToRunIn = [];
if (userContexts.size) {
contextsToRunIn = this.
.getTopLevelContexts()
.filter((context) => {
return userContexts.has(context.userContext);
});
}
else if (browsingContexts.size) {
contextsToRunIn = [...browsingContexts.values()];
}
else {
contextsToRunIn = this.
}
const cdpTargets = new Set(contextsToRunIn.map((context) => context.cdpTarget));
await preloadScript.initInTargets(cdpTargets, false);
return {
script: preloadScript.id,
};
}
async removePreloadScript(params) {
const { script: id } = params;
const script = this.
await script.remove();
this.
return {};
}
async callFunction(params) {
const realm = await this.
return await realm.callFunction(params.functionDeclaration, params.awaitPromise, params.this, params.arguments, params.resultOwnership, params.serializationOptions, params.userActivation);
}
async evaluate(params) {
const realm = await this.
return await realm.evaluate(params.expression, params.awaitPromise, params.resultOwnership, params.serializationOptions, params.userActivation);
}
async disown(params) {
const realm = await this.
await Promise.all(params.handles.map(async (handle) => await realm.disown(handle)));
return {};
}
getRealms(params) {
if (params.context !== undefined) {
// Make sure the context is known.
this.
}
const realms = this.
.findRealms({
browsingContextId: params.context,
type: params.type,
})
.map((realm) => realm.realmInfo);
return { realms };
}
async
if ('context' in target) {
const context = this.
return await context.getOrCreateSandbox(target.sandbox);
}
return this.
realmId: target.realm,
});
}
}
//# sourceMappingURL=ScriptProcessor.js.map