Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Playwright Copilot Target

Similar to the more generic PlaywrightTarget, PlaywrightCopilotTarget uses Playwright for browser automation. It is built specifically for testing Microsoft’s Copilots (currently supports M365 and Consumer Copilot).

Note: This code will not run in Jupyter! Please run it as a standalone Python script. To convert to a .py, find the corresponding file in the repository, use jupytext --to py:percent, or copy the code into a .py file.`

Connecting to an Existing Browser Session

Instead of launching a new browser, you can connect PlaywrightTarget to an existing browser session. Here are a few approaches:

First, start a browser (in this case Edge) with remote debugging enabled (outside of Python):

Start-Process msedge -ArgumentList "--remote-debugging-port=9222", "--user-data-dir=$env:TEMP\edge-debug", "--profile-directory=`"Default`""

The profile directory is optional but useful if you want to maintain session state (e.g., logged-in users). In the example below we assume that the user is logged into Consumer Copilot and M365 Copilot. To check the profile, go to edge://version/ and check the “Profile Path”.

Using PlaywrightCopilotTarget for Text Interactions

Now, we can use the PlaywrightCopilotTarget which has built-in Copilot functionality. This target automatically handles text inputs without needing custom interaction functions.

Using PlaywrightCopilotTarget for multimodal interactions