cdpClient.d.ts 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /**
  2. * Copyright 2021 Google LLC.
  3. * Copyright (c) Microsoft Corporation.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. import type { ProtocolMapping } from 'devtools-protocol/types/protocol-mapping.js';
  18. import { EventEmitter } from '../utils/EventEmitter.js';
  19. import type { CdpConnection } from './cdpConnection.js';
  20. export type CdpEvents = {
  21. [Property in keyof ProtocolMapping.Events]: ProtocolMapping.Events[Property][0];
  22. };
  23. /** A error that will be thrown if/when the connection is closed. */
  24. export declare class CloseError extends Error {
  25. }
  26. export interface ICdpClient extends EventEmitter<CdpEvents> {
  27. /**
  28. * Provides an unique way to detect if an error was caused by the closure of a
  29. * Target or Session.
  30. *
  31. * @example During the creation of a subframe we navigate the main frame.
  32. * The subframe Target is closed while initialized commands are in-flight.
  33. * In this case we want to swallow the thrown error.
  34. */
  35. isCloseError(error: unknown): boolean;
  36. /**
  37. * Returns a command promise, which will be resolved with the command result
  38. * after receiving the result from CDP.
  39. * @param method Name of the CDP command to call.
  40. * @param params Parameters to pass to the CDP command.
  41. */
  42. sendCommand<CdpMethod extends keyof ProtocolMapping.Commands>(method: CdpMethod, params?: ProtocolMapping.Commands[CdpMethod]['paramsType'][0]): Promise<ProtocolMapping.Commands[CdpMethod]['returnType']>;
  43. }
  44. /** Represents a high-level CDP connection to the browser. */
  45. export declare class CdpClient extends EventEmitter<CdpEvents> implements ICdpClient {
  46. #private;
  47. constructor(cdpConnection: CdpConnection, sessionId?: string);
  48. sendCommand<CdpMethod extends keyof ProtocolMapping.Commands>(method: CdpMethod, ...params: ProtocolMapping.Commands[CdpMethod]['paramsType']): Promise<ProtocolMapping.Commands[CdpMethod]['returnType']>;
  49. isCloseError(error: unknown): boolean;
  50. }