cdpSessionDispatcher.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.CDPSessionDispatcher = void 0;
  6. var _crConnection = require("../chromium/crConnection");
  7. var _dispatcher = require("./dispatcher");
  8. /**
  9. * Copyright (c) Microsoft Corporation.
  10. *
  11. * Licensed under the Apache License, Version 2.0 (the 'License");
  12. * you may not use this file except in compliance with the License.
  13. * You may obtain a copy of the License at
  14. *
  15. * http://www.apache.org/licenses/LICENSE-2.0
  16. *
  17. * Unless required by applicable law or agreed to in writing, software
  18. * distributed under the License is distributed on an "AS IS" BASIS,
  19. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  20. * See the License for the specific language governing permissions and
  21. * limitations under the License.
  22. */
  23. class CDPSessionDispatcher extends _dispatcher.Dispatcher {
  24. constructor(scope, cdpSession) {
  25. super(scope, cdpSession, 'CDPSession', {});
  26. this._type_CDPSession = true;
  27. this.addObjectListener(_crConnection.CDPSession.Events.Event, ({
  28. method,
  29. params
  30. }) => this._dispatchEvent('event', {
  31. method,
  32. params
  33. }));
  34. this.addObjectListener(_crConnection.CDPSession.Events.Closed, () => this._dispose());
  35. }
  36. async send(params) {
  37. return {
  38. result: await this._object.send(params.method, params.params)
  39. };
  40. }
  41. async detach(_, metadata) {
  42. metadata.potentiallyClosesScope = true;
  43. await this._object.detach();
  44. }
  45. }
  46. exports.CDPSessionDispatcher = CDPSessionDispatcher;