first commit
This commit is contained in:
27
node_modules/chromium-bidi/lib/cjs/bidiServer/BrowserInstance.d.ts
generated
vendored
Normal file
27
node_modules/chromium-bidi/lib/cjs/bidiServer/BrowserInstance.d.ts
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
import { type ChromeReleaseChannel, type Process } from '@puppeteer/browsers';
|
||||
import type { MapperOptions } from '../bidiMapper/BidiServer.js';
|
||||
import { MapperServerCdpConnection } from './MapperCdpConnection.js';
|
||||
import type { SimpleTransport } from './SimpleTransport.js';
|
||||
type ChromeOptions = {
|
||||
chromeArgs: string[];
|
||||
chromeBinary?: string;
|
||||
channel: ChromeReleaseChannel;
|
||||
headless: boolean;
|
||||
};
|
||||
/**
|
||||
* BrowserProcess is responsible for running the browser and BiDi Mapper within
|
||||
* it.
|
||||
* 1. Launch Chromium (using Puppeteer for now).
|
||||
* 2. Get `BiDi-CDP` mapper JS binaries using `MapperReader`.
|
||||
* 3. Run `BiDi-CDP` mapper in launched browser using `MapperRunner`.
|
||||
* 4. Bind `BiDi-CDP` mapper to the `BiDi server` to forward messages from BiDi
|
||||
* Mapper to the client.
|
||||
*/
|
||||
export declare class BrowserInstance {
|
||||
#private;
|
||||
static run(chromeOptions: ChromeOptions, mapperOptions: MapperOptions, verbose: boolean): Promise<BrowserInstance>;
|
||||
constructor(mapperCdpConnection: MapperServerCdpConnection, browserProcess: Process);
|
||||
close(): Promise<void>;
|
||||
bidiSession(): SimpleTransport;
|
||||
}
|
||||
export {};
|
||||
126
node_modules/chromium-bidi/lib/cjs/bidiServer/BrowserInstance.js
generated
vendored
Normal file
126
node_modules/chromium-bidi/lib/cjs/bidiServer/BrowserInstance.js
generated
vendored
Normal file
@@ -0,0 +1,126 @@
|
||||
"use strict";
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.BrowserInstance = void 0;
|
||||
const promises_1 = require("fs/promises");
|
||||
const os_1 = __importDefault(require("os"));
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const browsers_1 = require("@puppeteer/browsers");
|
||||
const debug_1 = __importDefault(require("debug"));
|
||||
const ws_1 = __importDefault(require("ws"));
|
||||
const CdpConnection_js_1 = require("../cdp/CdpConnection.js");
|
||||
const WebsocketTransport_js_1 = require("../utils/WebsocketTransport.js");
|
||||
const MapperCdpConnection_js_1 = require("./MapperCdpConnection.js");
|
||||
const reader_js_1 = require("./reader.js");
|
||||
const debugInternal = (0, debug_1.default)('bidi:mapper:internal');
|
||||
/**
|
||||
* BrowserProcess is responsible for running the browser and BiDi Mapper within
|
||||
* it.
|
||||
* 1. Launch Chromium (using Puppeteer for now).
|
||||
* 2. Get `BiDi-CDP` mapper JS binaries using `MapperReader`.
|
||||
* 3. Run `BiDi-CDP` mapper in launched browser using `MapperRunner`.
|
||||
* 4. Bind `BiDi-CDP` mapper to the `BiDi server` to forward messages from BiDi
|
||||
* Mapper to the client.
|
||||
*/
|
||||
class BrowserInstance {
|
||||
#mapperCdpConnection;
|
||||
#browserProcess;
|
||||
static async run(chromeOptions, mapperOptions, verbose) {
|
||||
const profileDir = await (0, promises_1.mkdtemp)(path_1.default.join(os_1.default.tmpdir(), 'web-driver-bidi-server-'));
|
||||
// See https://github.com/GoogleChrome/chrome-launcher/blob/main/docs/chrome-flags-for-tools.md
|
||||
const chromeArguments = [
|
||||
...(chromeOptions.headless
|
||||
? ['--headless', '--hide-scrollbars', '--mute-audio']
|
||||
: []),
|
||||
// keep-sorted start
|
||||
'--allow-browser-signin=false',
|
||||
'--disable-component-update',
|
||||
'--disable-default-apps',
|
||||
'--disable-features=DialMediaRouteProvider,TrackingProtection3pcd',
|
||||
'--disable-infobars',
|
||||
'--disable-notifications',
|
||||
'--disable-popup-blocking',
|
||||
'--disable-search-engine-choice-screen',
|
||||
'--enable-automation',
|
||||
'--no-default-browser-check',
|
||||
'--no-first-run',
|
||||
'--password-store=basic',
|
||||
'--remote-debugging-port=9222',
|
||||
'--use-mock-keychain',
|
||||
`--user-data-dir=${profileDir}`,
|
||||
// keep-sorted end
|
||||
...chromeOptions.chromeArgs.filter((arg) => !arg.startsWith('--headless')),
|
||||
'about:blank',
|
||||
];
|
||||
const executablePath = chromeOptions.chromeBinary ??
|
||||
process.env['BROWSER_BIN'] ??
|
||||
(0, browsers_1.computeSystemExecutablePath)({
|
||||
browser: browsers_1.Browser.CHROME,
|
||||
channel: chromeOptions.channel,
|
||||
});
|
||||
if (!executablePath) {
|
||||
throw new Error('Could not find Chrome binary');
|
||||
}
|
||||
const browserProcess = (0, browsers_1.launch)({
|
||||
executablePath,
|
||||
args: chromeArguments,
|
||||
env: process.env,
|
||||
});
|
||||
const cdpEndpoint = await browserProcess.waitForLineOutput(browsers_1.CDP_WEBSOCKET_ENDPOINT_REGEX);
|
||||
// There is a conflict between prettier and eslint here.
|
||||
// prettier-ignore
|
||||
const cdpConnection = await this.#establishCdpConnection(cdpEndpoint);
|
||||
// 2. Get `BiDi-CDP` mapper JS binaries.
|
||||
const mapperTabSource = await (0, reader_js_1.getMapperTabSource)();
|
||||
// 3. Run `BiDi-CDP` mapper in launched browser using `MapperRunner`.
|
||||
const mapperCdpConnection = await MapperCdpConnection_js_1.MapperServerCdpConnection.create(cdpConnection, mapperTabSource, verbose, mapperOptions);
|
||||
return new BrowserInstance(mapperCdpConnection, browserProcess);
|
||||
}
|
||||
constructor(mapperCdpConnection, browserProcess) {
|
||||
this.#mapperCdpConnection = mapperCdpConnection;
|
||||
this.#browserProcess = browserProcess;
|
||||
}
|
||||
async close() {
|
||||
// Close the mapper tab.
|
||||
this.#mapperCdpConnection.close();
|
||||
// Close browser.
|
||||
await this.#browserProcess.close();
|
||||
}
|
||||
bidiSession() {
|
||||
return this.#mapperCdpConnection.bidiSession();
|
||||
}
|
||||
static #establishCdpConnection(cdpUrl) {
|
||||
return new Promise((resolve, reject) => {
|
||||
debugInternal('Establishing session with cdpUrl: ', cdpUrl);
|
||||
const ws = new ws_1.default(cdpUrl);
|
||||
ws.once('error', reject);
|
||||
ws.on('open', () => {
|
||||
debugInternal('Session established.');
|
||||
const transport = new WebsocketTransport_js_1.WebSocketTransport(ws);
|
||||
const connection = new CdpConnection_js_1.MapperCdpConnection(transport);
|
||||
resolve(connection);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.BrowserInstance = BrowserInstance;
|
||||
//# sourceMappingURL=BrowserInstance.js.map
|
||||
1
node_modules/chromium-bidi/lib/cjs/bidiServer/BrowserInstance.js.map
generated
vendored
Normal file
1
node_modules/chromium-bidi/lib/cjs/bidiServer/BrowserInstance.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"BrowserInstance.js","sourceRoot":"","sources":["../../../src/bidiServer/BrowserInstance.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG;;;;;;AAEH,0CAAoC;AACpC,4CAAoB;AACpB,gDAAwB;AAExB,kDAO6B;AAC7B,kDAA0B;AAC1B,4CAA2B;AAG3B,8DAA4D;AAC5D,0EAAkE;AAElE,qEAAmE;AACnE,2CAA+C;AAG/C,MAAM,aAAa,GAAG,IAAA,eAAK,EAAC,sBAAsB,CAAC,CAAC;AASpD;;;;;;;;GAQG;AACH,MAAa,eAAe;IAC1B,oBAAoB,CAA4B;IAChD,e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AAS,GAAG,IAAI,0CAAkB,CAAC,EAAE,CAAC,CAAC;gBAC7C,MAAM,UAAU,GAAG,IAAI,sCAAmB,CAAC,SAAS,CAAC,CAAC;gBACtD,OAAO,CAAC,UAAU,CAAC,CAAC;YACtB,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAvHD,0CAuHC"}
|
||||
26
node_modules/chromium-bidi/lib/cjs/bidiServer/MapperCdpConnection.d.ts
generated
vendored
Normal file
26
node_modules/chromium-bidi/lib/cjs/bidiServer/MapperCdpConnection.d.ts
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Copyright 2021 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 { MapperOptions } from '../bidiMapper/BidiServer.js';
|
||||
import type { MapperCdpConnection } from '../cdp/CdpConnection.js';
|
||||
import { SimpleTransport } from './SimpleTransport.js';
|
||||
export declare class MapperServerCdpConnection {
|
||||
#private;
|
||||
static create(cdpConnection: MapperCdpConnection, mapperTabSource: string, verbose: boolean, mapperOptions: MapperOptions): Promise<MapperServerCdpConnection>;
|
||||
private constructor();
|
||||
close(): void;
|
||||
bidiSession(): SimpleTransport;
|
||||
}
|
||||
141
node_modules/chromium-bidi/lib/cjs/bidiServer/MapperCdpConnection.js
generated
vendored
Normal file
141
node_modules/chromium-bidi/lib/cjs/bidiServer/MapperCdpConnection.js
generated
vendored
Normal file
@@ -0,0 +1,141 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Copyright 2021 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.
|
||||
*/
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.MapperServerCdpConnection = void 0;
|
||||
const debug_1 = __importDefault(require("debug"));
|
||||
const SimpleTransport_js_1 = require("./SimpleTransport.js");
|
||||
const debugInternal = (0, debug_1.default)('bidi:mapper:internal');
|
||||
const debugInfo = (0, debug_1.default)('bidi:mapper:info');
|
||||
const debugOthers = (0, debug_1.default)('bidi:mapper:debug:others');
|
||||
// Memorizes a debug creation
|
||||
const loggers = new Map();
|
||||
const getLogger = (type) => {
|
||||
const prefix = `bidi:mapper:${type}`;
|
||||
let logger = loggers.get(prefix);
|
||||
if (!logger) {
|
||||
logger = (0, debug_1.default)(prefix);
|
||||
loggers.set(prefix, logger);
|
||||
}
|
||||
return logger;
|
||||
};
|
||||
class MapperServerCdpConnection {
|
||||
#cdpConnection;
|
||||
#bidiSession;
|
||||
static async create(cdpConnection, mapperTabSource, verbose, mapperOptions) {
|
||||
try {
|
||||
const bidiSession = await this.#initMapper(cdpConnection, mapperTabSource, verbose, mapperOptions);
|
||||
return new MapperServerCdpConnection(cdpConnection, bidiSession);
|
||||
}
|
||||
catch (e) {
|
||||
cdpConnection.close();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
constructor(cdpConnection, bidiSession) {
|
||||
this.#cdpConnection = cdpConnection;
|
||||
this.#bidiSession = bidiSession;
|
||||
}
|
||||
static async #sendMessage(mapperCdpClient, message) {
|
||||
try {
|
||||
await mapperCdpClient.sendCommand('Runtime.evaluate', {
|
||||
expression: `onBidiMessage(${JSON.stringify(message)})`,
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
debugInternal('Call to onBidiMessage failed', error);
|
||||
}
|
||||
}
|
||||
close() {
|
||||
this.#cdpConnection.close();
|
||||
}
|
||||
bidiSession() {
|
||||
return this.#bidiSession;
|
||||
}
|
||||
static #onBindingCalled = (params, bidiSession) => {
|
||||
if (params.name === 'sendBidiResponse') {
|
||||
bidiSession.emit('message', params.payload);
|
||||
}
|
||||
else if (params.name === 'sendDebugMessage') {
|
||||
this.#onDebugMessage(params.payload);
|
||||
}
|
||||
};
|
||||
static #onDebugMessage = (json) => {
|
||||
try {
|
||||
const log = JSON.parse(json);
|
||||
if (log.logType !== undefined && log.messages !== undefined) {
|
||||
const logger = getLogger(log.logType);
|
||||
logger(log.messages);
|
||||
}
|
||||
}
|
||||
catch {
|
||||
// Fall back to raw log in case of unknown
|
||||
debugOthers(json);
|
||||
}
|
||||
};
|
||||
static #onConsoleAPICalled = (params) => {
|
||||
debugInfo('consoleAPICalled: %s %O', params.type, params.args.map((arg) => arg.value));
|
||||
};
|
||||
static #onRuntimeExceptionThrown = (params) => {
|
||||
debugInfo('exceptionThrown:', params);
|
||||
};
|
||||
static async #initMapper(cdpConnection, mapperTabSource, verbose, mapperOptions) {
|
||||
debugInternal('Initializing Mapper.', mapperOptions);
|
||||
const browserClient = await cdpConnection.createBrowserSession();
|
||||
const { targetId: mapperTabTargetId } = await browserClient.sendCommand('Target.createTarget', {
|
||||
url: 'about:blank',
|
||||
});
|
||||
const { sessionId: mapperSessionId } = await browserClient.sendCommand('Target.attachToTarget', { targetId: mapperTabTargetId, flatten: true });
|
||||
const mapperCdpClient = cdpConnection.getCdpClient(mapperSessionId);
|
||||
const bidiSession = new SimpleTransport_js_1.SimpleTransport(async (message) => await this.#sendMessage(mapperCdpClient, message));
|
||||
// Process responses from the mapper tab.
|
||||
mapperCdpClient.on('Runtime.bindingCalled', (params) => this.#onBindingCalled(params, bidiSession));
|
||||
// Forward console messages from the mapper tab.
|
||||
mapperCdpClient.on('Runtime.consoleAPICalled', this.#onConsoleAPICalled);
|
||||
// Catch unhandled exceptions in the mapper.
|
||||
mapperCdpClient.on('Runtime.exceptionThrown', this.#onRuntimeExceptionThrown);
|
||||
await mapperCdpClient.sendCommand('Runtime.enable');
|
||||
await browserClient.sendCommand('Target.exposeDevToolsProtocol', {
|
||||
bindingName: 'cdp',
|
||||
targetId: mapperTabTargetId,
|
||||
});
|
||||
await mapperCdpClient.sendCommand('Runtime.addBinding', {
|
||||
name: 'sendBidiResponse',
|
||||
});
|
||||
if (verbose) {
|
||||
// Needed to request verbose logs from Mapper.
|
||||
await mapperCdpClient.sendCommand('Runtime.addBinding', {
|
||||
name: 'sendDebugMessage',
|
||||
});
|
||||
}
|
||||
// Evaluate Mapper Tab sources in the tab.
|
||||
await mapperCdpClient.sendCommand('Runtime.evaluate', {
|
||||
expression: mapperTabSource,
|
||||
});
|
||||
await mapperCdpClient.sendCommand('Runtime.evaluate', {
|
||||
expression: `window.runMapperInstance('${mapperTabTargetId}', ${JSON.stringify(mapperOptions)})`,
|
||||
awaitPromise: true,
|
||||
});
|
||||
debugInternal('Mapper is launched!');
|
||||
return bidiSession;
|
||||
}
|
||||
}
|
||||
exports.MapperServerCdpConnection = MapperServerCdpConnection;
|
||||
//# sourceMappingURL=MapperCdpConnection.js.map
|
||||
1
node_modules/chromium-bidi/lib/cjs/bidiServer/MapperCdpConnection.js.map
generated
vendored
Normal file
1
node_modules/chromium-bidi/lib/cjs/bidiServer/MapperCdpConnection.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"MapperCdpConnection.js","sourceRoot":"","sources":["../../../src/bidiServer/MapperCdp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AC,uBAAuB,EAAE,CAAC,MAAM,EAAE,EAAE,CACrD,IAAI,CAAC,gBAAgB,CAAC,MAAM,EAAE,WAAW,CAAC,CAC3C,CAAC;QACF,gDAAgD;QAChD,eAAe,CAAC,EAAE,CAAC,0BAA0B,EAAE,IAAI,CAAC,mBAAmB,CAAC,CAAC;QACzE,4CAA4C;QAC5C,eAAe,CAAC,EAAE,CAChB,yBAAyB,EACzB,IAAI,CAAC,yBAAyB,CAC/B,CAAC;QAEF,MAAM,eAAe,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAC;QAEpD,MAAM,aAAa,CAAC,WAAW,CAAC,+BAA+B,EAAE;YAC/D,WAAW,EAAE,KAAK;YAClB,QAAQ,EAAE,iBAAiB;SAC5B,CAAC,CAAC;QAEH,MAAM,eAAe,CAAC,WAAW,CAAC,oBAAoB,EAAE;YACtD,IAAI,EAAE,kBAAkB;SACzB,CAAC,CAAC;QAEH,IAAI,OAAO,EAAE,CAAC;YACZ,8CAA8C;YAC9C,MAAM,eAAe,CAAC,WAAW,CAAC,oBAAoB,EAAE;gBACtD,IAAI,EAAE,kBAAkB;aACzB,CAAC,CAAC;QACL,CAAC;QAED,0CAA0C;QAC1C,MAAM,eAAe,CAAC,WAAW,CAAC,kBAAkB,EAAE;YACpD,UAAU,EAAE,eAAe;SAC5B,CAAC,CAAC;QAEH,MAAM,eAAe,CAAC,WAAW,CAAC,kBAAkB,EAAE;YACpD,UAAU,EAAE,6BAA6B,iBAAiB,MAAM,IAAI,CAAC,SAAS,CAC5E,aAAa,CACd,GAAG;YACJ,YAAY,EAAE,IAAI;SACnB,CAAC,CAAC;QAEH,aAAa,CAAC,qBAAqB,CAAC,CAAC;QACrC,OAAO,WAAW,CAAC;IACrB,CAAC;;AAxKH,8DAyKC"}
|
||||
13
node_modules/chromium-bidi/lib/cjs/bidiServer/SimpleTransport.d.ts
generated
vendored
Normal file
13
node_modules/chromium-bidi/lib/cjs/bidiServer/SimpleTransport.d.ts
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
import { EventEmitter } from '../utils/EventEmitter';
|
||||
/**
|
||||
* Implements simple transport that allows sending string messages via
|
||||
* `sendCommand` and receiving them via `on('message')`.
|
||||
*/
|
||||
export declare class SimpleTransport extends EventEmitter<Record<'message', string>> {
|
||||
#private;
|
||||
/**
|
||||
* @param sendCommandDelegate delegate to be called in `sendCommand`.
|
||||
*/
|
||||
constructor(sendCommandDelegate: (plainCommand: string) => Promise<void>);
|
||||
sendCommand(plainCommand: string): Promise<void>;
|
||||
}
|
||||
39
node_modules/chromium-bidi/lib/cjs/bidiServer/SimpleTransport.js
generated
vendored
Normal file
39
node_modules/chromium-bidi/lib/cjs/bidiServer/SimpleTransport.js
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
"use strict";
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.SimpleTransport = void 0;
|
||||
const EventEmitter_1 = require("../utils/EventEmitter");
|
||||
/**
|
||||
* Implements simple transport that allows sending string messages via
|
||||
* `sendCommand` and receiving them via `on('message')`.
|
||||
*/
|
||||
class SimpleTransport extends EventEmitter_1.EventEmitter {
|
||||
#sendCommandDelegate;
|
||||
/**
|
||||
* @param sendCommandDelegate delegate to be called in `sendCommand`.
|
||||
*/
|
||||
constructor(sendCommandDelegate) {
|
||||
super();
|
||||
this.#sendCommandDelegate = sendCommandDelegate;
|
||||
}
|
||||
async sendCommand(plainCommand) {
|
||||
await this.#sendCommandDelegate(plainCommand);
|
||||
}
|
||||
}
|
||||
exports.SimpleTransport = SimpleTransport;
|
||||
//# sourceMappingURL=SimpleTransport.js.map
|
||||
1
node_modules/chromium-bidi/lib/cjs/bidiServer/SimpleTransport.js.map
generated
vendored
Normal file
1
node_modules/chromium-bidi/lib/cjs/bidiServer/SimpleTransport.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"SimpleTransport.js","sourceRoot":"","sources":["../../../src/bidiServer/SimpleTransport.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;AAEH,wDAAmD;AAEnD;;;GAGG;AACH,MAAa,eAAgB,SAAQ,2BAAuC;IACjE,oBAAoB,CAA0C;IAEvE;;OAEG;IACH,YAAY,mBAA4D;QACtE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,oBAAoB,GAAG,mBAAmB,CAAC;IAClD,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,YAAoB;QACpC,MAAM,IAAI,CAAC,oBAAoB,CAAC,YAAY,CAAC,CAAC;IAChD,CAAC;CACF;AAdD,0CAcC"}
|
||||
7
node_modules/chromium-bidi/lib/cjs/bidiServer/WebSocketServer.d.ts
generated
vendored
Normal file
7
node_modules/chromium-bidi/lib/cjs/bidiServer/WebSocketServer.d.ts
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
import type { ChromeReleaseChannel } from '@puppeteer/browsers';
|
||||
import debug from 'debug';
|
||||
export declare const debugInfo: debug.Debugger;
|
||||
export declare class WebSocketServer {
|
||||
#private;
|
||||
constructor(port: number, channel: ChromeReleaseChannel, headless: boolean, verbose: boolean);
|
||||
}
|
||||
347
node_modules/chromium-bidi/lib/cjs/bidiServer/WebSocketServer.js
generated
vendored
Normal file
347
node_modules/chromium-bidi/lib/cjs/bidiServer/WebSocketServer.js
generated
vendored
Normal file
@@ -0,0 +1,347 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.WebSocketServer = exports.debugInfo = void 0;
|
||||
/**
|
||||
* Copyright 2021 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.
|
||||
*/
|
||||
const http_1 = __importDefault(require("http"));
|
||||
const debug_1 = __importDefault(require("debug"));
|
||||
const websocket = __importStar(require("websocket"));
|
||||
const uuid_js_1 = require("../utils/uuid.js");
|
||||
const BrowserInstance_js_1 = require("./BrowserInstance.js");
|
||||
exports.debugInfo = (0, debug_1.default)('bidi:server:info');
|
||||
const debugInternal = (0, debug_1.default)('bidi:server:internal');
|
||||
const debugSend = (0, debug_1.default)('bidi:server:SEND ▸');
|
||||
const debugRecv = (0, debug_1.default)('bidi:server:RECV ◂');
|
||||
class WebSocketServer {
|
||||
#sessions = new Map();
|
||||
#port;
|
||||
#channel;
|
||||
#headless;
|
||||
#verbose;
|
||||
#server;
|
||||
#wsServer;
|
||||
constructor(port, channel, headless, verbose) {
|
||||
this.#port = port;
|
||||
this.#channel = channel;
|
||||
this.#headless = headless;
|
||||
this.#verbose = verbose;
|
||||
this.#server = http_1.default.createServer(this.#onRequest.bind(this));
|
||||
this.#wsServer = new websocket.server({
|
||||
httpServer: this.#server,
|
||||
autoAcceptConnections: false,
|
||||
});
|
||||
this.#wsServer.on('request', this.#onWsRequest.bind(this));
|
||||
this.#server.listen(this.#port, () => {
|
||||
(0, exports.debugInfo)('BiDi server is listening on port', this.#port);
|
||||
});
|
||||
}
|
||||
async #onRequest(request, response) {
|
||||
debugInternal(`Received HTTP ${JSON.stringify(request.method)} request for ${JSON.stringify(request.url)}`);
|
||||
if (!request.url) {
|
||||
return response.end(404);
|
||||
}
|
||||
// https://w3c.github.io/webdriver-bidi/#transport, step 2.
|
||||
if (request.url === '/session') {
|
||||
const body = await new Promise((resolve, reject) => {
|
||||
const bodyArray = [];
|
||||
request.on('data', (chunk) => {
|
||||
bodyArray.push(chunk);
|
||||
});
|
||||
request.on('error', reject);
|
||||
request.on('end', () => {
|
||||
resolve(Buffer.concat(bodyArray));
|
||||
});
|
||||
});
|
||||
// https://w3c.github.io/webdriver-bidi/#transport, step 3.
|
||||
const jsonBody = JSON.parse(body.toString());
|
||||
response.writeHead(200, {
|
||||
'Content-Type': 'application/json;charset=utf-8',
|
||||
'Cache-Control': 'no-cache',
|
||||
});
|
||||
const sessionId = (0, uuid_js_1.uuidv4)();
|
||||
const session = {
|
||||
sessionId,
|
||||
// TODO: launch browser instance and set it to the session after WPT
|
||||
// tests clean up is switched to pure BiDi.
|
||||
browserInstancePromise: undefined,
|
||||
sessionOptions: {
|
||||
chromeOptions: this.#getChromeOptions(jsonBody.capabilities, this.#channel, this.#headless),
|
||||
mapperOptions: this.#getMapperOptions(jsonBody.capabilities),
|
||||
verbose: this.#verbose,
|
||||
},
|
||||
};
|
||||
this.#sessions.set(sessionId, session);
|
||||
const webSocketUrl = `ws://localhost:${this.#port}/session/${sessionId}`;
|
||||
debugInternal(`Session created. WebSocket URL: ${JSON.stringify(webSocketUrl)}.`);
|
||||
response.write(JSON.stringify({
|
||||
value: {
|
||||
sessionId,
|
||||
capabilities: {
|
||||
webSocketUrl,
|
||||
},
|
||||
},
|
||||
}));
|
||||
return response.end();
|
||||
}
|
||||
else if (request.url.startsWith('/session')) {
|
||||
debugInternal(`Unknown session command ${request.method ?? 'UNKNOWN METHOD'} request for ${request.url} with payload ${await this.#getHttpRequestPayload(request)}. 200 returned.`);
|
||||
response.writeHead(200, {
|
||||
'Content-Type': 'application/json;charset=utf-8',
|
||||
'Cache-Control': 'no-cache',
|
||||
});
|
||||
response.write(JSON.stringify({
|
||||
value: {},
|
||||
}));
|
||||
return response.end();
|
||||
}
|
||||
debugInternal(`Unknown ${request.method} request for ${JSON.stringify(request.url)} with payload ${await this.#getHttpRequestPayload(request)}. 404 returned.`);
|
||||
return response.end(404);
|
||||
}
|
||||
#onWsRequest(request) {
|
||||
// Session is set either by Classic or BiDi commands.
|
||||
let session;
|
||||
const requestSessionId = (request.resource ?? '').split('/').pop();
|
||||
debugInternal(`new WS request received. Path: ${JSON.stringify(request.resourceURL.path)}, sessionId: ${JSON.stringify(requestSessionId)}`);
|
||||
if (requestSessionId !== '' &&
|
||||
requestSessionId !== undefined &&
|
||||
!this.#sessions.has(requestSessionId)) {
|
||||
debugInternal('Unknown session id:', requestSessionId);
|
||||
request.reject();
|
||||
return;
|
||||
}
|
||||
const connection = request.accept();
|
||||
session = this.#sessions.get(requestSessionId ?? '');
|
||||
if (session !== undefined) {
|
||||
// BrowserInstance is created for each new WS connection, even for the
|
||||
// same SessionId. This is because WPT uses a single session for all the
|
||||
// tests, but cleans up tests using WebDriver Classic commands, which is
|
||||
// not implemented in this Mapper runner.
|
||||
// TODO: connect to an existing BrowserInstance instead.
|
||||
const sessionOptions = session.sessionOptions;
|
||||
session.browserInstancePromise = this.#closeBrowserInstanceIfLaunched(session)
|
||||
.then(async () => await this.#launchBrowserInstance(connection, sessionOptions))
|
||||
.catch((e) => {
|
||||
(0, exports.debugInfo)('Error while creating session', e);
|
||||
connection.close(500, 'cannot create browser instance');
|
||||
throw e;
|
||||
});
|
||||
}
|
||||
connection.on('message', async (message) => {
|
||||
// If type is not text, return error.
|
||||
if (message.type !== 'utf8') {
|
||||
this.#respondWithError(connection, {}, "invalid argument" /* ErrorCode.InvalidArgument */, `not supported type (${message.type})`);
|
||||
return;
|
||||
}
|
||||
const plainCommandData = message.utf8Data;
|
||||
if (debugRecv.enabled) {
|
||||
try {
|
||||
debugRecv(JSON.parse(plainCommandData));
|
||||
}
|
||||
catch {
|
||||
debugRecv(plainCommandData);
|
||||
}
|
||||
}
|
||||
// Try to parse the message to handle some of BiDi commands.
|
||||
let parsedCommandData;
|
||||
try {
|
||||
parsedCommandData = JSON.parse(plainCommandData);
|
||||
}
|
||||
catch (e) {
|
||||
this.#respondWithError(connection, {}, "invalid argument" /* ErrorCode.InvalidArgument */, `Cannot parse data as JSON`);
|
||||
return;
|
||||
}
|
||||
// Handle creating new session.
|
||||
if (parsedCommandData.method === 'session.new') {
|
||||
if (session !== undefined) {
|
||||
(0, exports.debugInfo)('WS connection already have an associated session.');
|
||||
this.#respondWithError(connection, plainCommandData, "session not created" /* ErrorCode.SessionNotCreated */, 'WS connection already have an associated session.');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const sessionOptions = {
|
||||
chromeOptions: this.#getChromeOptions(parsedCommandData.params?.capabilities, this.#channel, this.#headless),
|
||||
mapperOptions: this.#getMapperOptions(parsedCommandData.params?.capabilities),
|
||||
verbose: this.#verbose,
|
||||
};
|
||||
const browserInstance = await this.#launchBrowserInstance(connection, sessionOptions);
|
||||
const sessionId = (0, uuid_js_1.uuidv4)();
|
||||
session = {
|
||||
sessionId,
|
||||
browserInstancePromise: Promise.resolve(browserInstance),
|
||||
sessionOptions,
|
||||
};
|
||||
this.#sessions.set(sessionId, session);
|
||||
}
|
||||
catch (e) {
|
||||
(0, exports.debugInfo)('Error while creating session', e);
|
||||
this.#respondWithError(connection, plainCommandData, "session not created" /* ErrorCode.SessionNotCreated */, e?.message ?? 'Unknown error');
|
||||
return;
|
||||
}
|
||||
// TODO: extend with capabilities.
|
||||
this.#sendClientMessage({
|
||||
id: parsedCommandData.id,
|
||||
type: 'success',
|
||||
result: {
|
||||
sessionId: session.sessionId,
|
||||
capabilities: {},
|
||||
},
|
||||
}, connection);
|
||||
return;
|
||||
}
|
||||
if (session === undefined) {
|
||||
(0, exports.debugInfo)('Session is not yet initialized.');
|
||||
this.#respondWithError(connection, plainCommandData, "invalid session id" /* ErrorCode.InvalidSessionId */, 'Session is not yet initialized.');
|
||||
return;
|
||||
}
|
||||
if (session.browserInstancePromise === undefined) {
|
||||
(0, exports.debugInfo)('Browser instance is not launched.');
|
||||
this.#respondWithError(connection, plainCommandData, "invalid session id" /* ErrorCode.InvalidSessionId */, 'Browser instance is not launched.');
|
||||
return;
|
||||
}
|
||||
const browserInstance = await session.browserInstancePromise;
|
||||
// Handle `browser.close` command.
|
||||
if (parsedCommandData.method === 'browser.close') {
|
||||
await browserInstance.close();
|
||||
this.#sendClientMessage({
|
||||
id: parsedCommandData.id,
|
||||
type: 'success',
|
||||
result: {},
|
||||
}, connection);
|
||||
return;
|
||||
}
|
||||
// Forward all other commands to BiDi Mapper.
|
||||
await browserInstance.bidiSession().sendCommand(plainCommandData);
|
||||
});
|
||||
connection.on('close', async () => {
|
||||
debugInternal(`Peer ${connection.remoteAddress} disconnected.`);
|
||||
// TODO: don't close Browser instance to allow re-connecting to the session.
|
||||
await this.#closeBrowserInstanceIfLaunched(session);
|
||||
});
|
||||
}
|
||||
async #closeBrowserInstanceIfLaunched(session) {
|
||||
if (session === undefined || session.browserInstancePromise === undefined) {
|
||||
return;
|
||||
}
|
||||
const browserInstance = await session.browserInstancePromise;
|
||||
session.browserInstancePromise = undefined;
|
||||
void browserInstance.close();
|
||||
}
|
||||
#getMapperOptions(capabilities) {
|
||||
const acceptInsecureCerts = capabilities?.alwaysMatch?.acceptInsecureCerts ?? false;
|
||||
const sharedIdWithFrame = capabilities?.alwaysMatch?.sharedIdWithFrame ?? false;
|
||||
return { acceptInsecureCerts, sharedIdWithFrame };
|
||||
}
|
||||
#getChromeOptions(capabilities, channel, headless) {
|
||||
const chromeCapabilities = capabilities?.alwaysMatch?.['goog:chromeOptions'];
|
||||
return {
|
||||
chromeArgs: chromeCapabilities?.args ?? [],
|
||||
channel,
|
||||
headless,
|
||||
chromeBinary: chromeCapabilities?.binary ?? undefined,
|
||||
};
|
||||
}
|
||||
async #launchBrowserInstance(connection, sessionOptions) {
|
||||
(0, exports.debugInfo)('Scheduling browser launch...');
|
||||
const browserInstance = await BrowserInstance_js_1.BrowserInstance.run(sessionOptions.chromeOptions, sessionOptions.mapperOptions, sessionOptions.verbose);
|
||||
// Forward messages from BiDi Mapper to the client unconditionally.
|
||||
browserInstance.bidiSession().on('message', (message) => {
|
||||
this.#sendClientMessageString(message, connection);
|
||||
});
|
||||
(0, exports.debugInfo)('Browser is launched!');
|
||||
return browserInstance;
|
||||
}
|
||||
#sendClientMessageString(message, connection) {
|
||||
if (debugSend.enabled) {
|
||||
try {
|
||||
debugSend(JSON.parse(message));
|
||||
}
|
||||
catch {
|
||||
debugSend(message);
|
||||
}
|
||||
}
|
||||
connection.sendUTF(message);
|
||||
}
|
||||
#sendClientMessage(object, connection) {
|
||||
const json = JSON.stringify(object);
|
||||
return this.#sendClientMessageString(json, connection);
|
||||
}
|
||||
#respondWithError(connection, plainCommandData, errorCode, errorMessage) {
|
||||
const errorResponse = this.#getErrorResponse(plainCommandData, errorCode, errorMessage);
|
||||
void this.#sendClientMessage(errorResponse, connection);
|
||||
}
|
||||
#getErrorResponse(plainCommandData, errorCode, errorMessage) {
|
||||
// XXX: this is bizarre per spec. We reparse the payload and
|
||||
// extract the ID, regardless of what kind of value it was.
|
||||
let commandId;
|
||||
try {
|
||||
const commandData = JSON.parse(plainCommandData);
|
||||
if ('id' in commandData) {
|
||||
commandId = commandData.id;
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
return {
|
||||
type: 'error',
|
||||
id: commandId,
|
||||
error: errorCode,
|
||||
message: errorMessage,
|
||||
// XXX: optional stacktrace field.
|
||||
};
|
||||
}
|
||||
#getHttpRequestPayload(request) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let data = '';
|
||||
request.on('data', (chunk) => {
|
||||
data += chunk;
|
||||
});
|
||||
request.on('end', () => {
|
||||
resolve(data);
|
||||
});
|
||||
request.on('error', (error) => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.WebSocketServer = WebSocketServer;
|
||||
//# sourceMappingURL=WebSocketServer.js.map
|
||||
1
node_modules/chromium-bidi/lib/cjs/bidiServer/WebSocketServer.js.map
generated
vendored
Normal file
1
node_modules/chromium-bidi/lib/cjs/bidiServer/WebSocketServer.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
17
node_modules/chromium-bidi/lib/cjs/bidiServer/index.d.ts
generated
vendored
Normal file
17
node_modules/chromium-bidi/lib/cjs/bidiServer/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* Copyright 2021 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.
|
||||
*/
|
||||
export {};
|
||||
63
node_modules/chromium-bidi/lib/cjs/bidiServer/index.js
generated
vendored
Normal file
63
node_modules/chromium-bidi/lib/cjs/bidiServer/index.js
generated
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Copyright 2021 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.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const browsers_1 = require("@puppeteer/browsers");
|
||||
const argparse_1 = require("argparse");
|
||||
const WebSocketServer_js_1 = require("./WebSocketServer.js");
|
||||
function parseArguments() {
|
||||
const parser = new argparse_1.ArgumentParser({
|
||||
add_help: true,
|
||||
exit_on_error: true,
|
||||
});
|
||||
parser.add_argument('-c', '--channel', {
|
||||
help: 'If set, the given installed Chrome Release Channel will be used ' +
|
||||
'instead of one pointed by Puppeteer version',
|
||||
choices: Object.values(browsers_1.ChromeReleaseChannel),
|
||||
default: browsers_1.ChromeReleaseChannel.DEV,
|
||||
});
|
||||
parser.add_argument('--headless', {
|
||||
help: 'Sets if browser should run in headless or headful mode. Default is true.',
|
||||
default: true,
|
||||
});
|
||||
parser.add_argument('-p', '--port', {
|
||||
help: 'Port that BiDi server should listen to. Default is 8080.',
|
||||
type: 'int',
|
||||
default: process.env['PORT'] ?? 8080,
|
||||
});
|
||||
parser.add_argument('-v', '--verbose', {
|
||||
help: 'If present, the Mapper debug log, including CDP commands and events will be logged into the server output.',
|
||||
action: 'store_true',
|
||||
default: process.env['VERBOSE'] === 'true' || false,
|
||||
});
|
||||
return parser.parse_known_args()[0];
|
||||
}
|
||||
(() => {
|
||||
try {
|
||||
const args = parseArguments();
|
||||
const { channel, port } = args;
|
||||
const headless = args.headless !== 'false';
|
||||
const verbose = args.verbose === true;
|
||||
(0, WebSocketServer_js_1.debugInfo)('Launching BiDi server...');
|
||||
new WebSocketServer_js_1.WebSocketServer(port, channel, headless, verbose);
|
||||
(0, WebSocketServer_js_1.debugInfo)('BiDi server launched');
|
||||
}
|
||||
catch (e) {
|
||||
(0, WebSocketServer_js_1.debugInfo)('Error launching BiDi server', e);
|
||||
}
|
||||
})();
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
node_modules/chromium-bidi/lib/cjs/bidiServer/index.js.map
generated
vendored
Normal file
1
node_modules/chromium-bidi/lib/cjs/bidiServer/index.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/bidiServer/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;AAEH,kDAAyD;AACzD,uCAAwC;AAExC,6DAAgE;AAEhE,SAAS,cAAc;IAMrB,MAAM,MAAM,GAAG,IAAI,yBAAc,CAAC;QAChC,QAAQ,EAAE,IAAI;QACd,aAAa,EAAE,IAAI;KACpB,CAAC,CAAC;IAEH,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,WAAW,EAAE;QACrC,IAAI,EACF,kEAAkE;YAClE,6CAA6C;QAC/C,OAAO,EAAE,MAAM,CAAC,M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E,CAAC"}
|
||||
17
node_modules/chromium-bidi/lib/cjs/bidiServer/reader.d.ts
generated
vendored
Normal file
17
node_modules/chromium-bidi/lib/cjs/bidiServer/reader.d.ts
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* Copyright 2021 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.
|
||||
*/
|
||||
export declare function getMapperTabSource(): Promise<string>;
|
||||
29
node_modules/chromium-bidi/lib/cjs/bidiServer/reader.js
generated
vendored
Normal file
29
node_modules/chromium-bidi/lib/cjs/bidiServer/reader.js
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Copyright 2021 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.
|
||||
*/
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getMapperTabSource = void 0;
|
||||
const promises_1 = __importDefault(require("fs/promises"));
|
||||
const path_1 = __importDefault(require("path"));
|
||||
async function getMapperTabSource() {
|
||||
return await promises_1.default.readFile(path_1.default.join(__dirname, '../../iife/mapperTab.js'), 'utf8');
|
||||
}
|
||||
exports.getMapperTabSource = getMapperTabSource;
|
||||
//# sourceMappingURL=reader.js.map
|
||||
1
node_modules/chromium-bidi/lib/cjs/bidiServer/reader.js.map
generated
vendored
Normal file
1
node_modules/chromium-bidi/lib/cjs/bidiServer/reader.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"reader.js","sourceRoot":"","sources":["../../../src/bidiServer/reader.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;;;;AAEH,2DAA6B;AAC7B,gDAAwB;AAEjB,KAAK,UAAU,kBAAkB;IACtC,OAAO,MAAM,kBAAE,CAAC,QAAQ,CACtB,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,yBAAyB,CAAC,EAC/C,MAAM,CACP,CAAC;AACJ,CAAC;AALD,gDAKC"}
|
||||
Reference in New Issue
Block a user