Skip to main content

Class to automate Chrome browser tasks using Playwright. It adds a class to deal with Microsoft Copilot

Project description

ong_chrome_automation

Automate Chrome browser tasks using Playwright, with special support for Microsoft Copilot interactions (work copilot, not personal copilot).

Features

  • Launch and control a local Chrome browser using Playwright.
  • Support for client certificates (PFX/PKCS12) for secure sites.
  • Optional anti-detection (stealth) scripts.
  • High-level automation for Microsoft Copilot web chat:
    • Send messages and files.
    • Retrieve responses as text, HTML, tables (pandas DataFrames), code blocks, and downloadable files.
  • Example scripts for common Copilot automation tasks.

Requirements

  • Python >= 3.11
  • Google Chrome installed (default path: C:/Program Files/Google/Chrome/Application/chrome.exe)
  • See requirements.txt for Python dependencies.

Installation

pip install -r requirements.txt
playwright install

Usage

Basic Chrome Automation

from ong_chrome_automation import LocalChromeBrowser

with LocalChromeBrowser() as browser:
    browser.goto("https://example.com")

With Client Certificate

from ong_chrome_automation import LocalChromeBrowser
with LocalChromeBrowser(
    origin="https://your-server.com",
    pfxPath="./path/to/cert.pfx",
    passphrase="your-password"
) as browser:
    browser.goto("https://your-server.com")

Hide Browser Window

To run the browser in headless mode (without a visible window), set visible=False:

from ong_chrome_automation import LocalChromeBrowser
with LocalChromeBrowser(visible=False) as browser:
    browser.goto("https://example.com")

Microsoft Copilot Automation

The CopilotAutomation class allows you to automate interactions with Microsoft Copilot web chat using Playwright. Below are some usage examples:

It is designed to work with the work version of Copilot (https://m365.cloud.microsoft/), not the personal version. To avoid MFA, you should have logged in in your Chrome session before using this class.

You can use it to send messages, upload files, and retrieve responses in various formats.

Example 1: Send a Message and Get Response

from ong_chrome_automation import LocalChromeBrowser, CopilotAutomation

with LocalChromeBrowser() as browser:
    copilot = CopilotAutomation(browser)
    copilot.chat("What is the capital of France?")
    print(copilot.get_text_response())

Example 2: Ask for code generation and read code blocks in response

from ong_chrome_automation import LocalChromeBrowser, CopilotAutomation
with LocalChromeBrowser() as browser:
    copilot = CopilotAutomation(browser)
    copilot.chat("Generate a Python code with a function named factorial that calculates the factorial of a positive integer.")
    codes = copilot.get_response_code_blocks()
    print(codes[0])  # Print the first code block```

Example 3: Upload a file and get response

Files can be uploaded to Copilot, and the response can be retrieved as text or HTML.

The limits of copilot apply to this case, e.g. just a single image file can be uploaded per message.

from ong_chrome_automation import LocalChromeBrowser, CopilotAutomation
with LocalChromeBrowser() as browser:
    copilot = CopilotAutomation(browser)
    copilot.chat("Analyze this file:", ["./path/to/your/file.txt"])
    print(copilot.get_text_response())

Example 4: Get response as a pandas DataFrame

from ong_chrome_automation import LocalChromeBrowser, CopilotAutomation
import pandas as pd
with LocalChromeBrowser() as browser:
    copilot = CopilotAutomation(browser)
    copilot.chat("Create a table for the squares of the first 10 numbers.")
    df = copilot.get_response_tables()[0]
    print(df.head())  # Display the first few rows of the DataFrame

Example 5: Download a file from Copilot response

from ong_chrome_automation import LocalChromeBrowser, CopilotAutomation
with LocalChromeBrowser() as browser:
    copilot = CopilotAutomation(browser)
    copilot.chat("Create an excel sheet with the numbers from 1 to 10.")
    files = copilot.get_response_files()
    for file in files:
        copilot.download_file(file, "download_folder")
        print("File downloaded successfully.")

Example 6: Handling long messages

If you send a message that exceeds the character limit of copilot, a ValueError will be raised.

If the message is part of a long conversation, it tries to create a new conversation first before raising the exception.

from ong_chrome_automation import LocalChromeBrowser, CopilotAutomation
with LocalChromeBrowser() as browser:
    copilot = CopilotAutomation(browser)
    try:
        copilot.chat("1" * 10000)
    except ValueError as e:
        print("Error:", e)

Project Structure

  • src/ong_chrome_automation/local_chrome_browser.py: Chrome browser automation class.
  • src/ong_chrome_automation/playwright_copilot.py: High-level Copilot automation.
  • requirements.txt: Python dependencies.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ong_chrome_automation-0.1.2-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file ong_chrome_automation-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for ong_chrome_automation-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3695ebe89beff4645b9c3e1299eaf5d1667c05288eb11c4acc7d808adb881acb
MD5 1d4283a0dfb7cd8bc6823ba627dc07b1
BLAKE2b-256 9a162212e9c1c5a576543a2834327023e9c2d5c4a7135dda449017598f18e3a9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page