pyrit.prompt_target.PlaywrightCopilotTarget#

class PlaywrightCopilotTarget(*, page: None, copilot_type: CopilotType = CopilotType.CONSUMER)[source]#

Bases: PromptTarget

PlaywrightCopilotTarget uses Playwright to interact with Microsoft Copilot web UI.

This target handles both text and image inputs, automatically navigating the Copilot interface including the dropdown menu for image uploads.

Both Consumer and M365 Copilot responses can contain text and images. When multimodal content is detected, the target will return multiple response pieces with appropriate data types.

Parameters:
  • page (Page) – The Playwright page object to use for interaction.

  • copilot_type (CopilotType) – The type of Copilot interface (Consumer or M365).

__init__(*, page: None, copilot_type: CopilotType = CopilotType.CONSUMER) None[source]#

Initialize the Playwright Copilot target.

Parameters:
  • page (Page) – The Playwright page object for browser interaction.

  • copilot_type (CopilotType) – The type of Copilot to interact with. Defaults to CopilotType.CONSUMER.

Raises:
  • RuntimeError – If the Playwright page is not initialized.

  • ValueError – If the page URL doesn’t match the specified copilot_type.

Methods

__init__(*, page[, copilot_type])

Initialize the Playwright Copilot target.

dispose_db_engine()

Dispose database engine to release database connections and resources.

get_identifier()

Get an identifier dictionary for this prompt target.

send_prompt_async(*, message)

Send a message to Microsoft Copilot and return the response.

set_model_name(*, model_name)

Set the model name for this target.

Attributes

ARIA_LABEL_THUMBNAIL: str = 'button[aria-label*="Thumbnail"] img'#
ATTR_ID: str = 'id'#
ATTR_SRC: str = 'src'#
IMAGE_DATA_URL_PREFIX: str = 'data:image/'#
IMAGE_STABILITY_ITERATIONS: int = 3#
LOGIN_REQUIRED_HEADER: str = 'Sign in for the full experience'#
M365_URL_IDENTIFIER: str = 'm365'#
MAX_IMAGE_WAIT_SECONDS: int = 15#
MAX_WAIT_TIME_SECONDS: int = 300#
MIN_IMAGE_WAIT_SECONDS: int = 3#
PLACEHOLDER_GENERATING: str = 'generating'#
PLACEHOLDER_GENERATING_RESPONSE: str = 'generating response'#
PLACEHOLDER_THINKING: str = 'thinking'#
POLL_INTERVAL_MS: int = 2000#
RESPONSE_COMPLETE_WAIT_MS: int = 3000#
RETRY_ATTEMPTS: int = 5#
RETRY_DELAY_MS: int = 500#
SELECTOR_IFRAME: str = 'iframe'#
SELECTOR_IMAGE: str = 'img'#
SUPPORTED_DATA_TYPES = {'image_path', 'text'}#
async send_prompt_async(*, message: Message) list[Message][source]#

Send a message to Microsoft Copilot and return the response.

Parameters:

message (Message) – The message to send. Can contain multiple pieces of type ‘text’ or ‘image_path’.

Returns:

A list containing the response from Copilot.

Return type:

list[Message]

Raises:

RuntimeError – If an error occurs during interaction.