  const isAllowed =
    targetFront.isTopLevel ||
    targetFront.targetType === targetList.TYPES.PROCESS ||
    (targetFront.targetType === targetList.TYPES.FRAME && listenForFrames);

  if (!isAllowed) {
    return;
  }

  const webConsoleFront = await targetFront.getFront("console");

  // Request notifying about new messages
  await webConsoleFront.startListeners(["ConsoleAPI"]);

  // Fetch already existing messages
  // /!\ The actor implementation requires to call startListeners(ConsoleAPI) first /!\
  let { messages } = await webConsoleFront.getCachedMessages(["ConsoleAPI"]);

  messages = messages.map(message => {
    // Handling cached messages for servers older than Firefox 78.
    // Wrap the message into a `message` attribute, to match `consoleAPICall` behavior
    if (message._type) {
      return {
        message,
        resourceType: ResourceWatcher.TYPES.CONSOLE_MESSAGE,
      };
    }
    message.resourceType = ResourceWatcher.TYPES.CONSOLE_MESSAGE;
    return message;
  });
  onAvailable(messages);

  // Forward new message events
  webConsoleFront.on("consoleAPICall", message => {
    message.resourceType = ResourceWatcher.TYPES.CONSOLE_MESSAGE;
    onAvailable([message]);
  });
};
PK