| // Copyright 2020 The Chromium Authors | |
| // Use of this source code is governed by a BSD-style license that can be | |
| // found in the LICENSE file. | |
| import * as ProtocolClient from '../core/protocol_client/protocol_client.js'; | |
| import type * as SDK from '../core/sdk/sdk.js'; | |
| import type {ProtocolMapping} from '../generated/protocol-mapping.js'; | |
| import type * as ProtocolProxyApi from '../generated/protocol-proxy-api.js'; | |
| export function dispatchEvent<E extends keyof ProtocolMapping.Events>( | |
| target: SDK.Target.Target, eventName: E, ...payload: ProtocolMapping.Events[E]): void { | |
| const event = eventName as ProtocolClient.InspectorBackend.QualifiedName; | |
| const [domain] = ProtocolClient.InspectorBackend.splitQualifiedName(event); | |
| const registeredEvents = | |
| ProtocolClient.InspectorBackend.inspectorBackend.getOrCreateEventParameterNamesForDomainForTesting( | |
| domain as keyof ProtocolProxyApi.ProtocolDispatchers); | |
| const eventParameterNames = registeredEvents.get(event); | |
| if (!eventParameterNames) { | |
| // The event is not registered, fake-register with empty parameters. | |
| registeredEvents.set(event, []); | |
| } | |
| target.dispatch({method: event, params: payload[0]}); | |
| } |