bidiTab.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. "use strict";
  2. /**
  3. * Copyright 2021 Google LLC.
  4. * Copyright (c) Microsoft Corporation.
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. *
  18. * @license
  19. */
  20. Object.defineProperty(exports, "__esModule", { value: true });
  21. const BidiMapper_js_1 = require("../bidiMapper/BidiMapper.js");
  22. const CdpConnection_js_1 = require("../cdp/CdpConnection.js");
  23. const log_js_1 = require("../utils/log.js");
  24. const BidiParser_js_1 = require("./BidiParser.js");
  25. const mapperTabPage_js_1 = require("./mapperTabPage.js");
  26. const Transport_js_1 = require("./Transport.js");
  27. (0, mapperTabPage_js_1.generatePage)();
  28. const mapperTabToServerTransport = new Transport_js_1.WindowBidiTransport();
  29. const cdpTransport = new Transport_js_1.WindowCdpTransport();
  30. /**
  31. * A CdpTransport implementation that uses the window.cdp bindings
  32. * injected by Target.exposeDevToolsProtocol.
  33. */
  34. const cdpConnection = new CdpConnection_js_1.MapperCdpConnection(cdpTransport, mapperTabPage_js_1.log);
  35. /**
  36. * Launches the BiDi mapper instance.
  37. * @param {string} selfTargetId
  38. * @param options Mapper options. E.g. `acceptInsecureCerts`.
  39. */
  40. async function runMapperInstance(selfTargetId, options) {
  41. // eslint-disable-next-line no-console
  42. console.log('Launching Mapper instance with selfTargetId:', selfTargetId);
  43. const bidiServer = await BidiMapper_js_1.BidiServer.createAndStart(mapperTabToServerTransport, cdpConnection,
  44. /**
  45. * Create a Browser CDP Session per Mapper instance.
  46. */
  47. await cdpConnection.createBrowserSession(), selfTargetId, options, new BidiParser_js_1.BidiParser(), mapperTabPage_js_1.log);
  48. (0, mapperTabPage_js_1.log)(log_js_1.LogType.debugInfo, 'Mapper instance has been launched');
  49. return bidiServer;
  50. }
  51. /**
  52. * Set `window.runMapper` to a function which launches the BiDi mapper instance.
  53. * @param selfTargetId Needed to filter out info related to BiDi target.
  54. * @param options Mapper options. E.g. `acceptInsecureCerts`. */
  55. window.runMapperInstance = async (selfTargetId, options) => {
  56. await runMapperInstance(selfTargetId, options);
  57. };
  58. //# sourceMappingURL=bidiTab.js.map